Vital
Loading...
Searching...
No Matches
oscillator_module.cpp
Go to the documentation of this file.
1#include "oscillator_module.h"
2
3#include "synth_oscillator.h"
4#include "wavetable.h"
5
6namespace vital {
7
14 SynthModule(kNumInputs, kNumOutputs), prefix_(std::move(prefix)), on_(nullptr), distortion_type_(nullptr) {
15 // Create a shared wavetable for this oscillator.
16 wavetable_ = std::make_shared<Wavetable>(kNumOscillatorWaveFrames);
17 // Track whether the oscillator was previously on.
18 was_on_ = std::make_shared<bool>(true);
19 }
20
27 // Create the internal SynthOscillator.
29
30 // Base controls.
31 createBaseControl(prefix_ + "_view_2d");
32 on_ = createBaseControl(prefix_ + "_on");
33 Value* midi_track = createBaseControl(prefix_ + "_midi_track");
34 Value* smooth_interpolation = createBaseControl(prefix_ + "_smooth_interpolation");
35 Value* spectral_unison = createBaseControl(prefix_ + "_spectral_unison");
36 Value* stack_style = createBaseControl(prefix_ + "_stack_style");
37 Value* transpose_quantize = createBaseControl(prefix_ + "_transpose_quantize");
38
39 // Inputs and outputs connected to oscillator parameters.
41
42 // Create mod controls (outputs) that can be connected to the oscillator parameters.
43 Output* wave_frame = createPolyModControl(prefix_ + "_wave_frame");
44 Output* transpose = createPolyModControl(prefix_ + "_transpose", true, false, nullptr, reset);
45 Output* tune = createPolyModControl(prefix_ + "_tune", true, false, nullptr, reset);
46 Output* unison_voices = createPolyModControl(prefix_ + "_unison_voices");
47 Output* unison_detune = createPolyModControl(prefix_ + "_unison_detune");
48 Output* detune_power = createPolyModControl(prefix_ + "_detune_power");
49 Output* detune_range = createPolyModControl(prefix_ + "_detune_range");
50 Output* amplitude = createPolyModControl(prefix_ + "_level", true, true, nullptr, reset);
51 Output* pan = createPolyModControl(prefix_ + "_pan");
52 Output* phase = createPolyModControl(prefix_ + "_phase", true, true, nullptr, reset);
53 Output* distortion_phase = createPolyModControl(prefix_ + "_distortion_phase");
54 Output* rand_phase = createPolyModControl(prefix_ + "_random_phase");
55 Output* blend = createPolyModControl(prefix_ + "_unison_blend");
56 Output* stereo_spread = createPolyModControl(prefix_ + "_stereo_spread");
57 Output* frame_spread = createPolyModControl(prefix_ + "_frame_spread");
58 Output* distortion_spread = createPolyModControl(prefix_ + "_distortion_spread");
59 distortion_type_ = createBaseControl(prefix_ + "_distortion_type");
60 Output* distortion_amount = createPolyModControl(prefix_ + "_distortion_amount");
61 Output* spectral_morph_spread = createPolyModControl(prefix_ + "_spectral_morph_spread");
62 Value* spectral_morph_type = createBaseControl(prefix_ + "_spectral_morph_type");
63 Output* spectral_morph_amount = createPolyModControl(prefix_ + "_spectral_morph_amount");
64
65 // Connect inputs to the oscillator.
70
71 // Connect parameter controls to the oscillator.
98
99 // Connect oscillator outputs.
102
103 // Add the oscillator as a processor to this module and finalize initialization.
106 }
107
116 void OscillatorModule::process(int num_samples) {
117 bool on = on_->value();
118
119 if (on)
120 SynthModule::process(num_samples);
121 else if (*was_on_) {
124 }
125
126 *was_on_ = on;
127 }
128} // namespace vital
SynthOscillator * oscillator_
Definition oscillator_module.h:105
OscillatorModule(std::string prefix="")
Constructs an OscillatorModule with an optional prefix for parameter naming.
Definition oscillator_module.cpp:13
std::shared_ptr< Wavetable > wavetable_
Definition oscillator_module.h:101
std::shared_ptr< bool > was_on_
Definition oscillator_module.h:102
Value * distortion_type_
Definition oscillator_module.h:106
@ kLevelled
Definition oscillator_module.h:36
@ kRaw
Definition oscillator_module.h:35
void process(int num_samples) override
Processes the oscillator for a given number of samples.
Definition oscillator_module.cpp:116
std::string prefix_
Definition oscillator_module.h:100
void init() override
Initializes the module and sets up the internal SynthOscillator with appropriate parameters.
Definition oscillator_module.cpp:26
Value * on_
Definition oscillator_module.h:104
@ kMidi
Definition oscillator_module.h:25
@ kActiveVoices
Definition oscillator_module.h:26
@ kReset
Definition oscillator_module.h:23
@ kRetrigger
Definition oscillator_module.h:24
void useOutput(Output *output)
Uses an existing Output object as this Processor's first output.
Definition processor.cpp:138
force_inline Input * input(unsigned int index=0) const
Retrieves the Input pointer at a given index.
Definition processor.h:587
void useInput(Input *input)
Uses an existing Input object as this Processor's first input.
Definition processor.cpp:126
void plug(const Output *source)
Connects an external Output to this Processor's first input.
Definition processor.cpp:79
virtual void process(int num_samples)=0
Main processing function. Called by the ProcessorRouter.
force_inline Output * output(unsigned int index=0) const
Retrieves the Output pointer at a given index.
Definition processor.h:616
virtual void init()
Called after constructor, used for any additional initialization. Subclasses can override....
Definition processor.h:258
virtual void reset(poly_mask reset_mask)
Called to reset the Processor's per-voice state (e.g., on note-on).
Definition processor.h:267
virtual void addProcessor(Processor *processor)
Adds a Processor to be managed by this router.
Definition processor_router.cpp:121
A ProcessorRouter that encapsulates a cohesive unit of functionality in the synthesizer.
Definition synth_module.h:129
Output * createPolyModControl(std::string name, bool audio_rate=false, bool smooth_value=false, Output *internal_modulation=nullptr, Input *reset=nullptr)
Creates a polyphonic mod control, including applying parameter scaling.
Definition synth_module.cpp:173
Value * createBaseControl(std::string name, bool audio_rate=false, bool smooth_value=false)
Creates a simple control processor for a given parameter name.
Definition synth_module.cpp:22
A core oscillator processor that generates audio by reading wavetable data with various effects.
Definition synth_oscillator.h:74
@ 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
@ kActiveVoices
Active voice mask.
Definition synth_oscillator.h:108
@ kTransposeQuantize
Transpose quantize setting.
Definition synth_oscillator.h:86
@ kLevelled
Output after amplitude leveling/panning.
Definition synth_oscillator.h:119
@ kRaw
Unleveled or "raw" output.
Definition synth_oscillator.h:118
A Processor that maintains and outputs a constant poly_float value.
Definition value.h:24
force_inline mono_float value() const
Returns the current mono_float value of the first lane.
Definition value.h:60
Contains classes and functions used within the Vital synthesizer framework.
constexpr int kNumOscillatorWaveFrames
Number of wave frames in each oscillator’s wavetable.
Definition synth_constants.h:19
Represents a connection to an Output from another Processor.
Definition processor.h:128
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
void clearBuffer()
Zeros out the entire output buffer.
Definition processor.h:81