soundlib – Sound Library for Tones, FX, MP3s
soundlib (including SoundMaker, Tone)
This library provides a high-level interface for playing and mixing sounds of different types on the CodeX. With this, sounds can also be played “in the background” while other code runs.
soundmaker =
SoundMaker
- Example:
Play a tone based on a supported instrument or waveform name
>>> tone = soundlib.get_tone('trumpet') >>> tone.play()
Instrument |
Waveform |
|---|---|
flute |
sine |
recorder |
triangle |
trumpet |
square |
violin |
sawtooth |
noise |
random |
organ |
(none) |
synth |
see |
- class codex.soundlib.SoundMaker(max_concurrent_sounds=16, sample_rate=16000)[source]
Provides sounds which can be mixed together concurrently (polyphonic!)
- get_sample(sample_buf, play=True, loop=False)[source]
Get a sample object so you can play it. This can be a buffer directly recorded from the CodeX mic, or any 16-bit array you create using
array.array(“h”) and fill with samples. Note: sample rate of sample_buf must match self.sample_rate or pitch will be wonky!
- class codex.soundlib.Tone(voice, sample)[source]
A Tone player with pitch and level control. Tones have variable pitch (frequency), and support several different wave shapes (waveforms).
This is built atop the FuncSample class in the
funcgenmodule. See that module for more details.Tone uses an audiomixer voice to play a FuncSample sample.
- glide(new_pitch, duration)[source]
Glide from current frequency to new pitch, linearly over tm seconds.
- set_envelope(a, d, s, r)[source]
Configure envelope parameters. Initial settings are: (0.003, 0.010, 0.95, 0.003)
- set_modulator(mod_name, rate, depth_buf)[source]
Configure a modulator (LFO)
The supplied depth_buf must have nonzero length and will be assumed to represent exactly 1-cycle of the LFO waveform.
Each modulator has its own independent LFO.