11 class FourierTransform;
32 static constexpr int kSeed = 0x4;
56 data_ = std::make_unique<poly_float[]>(num_poly_floats);
58 generator.seed(
kSeed);
59 for (
int i = 0; i < num_poly_floats; ++i)
60 data_[i] = generator.polyNext();
64 std::unique_ptr<poly_float[]> data_;
268 poly_float* values,
int num_values,
bool spread);
278 poly_float* values,
int num_values,
bool spread);
364 void process(
int num_samples)
override;
409 void processOscillators(
int num_samples,
DistortionType distortion_type);
428 void processBlend(
int num_samples,
poly_mask reset_mask);
436 void loadVoiceBlock(VoiceBlock& voice_block,
int index,
poly_mask active_mask);
441 void resetWavetableBuffers();
447 void setActiveOscillators(
int new_active_oscillators);
458 template<poly_
float(*snapTranspose)(poly_
float, poly_
float,
float*)>
459 void setPhaseIncBufferSnap(
int num_samples,
poly_mask reset_mask,
469 void setPhaseIncBuffer(
int num_samples,
poly_mask reset_mask,
475 void setPhaseIncMults();
480 void setupShepardWrap();
485 void clearShepardWrap();
492 void doShepardWrap(
poly_mask new_buffer_mask,
int quantize);
504 void setWaveBuffers(
poly_float phase_inc,
int index);
519 void computeSpectralWaveBufferPair(
int phase_update,
int index,
bool formant_shift,
520 float phase_adjustment,
poly_int wave_index,
532 void setFourierWaveBuffers(
poly_float phase_inc,
int index,
bool formant_shift);
565 static constexpr int kBaseSampleRate = 44100;
567 float adjustment = 1.0f;
569 while (sample_rate_mult > 1) {
570 sample_rate_mult >>= 1;
594 poly_float pan_amplitude_;
595 poly_float center_amplitude_;
596 poly_float detuned_amplitude_;
597 poly_float midi_note_;
598 poly_float distortion_phase_;
599 poly_float blend_stereo_multiply_;
600 poly_float blend_center_multiply_;
614 VoiceBlock voice_block_;
617 utils::RandomGenerator random_generator_;
620 int transpose_quantize_;
622 poly_float last_quantized_transpose_;
624 poly_float last_quantize_ratio_;
628 int active_oscillators_;
631 Wavetable* wavetable_;
633 int wavetable_version_;
636 Output* first_mod_oscillator_;
637 Output* second_mod_oscillator_;
645 std::shared_ptr<FourierTransform> fourier_transform_;
647 std::shared_ptr<Output> phase_inc_buffer_;
649 std::shared_ptr<PhaseBuffer> phase_buffer_;
Base class for all signal-processing units in Vital.
Definition processor.h:212
virtual void setOversampleAmount(int oversample)
Sets the oversampling amount and updates the effective sample rate.
Definition processor.h:293
force_inline int getSampleRate() const
Retrieves the current (effective) sample rate.
Definition processor.h:326
A singleton class that generates and stores random poly_float values.
Definition synth_oscillator.h:29
static constexpr int kSeed
Seed value for internal random generator.
Definition synth_oscillator.h:32
const poly_float * buffer()
Get the internal random data buffer.
Definition synth_oscillator.h:48
static RandomValues * instance()
Retrieve the singleton instance of RandomValues.
Definition synth_oscillator.h:38
A core oscillator processor that generates audio by reading wavetable data with various effects.
Definition synth_oscillator.h:74
void process(int num_samples) override
Processes the oscillator for a given number of samples, writing to the output buffers.
Definition synth_oscillator.cpp:1194
SynthOscillator(Wavetable *wavetable)
Constructs a SynthOscillator with the specified Wavetable.
Definition synth_oscillator.cpp:519
static bool isFirstModulation(int type)
Checks if distortion type uses the first modulation oscillator.
Definition synth_oscillator.h:185
DistortionType
Types of distortion/waveshaping used by the oscillator.
Definition synth_oscillator.h:145
@ kRmOscillatorB
RM using oscillator B.
Definition synth_oscillator.h:157
@ kFmOscillatorA
FM using oscillator A.
Definition synth_oscillator.h:153
@ kFmSample
FM using sample.
Definition synth_oscillator.h:155
@ kFmOscillatorB
FM using oscillator B.
Definition synth_oscillator.h:154
@ kNone
No distortion.
Definition synth_oscillator.h:146
@ kSqueeze
Squeeze distortion.
Definition synth_oscillator.h:151
@ kRmSample
RM using sample.
Definition synth_oscillator.h:158
@ kFormant
Formant shifting.
Definition synth_oscillator.h:148
@ kPulseWidth
Pulse width distortion.
Definition synth_oscillator.h:152
@ kRmOscillatorA
RM using oscillator A.
Definition synth_oscillator.h:156
@ kQuantize
Quantization.
Definition synth_oscillator.h:149
@ kBend
Bend distortion.
Definition synth_oscillator.h:150
@ kNumDistortionTypes
Definition synth_oscillator.h:159
@ kSync
Sync distortion.
Definition synth_oscillator.h:147
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.
Definition synth_oscillator.cpp:1014
static constexpr int kPolyPhasePerVoice
Number of poly phases used per voice.
Definition synth_oscillator.h:201
static bool usesDistortionPhase(DistortionType distortion_type)
Checks if a given distortion type uses a separate distortion_phase (kSync, kQuantize,...
Definition synth_oscillator.cpp:1189
@ kMidiTrack
MIDI tracking toggle.
Definition synth_oscillator.h:83
@ kPhase
Phase offset.
Definition synth_oscillator.h:92
@ kDistortionAmount
Distortion amount.
Definition synth_oscillator.h:107
@ kRandomPhase
Random phase amount.
Definition synth_oscillator.h:94
@ kStereoSpread
Stereo spread amount.
Definition synth_oscillator.h:96
@ kReset
Manual reset (phase reset)
Definition synth_oscillator.h:109
@ kMidiNote
MIDI note (for pitch)
Definition synth_oscillator.h:82
@ kBlend
Blend between center voice and detuned voices.
Definition synth_oscillator.h:95
@ kSpectralMorphType
Spectral morph type.
Definition synth_oscillator.h:103
@ kDistortionPhase
Phase distortion offset.
Definition synth_oscillator.h:93
@ kTune
Fine tune.
Definition synth_oscillator.h:87
@ kUnisonVoices
Number of unison voices.
Definition synth_oscillator.h:90
@ kDetuneRange
Detune range.
Definition synth_oscillator.h:99
@ kRetrigger
Retrigger mask.
Definition synth_oscillator.h:110
@ kUnisonDistortionSpread
Unison distortion spread.
Definition synth_oscillator.h:101
@ kSpectralUnison
Toggle for spectral unison.
Definition synth_oscillator.h:105
@ kPan
Stereo panning.
Definition synth_oscillator.h:89
@ kTranspose
Transpose amount.
Definition synth_oscillator.h:85
@ kSmoothlyInterpolate
Not used directly in this file, but part of the Vital architecture.
Definition synth_oscillator.h:84
@ kDistortionType
Distortion type.
Definition synth_oscillator.h:106
@ kUnisonDetune
Unison detune amount.
Definition synth_oscillator.h:91
@ kSpectralMorphAmount
Spectral morph amount.
Definition synth_oscillator.h:104
@ kDetunePower
Detune power exponent.
Definition synth_oscillator.h:98
@ kAmplitude
Output amplitude.
Definition synth_oscillator.h:88
@ kUnisonSpectralMorphSpread
Unison spectral morph spread.
Definition synth_oscillator.h:102
@ kUnisonFrameSpread
Unison wavetable frame spread.
Definition synth_oscillator.h:100
@ kStackStyle
Unison stack style.
Definition synth_oscillator.h:97
@ kWaveFrame
Waveform frame selection.
Definition synth_oscillator.h:81
@ kNumInputs
Number of inputs.
Definition synth_oscillator.h:111
@ kActiveVoices
Active voice mask.
Definition synth_oscillator.h:108
@ kTransposeQuantize
Transpose quantize setting.
Definition synth_oscillator.h:86
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).
Definition synth_oscillator.cpp:1173
void setSecondOscillatorOutput(Output *oscillator)
Assigns an oscillator Output pointer for FM/RM modulation (second mod oscillator).
Definition synth_oscillator.h:382
void setSampleOutput(Output *sample)
Assigns a sample Output pointer for FM/RM modulation using a sample.
Definition synth_oscillator.h:388
void setOversampleAmount(int oversample) override
Overrides the base Processor method to set oversampling. Ensures internal buffers are large enough.
Definition synth_oscillator.h:394
SpectralMorph
Types of spectral morph effects that can be applied to the wavetable.
Definition synth_oscillator.h:126
@ kSmear
Smear morph.
Definition synth_oscillator.h:132
@ kRandomAmplitudes
Random amplitudes morph.
Definition synth_oscillator.h:133
@ kSkew
Skew morph.
Definition synth_oscillator.h:138
@ kFormScale
Formant scaling.
Definition synth_oscillator.h:129
@ kHarmonicScale
Harmonic scaling.
Definition synth_oscillator.h:130
@ kHighPass
Highpass morph.
Definition synth_oscillator.h:135
@ kInharmonicScale
Inharmonic scaling.
Definition synth_oscillator.h:131
@ kNoSpectralMorph
No spectral morph effect.
Definition synth_oscillator.h:127
@ kLowPass
Lowpass morph.
Definition synth_oscillator.h:134
@ kNumSpectralMorphTypes
Definition synth_oscillator.h:139
@ kShepardTone
Shepard tone morph.
Definition synth_oscillator.h:137
@ kPhaseDisperse
Phase dispersion.
Definition synth_oscillator.h:136
@ kVocode
Vocode morph.
Definition synth_oscillator.h:128
static constexpr int kNumBuffers
Number of buffers to store waveforms, based on the number of poly phases.
Definition synth_oscillator.h:205
Processor * clone() const override
Clones this oscillator, returning a new instance with the same parameters.
Definition synth_oscillator.h:370
void setFirstOscillatorOutput(Output *oscillator)
Assigns an oscillator Output pointer for FM/RM modulation (first mod oscillator).
Definition synth_oscillator.h:376
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.
Definition synth_oscillator.cpp:1112
static constexpr int kSpectralBufferSize
Size of spectral buffer for Fourier transforms.
Definition synth_oscillator.h:207
UnisonStackType
Ways to stack unison voices for chord or harmonic effects.
Definition synth_oscillator.h:165
@ kNormal
Standard unison.
Definition synth_oscillator.h:166
@ kMinorChord
Minor chord intervals.
Definition synth_oscillator.h:174
@ kNumUnisonStackTypes
Definition synth_oscillator.h:177
@ kOctave
Alternate between the base pitch and +1 octave.
Definition synth_oscillator.h:169
@ kOddHarmonicSeries
Odd harmonic series.
Definition synth_oscillator.h:176
@ kMajorChord
Major chord intervals.
Definition synth_oscillator.h:173
@ kHarmonicSeries
Harmonic series.
Definition synth_oscillator.h:175
@ kCenterDropOctave2
Shift center voice down two octaves.
Definition synth_oscillator.h:168
@ kOctave2
Alternate among the base pitch, +1 octave, +2 octaves.
Definition synth_oscillator.h:170
@ kPowerChord2
Extended power chord intervals.
Definition synth_oscillator.h:172
@ kCenterDropOctave
Shift center voice down an octave.
Definition synth_oscillator.h:167
@ kPowerChord
Power chord intervals.
Definition synth_oscillator.h:171
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.
Definition synth_oscillator.cpp:1070
@ kNumOutputs
Number of outputs.
Definition synth_oscillator.h:120
@ kLevelled
Output after amplitude leveling/panning.
Definition synth_oscillator.h:119
@ kRaw
Unleveled or "raw" output.
Definition synth_oscillator.h:118
static poly_float interpolate(const mono_float *buffer, const poly_int indices)
Performs linear interpolation on a single wave buffer.
Definition synth_oscillator.cpp:1185
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.
Definition synth_oscillator.cpp:1154
void reset(poly_mask reset_mask, poly_int sample)
Resets oscillator state with an offset sample count.
Definition synth_oscillator.cpp:558
static constexpr int kMaxUnison
Maximum number of unison voices.
Definition synth_oscillator.h:199
static const mono_float kStackMultipliers[kNumUnisonStackTypes][kNumPolyPhase]
Precomputed multipliers used for stacking unison voices into intervals.
Definition synth_oscillator.h:210
static constexpr int kNumPolyPhase
Number of poly phases total.
Definition synth_oscillator.h:203
static bool isSecondModulation(int type)
Checks if distortion type uses the second modulation oscillator.
Definition synth_oscillator.h:194
A class representing a wavetable, holding multiple frames of waveforms and their frequency-domain rep...
Definition wavetable.h:20
static constexpr int kNumHarmonics
Number of harmonics in the waveform (half the size plus one).
Definition wavetable.h:29
static constexpr int kWaveformSize
Size of each waveform frame.
Definition wavetable.h:25
A basic random number generator for producing uniform distributions of floats.
Definition utils.h:61
#define force_inline
Definition common.h:23
Contains classes and functions used within the Vital synthesizer framework.
constexpr int kMaxBufferSize
Maximum buffer size for processing.
Definition common.h:39
constexpr int kMaxOversample
Maximum allowed oversampling factor.
Definition common.h:40
float mono_float
Definition common.h:33
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
Holds a buffer of poly_int values for phase information.
Definition synth_oscillator.h:18
poly_int buffer[kMaxBufferSize *kMaxOversample]
Phase buffer array.
Definition synth_oscillator.h:20
A helper struct for loading per-voice data during audio processing.
Definition synth_oscillator.h:216
int total_samples
Total samples processed for this chunk.
Definition synth_oscillator.h:232
const mono_float * to_buffers[poly_float::kSize]
Definition synth_oscillator.h:257
const poly_float * modulation_buffer
Buffer for FM/RM modulation values.
Definition synth_oscillator.h:251
int start_sample
Sample offset to start processing for this voice.
Definition synth_oscillator.h:230
bool smoothing_enabled
Whether wave blending is smoothly interpolated.
Definition synth_oscillator.h:249
poly_float distortion
Current distortion amount.
Definition synth_oscillator.h:243
int end_sample
Sample offset to end processing for this voice.
Definition synth_oscillator.h:231
poly_float from_phase_inc_mult
Previous chunk's phase increment multiplier.
Definition synth_oscillator.h:236
const mono_float * from_buffers[poly_float::kSize]
Buffers used for crossfading from one wave to another.
Definition synth_oscillator.h:256
const poly_float * phase_inc_buffer
Phase increment buffer.
Definition synth_oscillator.h:252
poly_mask shepard_half_mask
Mask indicating voices that should shift by /2.
Definition synth_oscillator.h:239
bool isStatic() const
Checks if the from_buffers and to_buffers are identical (i.e., no crossfade needed).
Definition synth_oscillator.h:226
poly_int last_distortion_phase
Previous chunk's distortion phase.
Definition synth_oscillator.h:242
poly_int phase
Current oscillator phase.
Definition synth_oscillator.h:234
const poly_int * phase_buffer
Phase buffer to add to 'phase' each sample.
Definition synth_oscillator.h:253
int num_buffer_samples
Number of samples to fade between wave buffers.
Definition synth_oscillator.h:246
poly_int distortion_phase
Current distortion phase.
Definition synth_oscillator.h:241
poly_float phase_inc_mult
Current phase increment multiplier.
Definition synth_oscillator.h:235
poly_float last_distortion
Previous chunk's distortion amount.
Definition synth_oscillator.h:244
poly_int current_buffer_sample
Keeps track of fade progress.
Definition synth_oscillator.h:247
poly_mask shepard_double_mask
Mask indicating voices that should shift by *2.
Definition synth_oscillator.h:238
VoiceBlock()
Default constructor. Initializes all values to a safe default.
Definition synth_oscillator.cpp:504
SpectralMorph spectral_morph
The current spectral morph type.
Definition synth_oscillator.h:250
Struct holding all necessary data for the Wavetable, including multiple frames.
Definition wavetable.h:41
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...