Vital
Loading...
Searching...
No Matches
formant_module.cpp
Go to the documentation of this file.
1#include "formant_module.h"
2#include "vocal_tract.h"
3
4namespace vital {
5
6 FormantModule::FormantModule(std::string prefix) :
7 SynthModule(kNumInputs, 1),
8 prefix_(std::move(prefix)),
9 formant_filters_(),
10 last_style_(0),
11 mono_(false) { }
12
13 Output* FormantModule::createModControl(std::string name, bool audio_rate, bool smooth_value) {
20 if (mono_)
21 return createMonoModControl(name, audio_rate, smooth_value);
22 return createPolyModControl(name, audio_rate, smooth_value, nullptr, input(kReset));
23 }
24
29 Output* formant_x = createModControl(prefix_ + "_formant_x", true, true);
30 Output* formant_y = createModControl(prefix_ + "_formant_y", true, true);
31 Output* formant_transpose = createModControl(prefix_ + "_formant_transpose", true, true);
32 Output* formant_resonance = createModControl(prefix_ + "_formant_resonance");
33 Output* formant_spread = createModControl(prefix_ + "_formant_spread");
34
35 // Create all FormantFilter styles
36 for (int i = 0; i < FormantFilter::kNumFormantStyles; ++i) {
37 FormantFilter* formant_filter = new FormantFilter(i);
38 formant_filters_[i] = formant_filter;
39 addProcessor(formant_filter);
40 formant_filter->enable(false);
41
42 formant_filter->useInput(input(kAudio), FormantFilter::kAudio);
43 formant_filter->useInput(input(kReset), FormantFilter::kReset);
44 formant_filter->plug(formant_spread, FormantFilter::kSpread);
45 formant_filter->plug(formant_x, FormantFilter::kInterpolateX);
46 formant_filter->plug(formant_y, FormantFilter::kInterpolateY);
47 formant_filter->plug(formant_transpose, FormantFilter::kTranspose);
48 formant_filter->plug(formant_resonance, FormantFilter::kResonance);
49 formant_filter->useOutput(output());
50 }
51
52 // Create VocalTract style and integrate it as one of the formant_filters_
53 VocalTract* vocal_tract = new VocalTract();
57 vocal_tract->plug(formant_x, VocalTract::kTonguePosition);
58 vocal_tract->plug(formant_y, VocalTract::kTongueHeight);
59 vocal_tract->useOutput(output());
61 addProcessor(vocal_tract);
62 vocal_tract->enable(false);
63
64 // Enable the default style
66
68 }
69
70 void FormantModule::process(int num_samples) {
76 int style = static_cast<int>(utils::clamp(input(kStyle)->at(0)[0], 0.0f, max_style));
77 setStyle(style);
78
79 SynthModule::process(num_samples);
80 }
81
88
95
101 if (last_style_ == new_style)
102 return;
103
105 formant_filters_[new_style]->enable(true);
106 last_style_ = new_style;
108 }
109} // namespace vital
A multi-formant filter for vocal/voicing effects in the Vital synthesizer.
Definition formant_filter.h:18
@ kTotalFormantFilters
Total number of formant filter modes.
Definition formant_filter.h:29
@ kNumFormantStyles
Number of primary formant styles.
Definition formant_filter.h:27
@ kVocalTract
Extended style: Vocal tract modeling.
Definition formant_filter.h:28
bool mono_
True if running in mono mode, false for polyphonic.
Definition formant_module.h:103
FormantModule(std::string prefix="")
Constructs a FormantModule, optionally with a parameter prefix for distinguishing multiple instances.
Definition formant_module.cpp:6
int last_style_
Tracks the currently active style.
Definition formant_module.h:102
void reset(poly_mask reset_mask) override
Resets the currently active formant filter for a given set of voices (indicated by the reset_mask).
Definition formant_module.cpp:82
std::string prefix_
Prefix for parameter naming.
Definition formant_module.h:100
@ kReset
Definition formant_module.h:29
@ kStyle
Definition formant_module.h:32
@ kBlend
Definition formant_module.h:31
@ kAudio
Definition formant_module.h:28
void setStyle(int new_style)
Sets the currently active formant filter style, enabling and disabling submodules as necessary.
Definition formant_module.cpp:96
void init() override
Initializes the FormantModule, creating formant filters and connecting parameters.
Definition formant_module.cpp:25
void hardReset() override
Performs a hard reset of the currently active formant filter, clearing its internal state.
Definition formant_module.cpp:89
Processor * formant_filters_[FormantFilter::kTotalFormantFilters]
Array holding all possible formant filter styles.
Definition formant_module.h:101
void process(int num_samples) override
Processes a block of samples. Chooses the appropriate formant filter style and processes audio.
Definition formant_module.cpp:70
Output * createModControl(std::string name, bool audio_rate=false, bool smooth_value=false)
Creates a modulation control (parameter) that can be mono or poly depending on the module settings.
Definition formant_module.cpp:13
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
virtual void hardReset()
Called to perform a "hard" reset for all voices.
Definition processor.h:272
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 enable(bool enable)
Enables or disables this Processor.
Definition processor.h:318
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
Processor * getLocalProcessor(const Processor *global_processor)
Retrieves the local instance of a globally defined Processor.
Definition processor_router.cpp:376
virtual void addProcessor(Processor *processor)
Adds a Processor to be managed by this router.
Definition processor_router.cpp:121
@ kResonance
Resonance parameter.
Definition synth_filter.h:58
@ kTranspose
MIDI transpose in semitones.
Definition synth_filter.h:65
@ kInterpolateY
For formant or XY interpolation.
Definition synth_filter.h:64
@ kReset
Reset signal.
Definition synth_filter.h:56
@ kInterpolateX
For formant or XY interpolation.
Definition synth_filter.h:63
@ kSpread
Additional parameter for e.g. formant spread.
Definition synth_filter.h:66
@ kAudio
Audio input index.
Definition synth_filter.h:55
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
Output * createMonoModControl(std::string name, bool audio_rate=false, bool smooth_value=false, Output *internal_modulation=nullptr)
Creates a monophonic mod control, including applying parameter scaling.
Definition synth_module.cpp:104
A model of a vocal tract for generating vowel-like formants and vocal articulations.
Definition vocal_tract.h:31
@ kTongueHeight
Controls the vertical (height) position of the virtual tongue.
Definition vocal_tract.h:39
@ kAudio
The input audio signal.
Definition vocal_tract.h:35
@ kBlend
Blend control for articulations.
Definition vocal_tract.h:37
@ kTonguePosition
Controls the virtual tongue's forward/backward position.
Definition vocal_tract.h:38
@ kReset
Reset signal to clear internal states.
Definition vocal_tract.h:36
#define force_inline
Definition common.h:23
const poly_mask kFullMask
A mask covering all lanes of a poly_float vector.
Definition synth_constants.h:257
force_inline poly_float clamp(poly_float value, mono_float min, mono_float max)
Clamps each lane of a vector to [min, max].
Definition poly_utils.h:306
Contains classes and functions used within the Vital synthesizer framework.
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
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56