relic_waveform
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
- relic_waveform.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
- relic_waveform.mix(*waveforms: tuple) ulab.numpy.ndarray
Combine multiple waveforms together to a single waveform. All
ulab.numpy.ndarrayobjects must have the same data type. If the sizes of the arrays are inconsistent, the output will be sized to the shortest array.import relic_waveform waveform = relic_waveform.mix( (relic_waveform.triangle(), 0.7), (relic_waveform.saw(frequency=2.0), 0.1), (relic_waveform.saw(frequency=3.0), 0.1), (relic_waveform.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.
- relic_waveform.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
- relic_waveform.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:
amplitude – The level of the waveform
phase – The cycle offset
frequency – The number of cycles
reverse –
The direction of the waveform, either decrementing (
False) or incrementing (True)
reverse=True
size – The number of frames of the resulting array
dtype – Data type code to use for the resulting array
- relic_waveform.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
- relic_waveform.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:
- relic_waveform.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













