Vital
Loading...
Searching...
No Matches
phaser_filter.cpp
Go to the documentation of this file.
1#include "phaser_filter.h"
2
3#include "futils.h"
4
5namespace vital {
6
11 PhaserFilter::PhaserFilter(bool clean) : Processor(PhaserFilter::kNumInputs, 1) {
12 clean_ = clean;
13 hardReset();
14 // Default to no inversion of the phaser output
15 invert_mult_ = 1.0f;
16 }
17
22 void PhaserFilter::reset(poly_mask reset_mask) {
23 allpass_output_ = utils::maskLoad(allpass_output_, 0.0f, reset_mask);
24 for (int i = 0; i < kMaxStages; ++i)
25 stages_[i].reset(reset_mask);
26
27 remove_lows_stage_.reset(reset_mask);
28 remove_highs_stage_.reset(reset_mask);
29 }
30
36 resonance_ = 0.0f;
37 drive_ = 0.0f;
38 peak1_amount_ = 0.0f;
39 peak3_amount_ = 0.0f;
40 peak5_amount_ = 0.0f;
41 allpass_output_ = 0.0f;
42 }
43
48 void PhaserFilter::process(int num_samples) {
50 processWithInput(input(kAudio)->source->buffer, num_samples);
51 }
52
58 void PhaserFilter::processWithInput(const poly_float* audio_in, int num_samples) {
59 // If clean_ is true, saturate resonance path with tanh; input passes through without saturation (utils::pass).
60 // Otherwise, let resonance pass unaltered (utils::pass), saturating the input with hardTanh.
61 if (clean_)
62 process<futils::tanh, utils::pass>(audio_in, num_samples);
63 else
64 process<utils::pass, futils::hardTanh>(audio_in, num_samples);
65 }
66
71 void PhaserFilter::setupFilter(const FilterState& filter_state) {
72 // Clamp resonance_percent between 0.0 and 1.0
73 poly_float resonance_percent = utils::clamp(filter_state.resonance_percent, 0.0f, 1.0f);
74 resonance_ = utils::interpolate(kMinResonance, kMaxResonance, resonance_percent);
75
76 // Drive is scaled by the resonance factor for some additional feedback
77 drive_ = (resonance_ * 0.5f + 1.0f) * filter_state.drive;
78
79 // pass_blend dictates how to distribute peaks among 1, 3, and 5
80 poly_float blend = filter_state.pass_blend;
81 peak1_amount_ = utils::clamp(-blend + 1.0f, 0.0f, 1.0f);
82 peak5_amount_ = utils::clamp(blend - 1.0f, 0.0f, 1.0f);
83 // peak3_amount_ is whatever remains to ensure the sum is 1
84 peak3_amount_ = -peak1_amount_ - peak5_amount_ + 1.0f;
85
86 // If style is non-zero, invert the phaser output; otherwise, do not invert.
87 if (filter_state.style)
88 invert_mult_ = -1.0f;
89 else
90 invert_mult_ = 1.0f;
91 }
92
93} // namespace vital
force_inline void reset(poly_mask reset_mask)
Resets the filter state for the voices indicated by a mask.
Definition one_pole_filter.h:36
A multi-stage phaser filter for the Vital synthesizer.
Definition phaser_filter.h:19
PhaserFilter(bool clean)
Constructs a PhaserFilter object.
Definition phaser_filter.cpp:11
static constexpr int kMaxStages
Maximum number of stages (3 clusters of 4 stages = 12 total).
Definition phaser_filter.h:49
static constexpr mono_float kMaxResonance
Maximum resonance value.
Definition phaser_filter.h:29
static constexpr mono_float kMinResonance
Minimum resonance value.
Definition phaser_filter.h:24
void reset(poly_mask reset_mask) override
Resets internal filter states for the specified voices.
Definition phaser_filter.cpp:22
void hardReset() override
Performs a full reset of the filter states (for all voices).
Definition phaser_filter.cpp:34
virtual void process(int num_samples) override
Processes the audio buffer through the phaser effect.
Definition phaser_filter.cpp:48
void processWithInput(const poly_float *audio_in, int num_samples) override
Processes a given input buffer through the phaser effect.
Definition phaser_filter.cpp:58
void setupFilter(const FilterState &filter_state) override
Sets up the filter parameters (resonance, drive, peaks) based on the FilterState.
Definition phaser_filter.cpp:71
Base class for all signal-processing units in Vital.
Definition processor.h:212
force_inline Input * input(unsigned int index=0) const
Retrieves the Input pointer at a given index.
Definition processor.h:587
bool inputMatchesBufferSize(int input=0)
Checks whether the buffer size of a particular input matches the size needed by this Processor.
Definition processor.cpp:42
Holds the parameters necessary to configure a SynthFilter at runtime.
Definition synth_filter.h:92
poly_float pass_blend
Blend parameter in [0..2], controlling pass type.
Definition synth_filter.h:117
poly_float drive
Drive in linear magnitude.
Definition synth_filter.h:113
int style
Filter style enum (e.g., k12Db, k24Db)
Definition synth_filter.h:116
poly_float resonance_percent
Resonance parameter in [0..1].
Definition synth_filter.h:112
@ kAudio
Audio input index.
Definition synth_filter.h:55
#define VITAL_ASSERT(x)
Definition common.h:11
Contains faster but less accurate versions of utility math functions, such as exponential,...
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
force_inline poly_float maskLoad(poly_float zero_value, poly_float one_value, poly_mask reset_mask)
Selects between two values (zero_value or one_value) based on a mask in each lane.
Definition poly_utils.h:351
force_inline poly_float interpolate(poly_float from, poly_float to, mono_float t)
Performs a linear interpolation between two poly_floats using a scalar t in [0..1].
Definition poly_utils.h:182
Contains classes and functions used within the Vital synthesizer framework.
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