music¶
Extreme-fidelity synthesis of musical elements.
music generates and manipulates music and sound in LPCM audio. It
implements the MASS framework — Music and
Audio in Sample Sequences — a collection of psychophysical descriptions of
musical elements expressed as equations and corresponding Python routines.
import music
scale = [music.note(440 * 2 ** (i / 12), duration=0.4) for i in range(12)]
music.write_wav_mono(music.horizontal_stack(*scale), "chromatic.wav")
New here? The Tutorial walks from a single note to a short stereo piece, and explains what the sample-by-sample model actually buys you.
What makes it precise¶
Sample-based synthesis. State is updated at every sample. A note with a vibrato has a different instantaneous frequency at each of its samples, and the vibrato pattern is folded into the wavetable lookup rather than applied afterwards — so the rendered sound is as close as it can be to the mathematical model that describes it.
Musical structures, with an emphasis on symmetry and discourse: permutation groups, change-ringing peals and plain changes.
Every routine’s docstring carries the equation it implements and cites the article it comes from. If you use this package, please cite:
Fabbri, Renato, et al. Musical elements in the discrete-time representation of sound. arXiv preprint arXiv:1412.6853 (2017).
Install¶
pip install music
Or from a checkout, which is convenient for hacking and debugging:
git clone https://github.com/ttm/music.git
pip install -e music
Requires Python 3.10 or newer.
PrimaryTables.draw_tables plots the
waveform tables and is the one thing that needs matplotlib, which is an extra:
pip install 'music[plot]'
Nothing else in the package uses it, and leaving it out makes import music
about 40% faster.
Where things live¶
Module |
What it holds |
|---|---|
Notes with vibrato, glissando, FM and Doppler; envelopes; noises |
|
ADSR, fades, FIR/IIR, reverb, loudness, stereo localization |
|
Reading, writing and playing audio, mono and stereo |
|
Permutations, algebraic groups, change-ringing peals |
|
Scheduling notes into a timeline and rendering them |
|
Conversions, mixing, stacking, rhythm |
The whole public API is re-exported flat from the top level, so
music.note(...) works regardless of which submodule defines it.