API reference¶
Every name below is re-exported from the top level: music.note(...) works
regardless of which submodule defines it.
Synthesis¶
Notes¶
Each returns a numpy array of PCM samples. note is the plain wavetable
lookup, as MASS specifies it; the rest layer vibrato, pitch transitions,
frequency modulation and movement onto it.
Synthesize a basic musical note. |
|
Synthesize a basic musical note with a phase. |
|
Synthesize a musical note with a vibrato. |
|
A note with a vibrato that also has a secondary oscillatory pattern. |
|
A note with a pitch transition: a glissando. |
|
A note with a pitch transition (a glissando) and a vibrato. |
|
A note with a glissando and a vibrato that also has a secondary oscillatory pattern. |
|
A note with an arbitrary sequence of pitch transition and a meta-vibrato. |
|
A sound with arbitrary meta-vibratos, transitions of frequency and localization. |
|
Synthesize a musical note with FM synthesis. |
|
A simple note with a transition of localization and resulting Doppler effect. |
|
Makes a trill. |
Band-limited rendering¶
bandlimited_note renders a fixed pitch without the partials above the
Nyquist frequency that note folds back into the band, and
render_oversampled renders any generator at a multiple of the rate and
filters it, for the folding a table cannot prevent.
Band-limited synthesis describes both, with the oscillators for a
pitch that moves.
Render a static-pitch periodic note with prefiltered harmonics. |
|
Render at a higher sampling rate, low-pass, then downsample. |
Sensory stimulation¶
Stimuli for sensory-stimulation work, each rendering one technique catalogued in SSTIM, the Sensory Stimulation Vocabulary. Every docstring names the SSTIM term it implements and states whether the modulation is physically present in the signal or constructed by the listener.
Synthesize a binaural beat: |
|
Synthesize a monaural beat: |
|
Synthesize an isochronic tone train: |
|
Sinusoidally modulate a carrier: |
|
Sweep a carrier's pitch: |
|
Modulate a band of noise: |
|
Orbit a source around the listener: |
A protocol is a sequence of those rather than one of them.
StimulationSession holds that sequence and renders it as
one sound, joining the phases with crossfades centred on their boundaries
so that the session lasts exactly the sum of the durations it was given.
A sequence of stimuli rendered as one sound. |
|
One phase of a session: a stimulus, for a while, ramped into. |
Envelopes and noise¶
Filters¶
Amplitude¶
Synthesize an ADSR envelope. |
|
A shorthand to make an ADSR envelope for a stereo sound. |
|
Creates a note with a vibrato and an ADSR envelope. |
|
A fade in or out. |
|
Cross fade two sounds over duration milliseconds. |
|
An envelope for a linear or exponential transition of amplitude. |
|
An envelope with linear or exponential transitions of amplitude. |
Spectral and spatial¶
Apply a FIR filter to a sonic_array. |
|
Apply an IIR filter to a signal. |
|
Apply an artificial reverberation or return the impulse response. |
|
Make a mono sound stereo and localize it by a very naive method. |
|
Make a mono sound stereo and localize it by experimental methods. |
|
Localize a sound along a straight path between two angles. |
|
Place a mono sound with a measured pair of impulse responses. |
|
Makes a sequence of squeezes of the fragment in x. |
Filter design¶
iir applies coefficients; these compute them, from the four designs the
MASS article specifies. Cutoff, centre and bandwidth are fractions of the
sample rate, which fraction_of converts a frequency in Hertz into.
A one-pole low pass, from the article's equation |
|
A one-pole high pass, from the article's equation |
|
A two-pole band pass, from the article's |
|
A two-pole notch, from the article's |
|
A frequency in Hertz, as the fraction of the sample rate a design wants. |
Input and output¶
Read an audio file and return an array of its values. |
|
The name |
|
Write a sound to a file, mono or stereo, WAV or FLAC. |
|
Writes a mono WAV file for a numpy array. |
|
Write a stereo WAV files for a numpy array. |
|
Play a sonic vector using the |
|
Normalize a mono sonic vector. |
|
Normalize a stereo sonic vector. |
Sequencing¶
Schedules notes and renders them as audio. |
Musical structures¶
Permutations, algebraic groups and change-ringing peals.
Get permutations of n elements in meaningful sequences. |
|
Shifts a permutation up or down by step positions. |
|
Computes the cyclic distance between the two elements of a permutation. |
|
A collection of named peals that can be acted on a domain. |
|
Uses permutations to make peals and represents peals as permutations. |
|
Presents plain changes as swaps and acts in domains to make peals. |
|
Prints a peal with colored numbers. |
Music theory¶
Scales, chords and the harmonic series, counted in semitones from a tonic or
root of zero – which is what pitch_to_freq takes, so any of these
becomes frequencies and then sound in two steps.
The semitones of a named scale, counted from tonic. |
|
A diatonic mode, built by rotating the steps as |
|
The first partials harmonics, in semitones above the fundamental. |
|
The semitones of a named chord, counted from root. |
|
One more third on top of a triad. |
|
Move one note of a chord by whole octaves. |
|
The number of semitones in an interval, from its traditional name. |
|
Every traditional name for an interval of this many semitones. |
|
The interval in semitones between two frequencies, rounded. |
|
How the article classifies an interval. |
The tables these read from are exported too: SCALES, MODES,
MINOR_SCALES and DIATONIC_STEPS for the scales, CHORDS,
TRIADS and SEVENTHS for the chords, and
HARMONIC_SERIES_AS_PRINTED for the article’s own table of partials, and
SIMPLE_INTERVALS and CONSONANCE for the intervals.
Bonds¶
Relations tying a note’s vibrato and tremolo to its frequency, so that a piece decides once how its notes behave rather than note by note.
A set of relations tying a note's characteristics to its frequency. |
|
A bond that rises with the frequency: |
|
A bond that falls with the frequency: |
|
A bond that changes in steps rather than continuously. |
Utilities¶
Conversions¶
Converts a frequency in Hertz to a MIDI note number. |
|
Converts a MIDI note number to the corresponding frequency in Hertz. |
|
Converts a MIDI interval to the corresponding frequency interval in |
|
Generates a list of frequencies based on a list of semitones and a starting frequency. |
|
Converts a difference in decibels to a difference in amplitude. |
|
Converts a difference in amplitude to a difference in decibels. |
|
Returns durations from rhythmic patterns. |
Combining sonic vectors¶
Creates a horizontal stack of arrays while preserving bidimensional |
|
Mixes two sonic vectors. |
|
The name this had while it was the second mixer rather than the general one. |
|
Mix sonic vectors of arbitrary lengths. |
|
Mix any number of sonic vectors, each at its own offset. |
|
Mixes two stereo sonic vectors. |
|
Mix two sonic vector by placing the beginning of the second one a specified number of seconds after the first one. |
|
The name this had before it was renamed for saying, in the name, how it differs from |
|
Converts a sound vector to stereo format. |
|
Resolve stereo arguments for a function. |
|
Applies pan transitions to a sonic vector. |
|
Summarize a namespace of variables. |
Wavetables¶
Provides primary tables for waveform lookup. |
|
One period of a primary waveform, as a lookup table. |
WAVEFORM_SINE, WAVEFORM_TRIANGULAR, WAVEFORM_SQUARE and
WAVEFORM_SAWTOOTH are the lookup tables used by default throughout the
package, and are the names that appear in the synthesis signatures above.
They are re-exported from the top level like everything else, so
music.note(waveform_table=music.WAVEFORM_SINE) works;
music.WAVEFORMS names the shapes waveform_table() can build.
Singing¶
sing() sings a lyric to a melody, one syllable a note, with either of
two backends that sing the same score at the same pitches for the same
lengths, so that the two can be compared.
The default, backend="psola", is the package’s own singer. espeak-ng
says each syllable, and Praat’s pitch-synchronous overlap-add, through
praat-parselmouth, holds it at its note’s pitch and makes it the note’s
length. A syllable said in less time than its note is said again, slower,
down to 80 words a minute, and only the middle of its vowel is lengthened,
so that its consonants keep the length they were said with. A long note is
sung with a vibrato, 0.35 semitones each way at 5.5 Hz, setting in a
quarter of a second into it, and the notes on the meter’s strong beats are
sung up to 2.3 dB louder, as abc2midi accents them for eCantorix. It sings
eCantorix’s effects, "tremolo", "melt" and "flite", with the
package’s own tremolo, reverberation and resampling. It needs
espeak-ng and pip install 'music[singing]', and sing() says
which is missing.
backend="ecantorix" sings the same score with the external
eCantorix engine, the default until
the package had its own singer, kept as the reference. Run
setup_engine() once to clone it; it also needs git, make,
perl, espeak, abc2midi (the abcmidi package) and sox
on the system, and the Perl modules MIDI, Math::FFT,
URI::Escape and Digest::SHA. setup_engine() and sing()
say which are missing.
The examples singing_backends.py and singing_effects.py sing the
same songs, and the effects, with both. tools/compare_singing.py
measures both backends’ pitch, length and render time against the score;
tools/compare_singing_timing.py renders timings and syllable shapes for
a level-matched listening review; and tools/score_singing_asr.py has
Whisper, with pip install faster-whisper, count the words it hears in
each.
Sing a line of text to a melody. |
|
Clone the eCantorix repository into the user's cache directory. |
|
Return the path to the local eCantorix engine. |
|
Sing a short phrase with eCantorix, to check the engine works. |
Legacy¶
Synthesizer classes kept for backwards compatibility, and as material for making more music.
A configurable sequence walker that renders notes. |
|
Simple synthesizer for sound synthesis with vibrato, tremolo, and ADSR. |
|
A synthesizer that iterates through arbitrary lists of variables. |