funcgen
– Function Generator for Audio Samples¶
Function Generator for Audio Samples
This implements the audiosample protocol (like RawSample or WAV) so it can be played by CircuitPython audio functions.
Basic waveform types are generated mathematically on the fly by FuncSample objects. Also a user-definable “SYNTH” function type is provided, which allows passing an array of 16-bit samples defining an arbitrary periodic waveform to be played back with variable frequency.
Additionally, a few post-processing effects are provided:
Envelope Control: To prevent ‘clicking’ which happens when you use the high-level play/stop functions, use env_attack() and env_release(). You can fully customize the “Attack, Decay, Sustain, Release (ADSR)” envelope settings!
Glide: You can “portmento” between notes easily.
Modulators: Patch-in user-defined LFO waveforms to modulate amplitude and/or frequency for tremolo or vibrato effects.
-
class
funcgen.
FuncSample
(func_type, sample_rate)[source]¶ Create a new FuncSample object.
- Parameters
func_type (int) – Index representing which function type to create. (see
Function Types
)sample_rate (int) – Sample rate for playback
-
set_envelope
(d, s, r)[source]¶ Configure envelope parameters. Initial settings are: (0.003, 0.010, 0.95, 0.003)
-
set_modulator
(rate, depth_buf)[source]¶ Configure a modulator, or Low Frequency Oscillator (LFO)
The supplied depth_buf must have nonzero length and will be assumed to represent exactly 1-cycle of the LFO waveform.
Each param has its own independent LFO.
- Parameters
param (int) – Which modulator (MOD_FREQUENCY, MOD_AMPLITUDE) (see
Modulator Types
)rate (float) – LFO frequency (Hz). set to ZERO to disable modulator.
depth_buf (
array
(“h”)) – Array of 16-bit signed samples