- Notifications
You must be signed in to change notification settings - Fork184
How to convert numpy arrays into Const() lookup tables#1053
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
What's the best way to convert a Numpy array into Const() lookup table? Let's say you want to generate 8 mipmapped 24-bit integer band-limited sawtooth wave tables on power of 2 base frequencies from 16Hz to 2048Hz. Because these only contain odd-order harmonics, you only need to generate half the waveform (you need to roll around and invert direction to use it, i.e. 0, 1, 2, 3, 0, -1, -2, -3... and multiply the values at negative indexes by -1). Doing this with Numpy using an 8x1024 array and converting the fromamaranthimport*importnumpyasnpfromnumpyimportsin,uint32,float64,powertau=2*np.pitemp_ramp_tables=np.empty((8,1024),dtype=float64)foriinrange(0,8):base_f0=power(2,i+4)n_harmonics=np.floor(18000/base_f0)# Generate 1024 samples normalized to 1/2 waveform (hence /2*tau))# and including all harmonics up to 18kHzh=np.arange(1,n_harmonics+1)temp_ramp_tables[i]=np.sum(sin(h*base_f0/ (2*tau))/h)# compress peak-to-peak relative to the largest amplitudetemp_ramp_tables/=np.max(temp_ramp_tables)# convert to positive half of unsigned 24-bit rangeramp_tables=temp_ramp_tables*(power(2,23)-1).astype(uint32)deltemp_ramp_tables The question is how to convert to a table for Amaranth? The best I can come up with is the below change: # convert to positive half of unsigned 24-bit rangeramp_tables= [ [Const(x,unsigned(23))forxintemp_ramp_tables[y]*(power(2,23)-1).astype(uint32)]foryinrange(0,8) ]deltemp_ramp_tables Is this the best way? Is there a better way? |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment
-
I would say this is the best way, yeah |
BetaWas this translation helpful?Give feedback.