music.CanonicalSynth¶
- class music.CanonicalSynth(**statevars)[source]¶
Bases:
objectSimple synthesizer for sound synthesis with vibrato, tremolo, and ADSR.
All functions but absorbState return a sonic array. You can parametrize the synth in any function call. If you want to keep some set of states for specific calls, clone your CanonicalSynth or create a new instance. You can also pass arbitrary variables to use later on.
- Parameters:
- fscalar
The frequency of the note in Hertz.
- dscalar
The duration of the note in seconds.
- fvscalar
The frequency of the vibrato oscillations in Hertz.
- nuscalar
The maximum deviation of pitch in the vibrato in semitones.
- tabarray_like
The table with the waveform to synthesize the sound.
- tabvarray_like
The table with the waveform of the vibrato oscillatory pattern.
Examples
>>> cs = CanonicalSynth() # TODO: develop example
- __init__(**statevars)[source]¶
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.
rawRender(**statevars)Render the sound without applying ADSR.
render(**statevars)Render a note with given parameters.
render2(**statevars)Render the sound and apply ADSR.
synthSetup([table, vibrato_table, ...])Setup synth engine.
tremoloEnvelope([sonic_vector])Calculate the tremolo envelope.
Attributes
- 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)[source]¶
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.
- tablearray_like,
- adsrSetup(A=100.0, D=40, S=-5.0, R=50, render_note=False, adsr_method='absolute')[source]¶
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 Whether to render the note immediately, by default False.
- adsr_method
str,optional The ADSR method, by default “absolute”.
- A
- adsrApply(audio_vec)[source]¶
Apply ADSR envelope to the audio vector.
- Parameters:
- audio_vecarray_like
Input audio vector.
- Returns:
- array_like
Audio vector with applied ADSR envelope.
- render(**statevars)[source]¶
Render a note with given parameters.
- Parameters:
- **statevars
dict Arbitrary keyword arguments for state variables.
- **statevars
- Returns:
- array_like
Rendered audio vector.
- tremoloEnvelope(sonic_vector=None, **statevars)[source]¶
Calculate the tremolo envelope.
- Parameters:
- sonic_vectorarray_like,
optional Input sonic vector, by default None.
- **statevars
dict Arbitrary keyword arguments for state variables.
- sonic_vectorarray_like,
- Returns:
- array_like
Tremolo envelope.
- absorbState(**statevars)[source]¶
Absorb state variables.
- Parameters:
- **statevars
dict Arbitrary keyword arguments for state variables.
- **statevars
- rawRender(**statevars)[source]¶
Render the sound without applying ADSR.
- Parameters:
- **statevars
dict Arbitrary keyword arguments for state variables.
- **statevars
- Returns:
- array_like
Rendered audio vector.
- render2(**statevars)[source]¶
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.