|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
Polyphonic synthesizer with analog, FM and wavetable engines and a sample source. More...
#include <Synthesizer.h>
Public Types | |
| using | Engine = synthesizer::Engine |
| using | VoiceMode = synthesizer::VoiceMode |
| using | GlideMode = synthesizer::GlideMode |
| using | PhaseMode = synthesizer::PhaseMode |
| using | OscWave = synthesizer::OscWave |
| using | SubWave = synthesizer::SubWave |
| using | FilterType = synthesizer::FilterType |
| using | LfoMode = synthesizer::LfoMode |
| using | ModSource = synthesizer::ModSource |
| using | ModDest = synthesizer::ModDest |
| using | Param = synthesizer::Param |
| using | ParamInfo = synthesizer::ParamInfo |
Public Member Functions | |
| Synthesizer () noexcept | |
| ~Synthesizer () | |
| Synthesizer (const Synthesizer &)=delete | |
| Synthesizer & | operator= (const Synthesizer &)=delete |
| void | prepare (const AudioSpec &spec, int maxVoices=16) |
| Allocates the voices, buffers and oversamplers and builds the shared tables (minBLEP, sample kernel, built-in wavetables). | |
| void | reset () noexcept |
| Silences every voice, drops queued events and restarts the note count, the controllers and the free LFOs. Audio thread. | |
| int | getLatency () const noexcept |
| Output delay in base-rate samples (0 at 1x; 64 at 2x, 68 at 4x). | |
| int | getActiveVoiceCount () const noexcept |
| Voices sounding after the last block, stealing fades included. | |
| int | getMaxVoices () const noexcept |
Polyphony prepared (the upper bound of voice.polyphony). | |
| void | setParameter (Param param, float value) noexcept |
| Sets a parameter, clamped to its range and rounded to its steps; NaN is ignored. Takes effect at the next block. | |
| bool | setParameter (std::string_view id, float value) noexcept |
| Sets a parameter by id; false for an unknown id. | |
| float | getParameter (Param param) const noexcept |
| The value last set (any thread). | |
| void | setTempo (double bpm) noexcept |
| Tempo for tempo-synced LFOs, 1..999 BPM (default 120). | |
| bool | setSampleZones (std::span< const SampleZoneSpec< T > > zones) |
| Replaces the zones the sample source plays (sample.level). | |
| bool | loadSample (AudioBufferView< const T > audio, double sampleRate, int rootKey=60) |
| One zone over the whole keyboard and velocity range. | |
| void | clearSampleZones () |
| Removes the sample zones (the user wavetable is kept). | |
| bool | loadUserWavetable (const T *frames, int frameSize, int numFrames) |
| Loads the user wavetable (bank "User"): consecutive single-cycle frames, analysed as WavetableBank::loadFrames() does. | |
| void | noteOn (int key, T velocity, int offset=0) noexcept |
Starts a note offset samples into the next block; velocity 0..1 (0 is a note-off, as in MIDI). | |
| void | noteOnTuned (int key, T velocity, T tuningCents, int offset=0) noexcept |
| Starts a note with individual fine tuning in cents, clamped to -100..100. The tuned pitch is the glide target and combines with master tuning, oscillators/zones and pitch bend. Key identity, key modulation/tracking and sample-zone selection use the integer key. Fixed-frequency FM operators and untracked sample sources ignore it. Mono/legato return restores the tuning of the most recent key still held. Non-finite velocity or tuning is ignored. Zero velocity is note-off. Audio thread; the event applies at offset in the next block. | |
| void | noteOff (int key, T releaseVelocity=T(0), int offset=0) noexcept |
| Releases a note; releaseVelocity 0..1 is a modulation source. | |
| void | setPitchBend (T bend, int offset=0) noexcept |
| Pitch bend, -1..+1 (scaled by voice.bendRange semitones). | |
| void | setModWheel (T value, int offset=0) noexcept |
| Mod wheel (CC 1), 0..1. | |
| void | setChannelPressure (T value, int offset=0) noexcept |
| Channel pressure, 0..1. | |
| void | setPolyPressure (int key, T value, int offset=0) noexcept |
| Polyphonic pressure of one key, 0..1. | |
| void | setSustainPedal (bool down, int offset=0) noexcept |
| Sustain pedal: while down, released keys keep sounding. | |
| void | setController (int controller, T value, int offset=0) noexcept |
| A MIDI control change, value 0..1: 1 mod wheel, 2 breath, 11 expression (it also scales the amplifier, as MIDI defines), 64 sustain pedal (down at 0.5 and above), 120 and 123 all notes off. Other controllers are ignored. | |
| void | allNotesOff (int offset=0) noexcept |
| Releases every sounding note (and lifts the pedal). | |
| void | processBlock (AudioBufferView< T > out) noexcept |
Renders the block, overwriting out, and applies the queued events at their offsets. Allocation free, lock free. A block longer than prepare()'s maxBlockSize is rendered in pieces. | |
| std::vector< uint8_t > | getState () const |
| Serializes every parameter by id (allocates). Samples and the user wavetable are data, not parameters: they are not included. | |
| bool | setState (const uint8_t *data, size_t size) |
| Restores parameters from a blob (tolerant: missing ids keep their defaults, unknown ids are ignored; rejects foreign blobs). | |
Static Public Member Functions | |
| static constexpr const ParamInfo & | getParamInfo (Param p) noexcept |
| The description of a parameter. | |
| static int | findParam (std::string_view id) noexcept |
| Index of the parameter with this id, or -1. | |
Static Public Attributes | |
| static constexpr int | kMaxEvents = 1024 |
| static constexpr int | kNumParams = synthesizer::kNumParams |
| static constexpr int | kMaxUnison = synthesizer::kMaxUnison |
| static constexpr int | kModSlots = synthesizer::kModSlots |
| static constexpr int | kMaxPolyphony = synthesizer::kMaxPolyphony |
| static constexpr int | kControlPeriod = 16 |
| Base-rate samples between modulation evaluations (interpolated between). | |
Polyphonic synthesizer with analog, FM and wavetable engines and a sample source.
| T | Sample type (float or double). |
Definition at line 520 of file Synthesizer.h.
| using dspark::Synthesizer< T >::Engine = synthesizer::Engine |
Definition at line 528 of file Synthesizer.h.
| using dspark::Synthesizer< T >::FilterType = synthesizer::FilterType |
Definition at line 534 of file Synthesizer.h.
| using dspark::Synthesizer< T >::GlideMode = synthesizer::GlideMode |
Definition at line 530 of file Synthesizer.h.
| using dspark::Synthesizer< T >::LfoMode = synthesizer::LfoMode |
Definition at line 535 of file Synthesizer.h.
| using dspark::Synthesizer< T >::ModDest = synthesizer::ModDest |
Definition at line 537 of file Synthesizer.h.
| using dspark::Synthesizer< T >::ModSource = synthesizer::ModSource |
Definition at line 536 of file Synthesizer.h.
| using dspark::Synthesizer< T >::OscWave = synthesizer::OscWave |
Definition at line 532 of file Synthesizer.h.
| using dspark::Synthesizer< T >::Param = synthesizer::Param |
Definition at line 538 of file Synthesizer.h.
| using dspark::Synthesizer< T >::ParamInfo = synthesizer::ParamInfo |
Definition at line 539 of file Synthesizer.h.
| using dspark::Synthesizer< T >::PhaseMode = synthesizer::PhaseMode |
Definition at line 531 of file Synthesizer.h.
| using dspark::Synthesizer< T >::SubWave = synthesizer::SubWave |
Definition at line 533 of file Synthesizer.h.
| using dspark::Synthesizer< T >::VoiceMode = synthesizer::VoiceMode |
Definition at line 529 of file Synthesizer.h.
|
inlinenoexcept |
Definition at line 559 of file Synthesizer.h.
|
inline |
Definition at line 568 of file Synthesizer.h.
|
delete |
|
inlinenoexcept |
Releases every sounding note (and lifts the pedal).
Definition at line 832 of file Synthesizer.h.
|
inline |
Removes the sample zones (the user wavetable is kept).
Definition at line 733 of file Synthesizer.h.
|
inlinestaticnoexcept |
Index of the parameter with this id, or -1.
Definition at line 555 of file Synthesizer.h.
|
inlinenoexcept |
Voices sounding after the last block, stealing fades included.
Definition at line 650 of file Synthesizer.h.
|
inlinenoexcept |
Output delay in base-rate samples (0 at 1x; 64 at 2x, 68 at 4x).
Definition at line 647 of file Synthesizer.h.
|
inlinenoexcept |
Polyphony prepared (the upper bound of voice.polyphony).
Definition at line 656 of file Synthesizer.h.
|
inlinenoexcept |
The value last set (any thread).
Definition at line 682 of file Synthesizer.h.
|
inlinestaticconstexprnoexcept |
The description of a parameter.
Definition at line 549 of file Synthesizer.h.
|
inline |
Serializes every parameter by id (allocates). Samples and the user wavetable are data, not parameters: they are not included.
Definition at line 872 of file Synthesizer.h.
|
inline |
One zone over the whole keyboard and velocity range.
Definition at line 723 of file Synthesizer.h.
|
inline |
Loads the user wavetable (bank "User"): consecutive single-cycle frames, analysed as WavetableBank::loadFrames() does.
Definition at line 744 of file Synthesizer.h.
|
inlinenoexcept |
Releases a note; releaseVelocity 0..1 is a modulation source.
Definition at line 780 of file Synthesizer.h.
|
inlinenoexcept |
Starts a note offset samples into the next block; velocity 0..1 (0 is a note-off, as in MIDI).
Definition at line 757 of file Synthesizer.h.
|
inlinenoexcept |
Starts a note with individual fine tuning in cents, clamped to -100..100. The tuned pitch is the glide target and combines with master tuning, oscillators/zones and pitch bend. Key identity, key modulation/tracking and sample-zone selection use the integer key. Fixed-frequency FM operators and untracked sample sources ignore it. Mono/legato return restores the tuning of the most recent key still held. Non-finite velocity or tuning is ignored. Zero velocity is note-off. Audio thread; the event applies at offset in the next block.
Definition at line 770 of file Synthesizer.h.
|
delete |
|
inline |
Allocates the voices, buffers and oversamplers and builds the shared tables (minBLEP, sample kernel, built-in wavetables).
| spec | Sample rate and the largest block (channels are taken from the view at processBlock()). |
| maxVoices | Polyphony available to voice.polyphony, 1..kMaxPolyphony. Spare voices for stealing fades are added on top. |
Definition at line 589 of file Synthesizer.h.
|
inlinenoexcept |
Renders the block, overwriting out, and applies the queued events at their offsets. Allocation free, lock free. A block longer than prepare()'s maxBlockSize is rendered in pieces.
Definition at line 841 of file Synthesizer.h.
|
inlinenoexcept |
Silences every voice, drops queued events and restarts the note count, the controllers and the free LFOs. Audio thread.
Definition at line 619 of file Synthesizer.h.
|
inlinenoexcept |
Channel pressure, 0..1.
Definition at line 797 of file Synthesizer.h.
|
inlinenoexcept |
A MIDI control change, value 0..1: 1 mod wheel, 2 breath, 11 expression (it also scales the amplifier, as MIDI defines), 64 sustain pedal (down at 0.5 and above), 120 and 123 all notes off. Other controllers are ignored.
Definition at line 817 of file Synthesizer.h.
|
inlinenoexcept |
Mod wheel (CC 1), 0..1.
Definition at line 794 of file Synthesizer.h.
|
inlinenoexcept |
Sets a parameter, clamped to its range and rounded to its steps; NaN is ignored. Takes effect at the next block.
Definition at line 662 of file Synthesizer.h.
|
inlinenoexcept |
Sets a parameter by id; false for an unknown id.
Definition at line 673 of file Synthesizer.h.
|
inlinenoexcept |
Pitch bend, -1..+1 (scaled by voice.bendRange semitones).
Definition at line 787 of file Synthesizer.h.
|
inlinenoexcept |
Polyphonic pressure of one key, 0..1.
Definition at line 800 of file Synthesizer.h.
|
inline |
Replaces the zones the sample source plays (sample.level).
Validates and copies every zone (Sampler's rules) and publishes them without blocking the audio thread. A note plays the FIRST zone whose key and velocity ranges contain it, so velocity layers and multisamples work, but zones are not layered as in Sampler. The user wavetable is kept.
Definition at line 707 of file Synthesizer.h.
|
inline |
Restores parameters from a blob (tolerant: missing ids keep their defaults, unknown ids are ignored; rejects foreign blobs).
Definition at line 882 of file Synthesizer.h.
|
inlinenoexcept |
Sustain pedal: while down, released keys keep sounding.
Definition at line 806 of file Synthesizer.h.
|
inlinenoexcept |
Tempo for tempo-synced LFOs, 1..999 BPM (default 120).
Definition at line 689 of file Synthesizer.h.
|
staticconstexpr |
Base-rate samples between modulation evaluations (interpolated between).
Definition at line 546 of file Synthesizer.h.
|
staticconstexpr |
Maximum queued events between processBlock calls. Events beyond this capacity are ignored; hosts must split dense spans beforehand. Every event kind shares the same queue.
Definition at line 526 of file Synthesizer.h.
|
staticconstexpr |
Definition at line 544 of file Synthesizer.h.
|
staticconstexpr |
Definition at line 542 of file Synthesizer.h.
|
staticconstexpr |
Definition at line 543 of file Synthesizer.h.
|
staticconstexpr |
Definition at line 541 of file Synthesizer.h.