music.IteratorSynth¶
- class music.IteratorSynth(**statevars)[source]¶
Bases:
CanonicalSynthA synthesizer that iterates through arbitrary lists of variables.
Inherits from CanonicalSynth.
It adds no attributes of its own.
Examples
>>> isynth = music.IteratorSynth() >>> isynth.fundamental_frequency_sequence = [220, 400, 100, 500] >>> isynth.duration_sequence = [2, 1, 1.5] >>> isynth.vibrato_frequency_sequence = [3, 6.5, 10] >>> sounds = [] >>> for i in range(300): ... sounds += [isynth.renderIterate(tremolo_frequency=.2*i)] >>> import music.core.io >>> music.core.io.write_wav_mono(music.horizontal_stack(*sounds), ... "./example.wav")
- __init__(**statevars)¶
Initializes the synthesizer with given state variables.
- Parameters:
- **statevars
dict Arbitrary keyword arguments for state variables.
- **statevars
Methods
__init__(**statevars)Initializes the synthesizer with given state variables.
absorbState(**statevars)Absorb state variables.
adsrApply(audio_vec)Apply ADSR envelope to the audio vector.
adsrSetup([A, D, S, R, render_note, adsr_method])Setup ADSR parameters.
Iterates through the sequences of state variables.
rawRender(**statevars)Render the sound without applying ADSR.
render(**statevars)Render a note with given parameters.
render2(**statevars)Render the sound and apply ADSR.
renderIterate(**statevars)Renders a sound iteration with the given state variables.
synthSetup([table, vibrato_table, ...])Setup synth engine.
tremoloEnvelope([sonic_vector])Calculate the tremolo envelope.
Attributes
- renderIterate(**statevars)[source]¶
Renders a sound iteration with the given state variables.
- Parameters:
- **statevars
Arbitrary keyword arguments for state variables.
- Returns:
listA list representing the rendered sound.
- absorbState(**statevars)¶
Absorb state variables.
- Parameters:
- **statevars
dict Arbitrary keyword arguments for state variables.
- **statevars
- adsrApply(audio_vec)¶
Apply ADSR envelope to the audio vector.
- Parameters:
- audio_vecarray_like
Input audio vector.
- Returns:
- array_like
Audio vector with applied ADSR envelope. A stereo vector has each channel shaped alike.
- adsrSetup(A=100.0, D=40, S=-5.0, R=50, render_note=False, adsr_method='absolute')¶
Setup ADSR parameters.
- Parameters:
- A
float, optional Attack time in milliseconds, by default 100.
- D
int, optional Decay time in milliseconds, by default 40.
- S
float, optional Sustain level in decibels, by default -5.
- R
int, optional Release time in milliseconds, by default 50.
- render_notebool, optional
Stored as an attribute and not read: rendering the note here was never implemented. By default False.
- adsr_method
str, optional The ADSR method, by default “absolute”. Stored and not read either: “absolute” is the only one there is.
- A
- Raises:
ValueErrorIf A, D or R is negative. A negative release reached numpy as a negative count of samples, and a negative attack or decay left stages that did not meet.
- rawRender(**statevars)¶
Render the sound without applying ADSR.
- Parameters:
- **statevars
dict Arbitrary keyword arguments for state variables.
- **statevars
- Returns:
- array_like
Rendered audio vector.
- render(**statevars)¶
Render a note with given parameters.
- Parameters:
- **statevars
dict Arbitrary keyword arguments for state variables.
- **statevars
- Returns:
- array_like
Rendered audio vector.
- render2(**statevars)¶
Render the sound and apply ADSR.
- Parameters:
- **statevars
dict Arbitrary keyword arguments for state variables.
- **statevars
- Returns:
- array_like
Rendered audio vector with applied ADSR envelope.
Notes
This is
rawRender()with the envelope, and no tremolo. It used to repeat that routine but for the table’s length, which it took fromtables.sizerather than fromtable: a table of any other length played at the wrong rate and read only part of itself.
- synthSetup(table=None, vibrato_table=None, tremolo_table=None, vibrato_depth=0.1, vibrato_frequency=2.0, tremolo_depth=3.0, tremolo_frequency=0.2, duration=2, fundamental_frequency=220)¶
Setup synth engine. ADSR is configured separately.
- Parameters:
- tablearray_like, optional
The waveform table for sound synthesis, by default None.
- vibrato_tablearray_like, optional
The waveform table for vibrato oscillatory pattern, by default None.
- tremolo_tablearray_like, optional
The waveform table for tremolo oscillatory pattern, by default None.
- vibrato_depth
float, optional The depth of vibrato in semitones, by default 0.1.
- vibrato_frequency
float, optional The frequency of the vibrato oscillations in Hertz, by default 2.0.
- tremolo_depth
float, optional The depth of tremolo in decibels, by default 3.0.
- tremolo_frequency
float, optional The frequency of the tremolo oscillations in Hertz, by default 0.2.
- duration
float, optional The duration of the note in seconds, by default 2.
- fundamental_frequency
float, optional The fundamental frequency of the note in Hertz, by default 220.
- tremoloEnvelope(sonic_vector=None, **statevars)¶
Calculate the tremolo envelope.
- Parameters:
- sonic_vectorarray_like, optional
Input sonic vector, by default None.
- **statevars
dict Arbitrary keyword arguments for state variables.
- Returns:
- array_like
Tremolo envelope, or the sonic vector under it: a stereo one has each channel shaped alike.