synthwaveform
¶
Helper library to generate waveforms.
Author(s): Cooper Dalrymple
Implementation Notes¶
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s Wave library: https://github.com/adafruit/Adafruit_CircuitPython_Wave
- synthwaveform.from_wav(path: str, max_size: int = None, channel: int = 0) tuple[ulab.numpy.ndarray, int] ¶
Read an single channel from a 16-bit audio wave file (“.wav”).
- Parameters:
path – The path to the “.wav” file
max_size – The maximum limit of which to load samples from the audio file. If set as
None
, there is no limit in buffer size. Use to avoid memory overflow with large audio files. Defaults toNone
.channel – The channel to extract mono audio data from. Defaults to 0.
- Returns:
A tuple of the waveform data and the sample rate of the source wav file
- synthwaveform.mix(*waveforms: tuple) ulab.numpy.ndarray ¶
Combine multiple waveforms together to a single waveform. All
ulab.numpy.ndarray
objects must have the same data type. If the sizes of the arrays are inconsistent, the output will be sized to the shortest array.import synthwaveform waveform = synthwaveform.mix( (synthwaveform.triangle(), 0.7), (synthwaveform.saw(frequency=2.0), 0.1), (synthwaveform.saw(frequency=3.0), 0.1), (synthwaveform.saw(frequency=4.0), 0.1), )
- Parameters:
waveforms – The arrays to be mixed together. In order to specify the level for each waveform, each waveform can be provided as a tuple with the first element being the waveform data and the second being the level.
- synthwaveform.noise(amplitude: float = 1.0, size: int = _DEFAULT_SIZE, dtype: ulab.numpy._DType = _DEFAULT_DTYPE) ulab.numpy.ndarray ¶
Generate random “white” noise
- Parameters:
amplitude – The level of the waveform
size – The number of frames of the resulting array
dtype – Data type code to use for the resulting array
- synthwaveform.saw(amplitude: float = 1.0, phase: float = 0.0, frequency: float = 1.0, reverse: bool = False, size: int = _DEFAULT_SIZE, dtype: ulab.numpy._DType = _DEFAULT_DTYPE) ulab.numpy.ndarray ¶
Generate a sawtooth waveform.
- Parameters:
- synthwaveform.sine(amplitude: float = 1.0, phase: float = 0.0, frequency: float = 1.0, size: int = _DEFAULT_SIZE, dtype: ulab.numpy._DType = _DEFAULT_DTYPE) ulab.numpy.ndarray ¶
Generate a sinusoidal waveform.
- Parameters:
amplitude – The level of the waveform
phase – The cycle offset
frequency – The number of cycles
size – The number of frames of the resulting array
dtype – Data type code to use for the resulting array
- synthwaveform.square(amplitude: float = 1.0, phase: float = 0.0, frequency: float = 1.0, duty_cycle: float = 0.5, size: int = _DEFAULT_SIZE, dtype: ulab.numpy._DType = _DEFAULT_DTYPE) ulab.numpy.ndarray ¶
Generate a square waveform.
- Parameters:
- synthwaveform.triangle(amplitude: float = 1.0, phase: float = 0.0, frequency: float = 1.0, size: int = _DEFAULT_SIZE, dtype: ulab.numpy._DType = _DEFAULT_DTYPE) ulab.numpy.ndarray ¶
Generate a triangle waveform.
- Parameters:
amplitude – The level of the waveform
phase – The cycle offset
frequency – The number of cycles
size – The number of frames of the resulting array
dtype – Data type code to use for the resulting array