music.waveform_table

music.waveform_table(kind, size=16384)[source]

One period of a primary waveform, as a lookup table.

Each table is written directly as a function of the phase, so it is exact at any size and holds exactly size samples. Building them by halves instead — the way this package used to — costs a sample at odd sizes and puts the sawtooth and triangle slightly out of true.

Parameters:
kind{‘sine’, ‘sawtooth’, ‘square’, ‘triangle’}

Which waveform to build.

sizeint, optional

The number of samples in the period. Defaults to LAMBDA_TILDE.

Returns:
ndarray

size samples spanning one period, in [-1, 1].

Raises:
ValueError

If kind is not one of WAVEFORMS, or size is not positive.

Parameters:
Return type:

NDArray[float64]

Examples

>>> waveform_table('square', 4)
array([-1., -1.,  1.,  1.])
>>> waveform_table('triangle', 4)
array([-1.,  0.,  1.,  0.])
>>> waveform_table('sawtooth', 4)
array([-1. , -0.5,  0. ,  0.5])