Vital
|
A core oscillator processor that generates audio by reading wavetable data with various effects. More...
#include <synth_oscillator.h>
Classes | |
struct | VoiceBlock |
A helper struct for loading per-voice data during audio processing. More... | |
Public Member Functions | |
SynthOscillator (Wavetable *wavetable) | |
Constructs a SynthOscillator with the specified Wavetable. | |
void | reset (poly_mask reset_mask, poly_int sample) |
Resets oscillator state with an offset sample count. | |
void | reset (poly_mask reset_mask) override |
Resets oscillator phase and other variables for specified voices. | |
void | setSpectralMorphValues (SpectralMorph spectral_morph) |
Sets the spectral morph values for internal morphing. | |
void | setDistortionValues (DistortionType distortion_type) |
Sets the distortion values for internal waveshaping/fm/rm. | |
void | process (int num_samples) override |
Processes the oscillator for a given number of samples, writing to the output buffers. | |
Processor * | clone () const override |
Clones this oscillator, returning a new instance with the same parameters. | |
void | setFirstOscillatorOutput (Output *oscillator) |
Assigns an oscillator Output pointer for FM/RM modulation (first mod oscillator). | |
void | setSecondOscillatorOutput (Output *oscillator) |
Assigns an oscillator Output pointer for FM/RM modulation (second mod oscillator). | |
void | setSampleOutput (Output *sample) |
Assigns a sample Output pointer for FM/RM modulation using a sample. | |
void | setOversampleAmount (int oversample) override |
Overrides the base Processor method to set oversampling. Ensures internal buffers are large enough. | |
![]() | |
Processor (int num_inputs, int num_outputs, bool control_rate=false, int max_oversample=1) | |
Constructs a Processor with a given number of inputs/outputs and oversampling. | |
virtual | ~Processor () |
Virtual destructor. | |
virtual bool | hasState () const |
Indicates whether this Processor requires per-voice state. | |
virtual void | processWithInput (const poly_float *audio_in, int num_samples) |
An optional processing function taking explicit input buffer. Fallback is an assertion failure (not supported). | |
virtual void | init () |
Called after constructor, used for any additional initialization. Subclasses can override. Sets the initialized flag. | |
virtual void | hardReset () |
Called to perform a "hard" reset for all voices. | |
bool | initialized () |
Returns whether this Processor has been initialized. | |
virtual void | setSampleRate (int sample_rate) |
Updates the sample rate of this Processor (scaled by oversampling). | |
force_inline bool | enabled () const |
Checks if this Processor is enabled. | |
virtual void | enable (bool enable) |
Enables or disables this Processor. | |
force_inline int | getSampleRate () const |
Retrieves the current (effective) sample rate. | |
force_inline int | getOversampleAmount () const |
Retrieves the current oversampling factor. | |
force_inline bool | isControlRate () const |
Checks if this Processor is running at control rate (buffer_size == 1). | |
virtual void | setControlRate (bool control_rate) |
Sets whether this Processor runs at control rate. | |
force_inline poly_mask | getResetMask (int input_index) const |
Retrieves a mask indicating which voices triggered a note-on event. Compares the input's trigger_value to kVoiceOn. | |
force_inline void | clearOutputBufferForReset (poly_mask reset_mask, int input_index, int output_index) const |
Clears output samples for voices that are about to be reset, based on the trigger offset. | |
bool | inputMatchesBufferSize (int input=0) |
Checks whether the buffer size of a particular input matches the size needed by this Processor. | |
bool | checkInputAndOutputSize (int num_samples) |
Checks if all inputs and outputs have buffers big enough for num_samples . | |
virtual bool | isPolyphonic () const |
Checks if this Processor is polyphonic by querying its ProcessorRouter. | |
void | plug (const Output *source) |
Connects an external Output to this Processor's first input. | |
void | plug (const Output *source, unsigned int input_index) |
Connects an external Output to a specified input index. | |
void | plug (const Processor *source) |
Connects the first output of a Processor to this Processor's first input. | |
void | plug (const Processor *source, unsigned int input_index) |
Connects the first output of a Processor to a specified input index. | |
void | plugNext (const Output *source) |
Connects an external Output to the first available (unplugged) input. | |
void | plugNext (const Processor *source) |
Connects the first output of a Processor to the first available (unplugged) input. | |
void | useInput (Input *input) |
Uses an existing Input object as this Processor's first input. | |
void | useInput (Input *input, int index) |
Uses an existing Input object at a specified input index. | |
void | useOutput (Output *output) |
Uses an existing Output object as this Processor's first output. | |
void | useOutput (Output *output, int index) |
Uses an existing Output object at a specified output index. | |
int | connectedInputs () |
Counts how many inputs are connected to a real source (not null_source_). | |
virtual void | unplugIndex (unsigned int input_index) |
Removes the connection at a specified input index, if any. | |
virtual void | unplug (const Output *source) |
Removes a connection to a given Output from all inputs. | |
virtual void | unplug (const Processor *source) |
Removes connections to all outputs from a given Processor. | |
virtual void | numInputsChanged () |
Called when the number of inputs changes (e.g., new connections). Subclasses may override for dynamic behavior. | |
force_inline void | router (ProcessorRouter *router) |
Sets the ProcessorRouter that owns or manages this Processor. | |
force_inline ProcessorRouter * | router () const |
Returns the ProcessorRouter that currently owns this Processor. | |
ProcessorRouter * | getTopLevelRouter () const |
Gets the topmost (root) ProcessorRouter by traversing parent routers. | |
virtual void | registerInput (Input *input, int index) |
Registers a new input, appending it to the input list. | |
virtual Output * | registerOutput (Output *output, int index) |
Registers a new Output in the output list at a specified index. | |
virtual void | registerInput (Input *input) |
Registers a new Input by appending it to the end of the input list. | |
virtual Output * | registerOutput (Output *output) |
Registers a new Output by appending it to the end of the output list. | |
force_inline int | numInputs () const |
Returns the total number of Input pointers (owned or otherwise). | |
force_inline int | numOutputs () const |
Returns the total number of Output pointers (owned or otherwise). | |
force_inline int | numOwnedInputs () const |
Returns how many Input objects this Processor owns. | |
force_inline int | numOwnedOutputs () const |
Returns how many Output objects this Processor owns. | |
force_inline Input * | input (unsigned int index=0) const |
Retrieves the Input pointer at a given index. | |
force_inline bool | isInputSourcePolyphonic (int index=0) |
Checks if the input source at a given index is polyphonic. | |
force_inline Input * | ownedInput (unsigned int index=0) const |
Retrieves an owned Input pointer at a given index. | |
force_inline Output * | output (unsigned int index=0) const |
Retrieves the Output pointer at a given index. | |
force_inline Output * | ownedOutput (unsigned int index=0) const |
Retrieves an owned Output pointer at a given index. | |
void | setPluggingStart (int start) |
Sets the position at which plugNext starts searching for an open input. | |
Static Public Member Functions | |
static bool | isFirstModulation (int type) |
Checks if distortion type uses the first modulation oscillator. | |
static bool | isSecondModulation (int type) |
Checks if distortion type uses the second modulation oscillator. | |
static void | setDistortionValues (DistortionType distortion_type, poly_float *values, int num_values, bool spread) |
Sets distortion values for an array of poly_float, handling unison spread if necessary. | |
static void | setSpectralMorphValues (SpectralMorph spectral_morph, poly_float *values, int num_values, bool spread) |
Sets spectral morph values for an array of poly_float, handling unison spread if necessary. | |
static void | runSpectralMorph (SpectralMorph morph_type, float morph_amount, const Wavetable::WavetableData *wavetable_data, int wavetable_index, poly_float *dest, FourierTransform *transform) |
Applies a spectral morph operation (e.g., vocode, smear) directly on a buffer. | |
static vital::poly_int | adjustPhase (DistortionType distortion_type, poly_int phase, poly_float distortion_amount, poly_int distortion_phase) |
Adjusts phase for sync, formant, quantize, etc. | |
static vital::poly_float | getPhaseWindow (DistortionType distortion_type, poly_int phase, poly_int distorted_phase) |
Retrieves a window multiplier (for example, half-sin window in formant mode). | |
static poly_float | interpolate (const mono_float *buffer, const poly_int indices) |
Performs linear interpolation on a single wave buffer. | |
static bool | usesDistortionPhase (DistortionType distortion_type) |
Checks if a given distortion type uses a separate distortion_phase (kSync, kQuantize, etc). | |
Static Public Attributes | |
static constexpr int | kMaxUnison = 16 |
Maximum number of unison voices. | |
static constexpr int | kPolyPhasePerVoice = kMaxUnison / poly_float::kSize |
Number of poly phases used per voice. | |
static constexpr int | kNumPolyPhase = kMaxUnison / 2 |
Number of poly phases total. | |
static constexpr int | kNumBuffers = kNumPolyPhase * poly_float::kSize |
Number of buffers to store waveforms, based on the number of poly phases. | |
static constexpr int | kSpectralBufferSize = Wavetable::kWaveformSize * 2 / poly_float::kSize + poly_float::kSize |
Size of spectral buffer for Fourier transforms. | |
static const mono_float | kStackMultipliers [kNumUnisonStackTypes][kNumPolyPhase] |
Precomputed multipliers used for stacking unison voices into intervals. | |
Additional Inherited Members | |
![]() | |
Output * | addOutput (int oversample=1) |
Creates and registers a new Output. Handles control rate vs. audio rate. | |
Input * | addInput () |
Creates and registers a new Input, initially connected to null_source_. | |
![]() | |
std::shared_ptr< ProcessorState > | state_ |
Shared state (sample rate, oversample, etc.) | |
int | plugging_start_ |
The index at which plugNext starts searching for an unplugged input. | |
std::vector< std::shared_ptr< Input > > | owned_inputs_ |
Inputs owned by this Processor. | |
std::vector< std::shared_ptr< Output > > | owned_outputs_ |
Outputs owned by this Processor. | |
std::shared_ptr< std::vector< Input * > > | inputs_ |
All inputs, owned or external. | |
std::shared_ptr< std::vector< Output * > > | outputs_ |
All outputs, owned or external. | |
ProcessorRouter * | router_ |
The ProcessorRouter that manages this Processor. | |
![]() | |
static const Output | null_source_ |
A null (dummy) source used for unconnected inputs. | |
A core oscillator processor that generates audio by reading wavetable data with various effects.
This class handles unison, spectral morphing, distortion, FM/RM modulation, and more. It inherits from Processor, allowing it to be part of Vital's modular audio graph.
anonymous enum |
Enumerator | |
---|---|
kWaveFrame | Waveform frame selection. |
kMidiNote | MIDI note (for pitch) |
kMidiTrack | MIDI tracking toggle. |
kSmoothlyInterpolate | Not used directly in this file, but part of the Vital architecture. |
kTranspose | Transpose amount. |
kTransposeQuantize | Transpose quantize setting. |
kTune | Fine tune. |
kAmplitude | Output amplitude. |
kPan | Stereo panning. |
kUnisonVoices | Number of unison voices. |
kUnisonDetune | Unison detune amount. |
kPhase | Phase offset. |
kDistortionPhase | Phase distortion offset. |
kRandomPhase | Random phase amount. |
kBlend | Blend between center voice and detuned voices. |
kStereoSpread | Stereo spread amount. |
kStackStyle | Unison stack style. |
kDetunePower | Detune power exponent. |
kDetuneRange | Detune range. |
kUnisonFrameSpread | Unison wavetable frame spread. |
kUnisonDistortionSpread | Unison distortion spread. |
kUnisonSpectralMorphSpread | Unison spectral morph spread. |
kSpectralMorphType | Spectral morph type. |
kSpectralMorphAmount | Spectral morph amount. |
kSpectralUnison | Toggle for spectral unison. |
kDistortionType | Distortion type. |
kDistortionAmount | Distortion amount. |
kActiveVoices | Active voice mask. |
kReset | Manual reset (phase reset) |
kRetrigger | Retrigger mask. |
kNumInputs | Number of inputs. |
anonymous enum |
Enumerator | |
---|---|
kRaw | Unleveled or "raw" output. |
kLevelled | Output after amplitude leveling/panning. |
kNumOutputs | Number of outputs. |
Types of distortion/waveshaping used by the oscillator.
Types of spectral morph effects that can be applied to the wavetable.
Ways to stack unison voices for chord or harmonic effects.
vital::SynthOscillator::SynthOscillator | ( | Wavetable * | wavetable | ) |
Constructs a SynthOscillator with the specified Wavetable.
wavetable | A pointer to the wavetable used for generating wave data. |
|
static |
Adjusts phase for sync, formant, quantize, etc.
distortion_type | Type of distortion. |
phase | Current phase to be distorted. |
distortion_amount | Amount of distortion to apply. |
distortion_phase | Additional phase offset used by certain distortion types. |
|
inlineoverridevirtual |
Clones this oscillator, returning a new instance with the same parameters.
Implements vital::Processor.
|
static |
Retrieves a window multiplier (for example, half-sin window in formant mode).
distortion_type | The distortion type. |
phase | The original oscillator phase. |
distorted_phase | The phase after distortion. |
|
static |
Performs linear interpolation on a single wave buffer.
buffer | The buffer of mono_float samples. |
indices | The poly_int of indices to read from. |
|
inlinestatic |
Checks if distortion type uses the first modulation oscillator.
type | The distortion type. |
|
inlinestatic |
Checks if distortion type uses the second modulation oscillator.
type | The distortion type. |
|
overridevirtual |
Processes the oscillator for a given number of samples, writing to the output buffers.
num_samples | The number of audio samples to generate. |
Implements vital::Processor.
|
overridevirtual |
Resets oscillator phase and other variables for specified voices.
reset_mask | The mask indicating which voices to reset. |
Reimplemented from vital::Processor.
Resets oscillator state with an offset sample count.
reset_mask | The mask indicating which voices need resetting. |
sample | A poly_int sample offset for retrigger. |
|
static |
Applies a spectral morph operation (e.g., vocode, smear) directly on a buffer.
morph_type | The spectral morph type. |
morph_amount | The amount of morphing to apply (0.0 - 1.0). |
wavetable_data | Pointer to the original wavetable data. |
wavetable_index | Which frame of the wavetable to process. |
dest | Pointer to the destination buffer for the result. |
transform | Pointer to the Fourier transform helper. |
void vital::SynthOscillator::setDistortionValues | ( | DistortionType | distortion_type | ) |
Sets the distortion values for internal waveshaping/fm/rm.
distortion_type | The type of distortion to apply. |
|
static |
Sets distortion values for an array of poly_float, handling unison spread if necessary.
distortion_type | The type of distortion used. |
values | Pointer to the poly_float array to modify. |
num_values | The number of items in the array. |
spread | True if a unison spread is applied to these values. |
|
inline |
|
inlineoverridevirtual |
Overrides the base Processor method to set oversampling. Ensures internal buffers are large enough.
oversample | The new oversampling factor. |
Reimplemented from vital::Processor.
|
inline |
|
inline |
void vital::SynthOscillator::setSpectralMorphValues | ( | SpectralMorph | spectral_morph | ) |
Sets the spectral morph values for internal morphing.
spectral_morph | The type of spectral morph. |
|
static |
Sets spectral morph values for an array of poly_float, handling unison spread if necessary.
spectral_morph | The type of spectral morph to apply. |
values | Pointer to the poly_float array to modify. |
num_values | The number of items in the array. |
spread | True if a unison spread is applied to these values. |
|
static |
Checks if a given distortion type uses a separate distortion_phase (kSync, kQuantize, etc).
distortion_type | The distortion type. |
|
staticconstexpr |
Maximum number of unison voices.
|
staticconstexpr |
Number of buffers to store waveforms, based on the number of poly phases.
|
staticconstexpr |
Number of poly phases total.
|
staticconstexpr |
Number of poly phases used per voice.
|
staticconstexpr |
Size of spectral buffer for Fourier transforms.
|
static |
Precomputed multipliers used for stacking unison voices into intervals.