faust
faust copied to clipboard
Computing tables during compilation
Defining a table for rdtable like so: wt = ba.time * 2.0 * ma.PI / 1024 : sin; computes values at init time. For arbitrarily complex equations this can incur a large init-time cost.
For such cases, could the compiler precompute the values so that they are treated similarly to a waveform statement? OR Allow the waveform primitive to take a function as input, such as waveform[tablesize]{signal};
The compiler is not smart enough to have special handling for bounded recursive functions in rdtable. If it had, using int(os.phasor) or ba.period would work.
In fact rdtable guarantees runtime calculation.
If you really want something precomputed compile time, try reformulating your function to work on discrete integer samples only. Usually something on the order of par(i, M, func(M, i)) : ba.selectn(M, int(os.phasor(M, freq))) will do something with more precomputation but it will look like a terrible nested if, not a table access.