Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to convert numpy arrays into Const() lookup tables#1053

Unanswered
jrmoserbaltimore asked this question inQ&A
Discussion options

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 thefloat64 touint32 (each half is entirely positive or negative) containing values scaled to 24-bit integer representation is doable pretty simply:

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?

You must be logged in to vote

Replies: 1 comment

Comment options

[Const(x,unsigned(23))forxintemp_ramp_tables[y]*(power(2,23)-1).astype(uint32)]

I would say this is the best way, yeah

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@jrmoserbaltimore@whitequark

[8]ページ先頭

©2009-2025 Movatter.jp