Created
May 2, 2014 21:27
-
-
Save ttmarek/c482087d0ed9cc53c18b to your computer and use it in GitHub Desktop.
Generates a fixed amplitude wavetable for use with FunctionGenerator.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fixed Amplitude (Maximum) | |
import numpy as np | |
table = [] | |
two_pi = 2*np.pi | |
res = 20 | |
top = 500 | |
def map_value(x, in_min, in_max, out_min, out_max): | |
return (((x - in_min) * (out_max - out_min))/(in_max - in_min)) + out_min | |
for i in range(0,res): | |
sine_value = np.sin(two_pi*i/(res-1)) | |
table.append(int(np.round(map_value(sine_value,-1,1,0,top),0))) | |
with open('wavetable.h', 'w') as wavetable: | |
wavetable.write('#include "Arduino.h"\n') | |
wavetable.write('const long length = '+str(len(table))+';\n'); | |
table = [str(x) for x in table] | |
table_string = ', '.join(table) | |
wavetable.write('const byte waveTable[] PROGMEM = {'+table_string+'};') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment