home/ atoms/ wavetable-table-size-power-of-two

Wavetable lengths are rounded up to a power of two for FFT and binary-index efficiency

The minimum length for a table of N harmonics is 2N+1 samples (Nyquist). Because linear interpolation needs oversampling for quality, at least 2× is advisable, so the minimum roughly doubles. In practice the length is then rounded up to the next power of two. The reasons: binary arithmetic gives zero-cost wrapping of the table index (a bitwise mask replaces a modulo); building tables with the FFT is far faster than summing sine waves individually, and the FFT is best suited to power-of-two lengths; and letting users define their own waves via FFT effectively requires it. The rounding-up also yields a little extra oversampling for free, slightly improving interpolation.

Examples

368 harmonics need at least 368×2+1 = 737 samples; with 2× interpolation oversampling, 1474; the next power of two is 2048, which also gives a bit more oversampling headroom. Memory is cheap, so going bigger is fine.

Assessment

A wavetable must hold 200 harmonics with 2× oversampling: compute the minimum sample count, state the power-of-two size you would use, and give two reasons powers of two are preferred.

“choose a table length that's a power of two, however. There are optimizations we can do that take advantage of binary arithmetic”
corpus · a-wavetable-oscillator-part-2-anti-aliasing-and-mip-mapping · chunk 2