Real-time oscillator voice with ADSR, pitch envelope, LFO and a resonant filter. More...
| Import Statement: | import Clayground.Sound |
SynthInstrument owns an internal audio engine and one oscillator instrument. Call triggerNote() to fire a note; tweak the patch via properties. It can also bake() a note to a WAV on disk for later reuse as a SampleInstrument source.
One of "sine", "square", "triangle", "sawtooth", "noise".
For "square" only: the fraction of each period the wave is high, 0.05..0.95. The default 0.5 is the plain square; 0.25 or 0.125 give the thinner, nasal pulses of chip sound.
ADSR envelope, all in seconds.
Pitch envelope: slide from pitchStart semitones above the trigger frequency to pitchEnd over pitchTime seconds. Set all to 0 for a flat pitch.
LFO in Hz/semitones targeting "pitch", "volume", or "none".
The filter after the oscillator: "none" (the default, bypassed), "lowpass", "highpass" or "bandpass". It is a two-pole state-variable filter, 12 dB per octave; the band-pass passes the cutoff at unity gain.
Cutoff frequency in Hz, 20..20000, default 1000. Ignored while filterType is "none".
Peak at the cutoff, 0..1: 0 (the default) is flat (Q 0.707), 1 is Q 10, about +20 dB.
Cutoff envelope: an ADSR of its own (seconds; sustain 0..1, default 1) that moves cutoff up by filterEnvAmount octaves at its peak, or down if the amount is negative. The default amount 0 keeps the cutoff fixed. A pluck: "lowpass", cutoff 400, filterEnvAmount 3, filterDecay 0.2, filterSustain 0.
Post-mix volume, 0..1.
Stereo position, -1 (left) .. +1 (right). The default 0 plays centred, the same samples in both channels. Panning turns the far channel down: at 0.5 the left plays at half level, the right at full. Moving it moves notes already ringing.
The mixer bus the voices play through: "sfx" (the default), "music" or "voice". Its volume is set on SoundMixer. Any other name is refused with a warning and the bus stays as it was.
At most this many voices ring at once. A note that would exceed it cuts the oldest voice of this instrument, without a release. The default 0 is no cap.
Read-only. Number of voices currently rendering.
Fire a note. midiNote 69 is A4. Returns true on success.
Same as triggerNote() but specifies pitch in Hz.
Render one note with the current patch into a WAV under the app cache directory and return its absolute path. Repeated bakes of the same inputs hit the cache and return the same filename.
Returns a QVector<float> of audio samples (destructive: advances the live engine). Primarily for tests.
See also SampleInstrument and SongPlayer.