46 constexpr mono_float kMinSampleEnvelope = 5.0f;
65 input_mean_squared_(0.0f) {
70 poly_float second_release = base_release_ms_second;
72 base_release_ms_first,
125 envelope_attack_samples =
utils::max(envelope_attack_samples, kMinSampleEnvelope);
126 envelope_release_samples =
utils::max(envelope_release_samples, kMinSampleEnvelope);
135 upper_threshold *= upper_threshold;
139 lower_threshold *= lower_threshold;
148 for (
int i = 0; i < num_samples; ++i) {
156 high_enveloped_mean_squared = (sample_squared + high_enveloped_mean_squared * high_samples) * high_scale;
157 high_enveloped_mean_squared =
utils::max(high_enveloped_mean_squared, upper_threshold);
160 poly_float upper_mag_delta = upper_threshold / high_enveloped_mean_squared;
167 low_enveloped_mean_squared = (sample_squared + low_enveloped_mean_squared * low_samples) * low_scale;
168 low_enveloped_mean_squared =
utils::min(low_enveloped_mean_squared, lower_threshold);
171 poly_float lower_mag_delta = lower_threshold / low_enveloped_mean_squared;
176 audio_out[i] = gain_compression * sample;
204 poly_float delta_mix = (
mix_ - current_mix) * (1.0f / num_samples);
206 for (
int i = 0; i < num_samples; ++i) {
207 current_output_mult += delta_output_mult;
208 current_mix += delta_mix;
211 audio_out[i] =
utils::interpolate(audio_input[i], audio_out[i] * current_output_mult, current_mix);
243 float rms_adjusted = rms_samples - 1.0f;
246 for (
int i = 0; i < num_samples; ++i) {
249 mean_squared = (mean_squared * rms_adjusted + sample_squared) * input_scale;
266 low_band_filter_(120.0f),
267 band_high_filter_(2500.0f),
268 low_band_compressor_(kLowAttackMs, kLowReleaseMs, kBandAttackMs, kBandReleaseMs),
269 band_high_compressor_(kBandAttackMs, kBandReleaseMs, kHighAttackMs, kHighReleaseMs) {
362 for (
int i = 0; i < num_samples; ++i) {
379 for (
int i = 0; i < num_samples; ++i) {
382 dest[i] = low_band_sample + low_high_sample;
398 for (
int i = 0; i < num_samples; ++i) {
400 poly_float low_band_sample = low_band_output[i];
403 dest[i] = low_band_sample + high_sample;
418 for (
int i = 0; i < num_samples; ++i) {
484 if (low_enabled && high_enabled) {
504 else if (low_enabled) {
511 else if (high_enabled) {
A dynamic range compressor Processor that operates on a single band of audio.
Definition compressor.h:16
poly_float base_release_ms_
Base release time in ms for the current voice.
Definition compressor.h:165
poly_float input_mean_squared_
Rolling mean squared value of the input signal.
Definition compressor.h:135
Compressor(mono_float base_attack_ms_first, mono_float base_release_ms_first, mono_float base_attack_ms_second, mono_float base_release_ms_second)
Constructs a Compressor Processor with given base attack and release times.
Definition compressor.cpp:60
@ kAudioOut
Compressed audio output.
Definition compressor.h:40
poly_float high_enveloped_mean_squared_
Internal high enveloped mean squared value for upper threshold detection.
Definition compressor.h:145
void processRms(const poly_float *audio_in, int num_samples)
Processes RMS for the input buffer and applies compression gain.
Definition compressor.cpp:110
void scaleOutput(const poly_float *audio_input, int num_samples)
Applies the final output scaling and dry/wet mix to the processed audio.
Definition compressor.cpp:192
poly_float computeMeanSquared(const poly_float *audio_in, int num_samples, poly_float mean_squared)
Computes the mean squared value over a buffer of samples.
Definition compressor.cpp:239
poly_float output_mean_squared_
Rolling mean squared value of the output signal.
Definition compressor.h:140
poly_float low_enveloped_mean_squared_
Internal low enveloped mean squared value for lower threshold detection.
Definition compressor.h:150
poly_float base_attack_ms_
Base attack time in ms for the current voice.
Definition compressor.h:160
void reset(poly_mask reset_mask) override
Resets internal states and envelopes.
Definition compressor.cpp:222
force_inline poly_float getOutputMeanSquared()
Retrieves the current output RMS value (mean squared).
Definition compressor.h:119
virtual void processWithInput(const poly_float *audio_in, int num_samples) override
Processes audio using the provided input buffer and writes to output.
Definition compressor.cpp:95
poly_float mix_
The current dry/wet mix (0.0 = fully dry, 1.0 = fully wet).
Definition compressor.h:155
@ kMix
Dry/Wet mix.
Definition compressor.h:31
@ kUpperRatio
Upper ratio (compression ratio above upper threshold)
Definition compressor.h:26
@ kAudio
Input audio signal.
Definition compressor.h:23
@ kUpperThreshold
Upper threshold in dB.
Definition compressor.h:24
@ kLowerThreshold
Lower threshold in dB.
Definition compressor.h:25
@ kRelease
Release time control (0.0 to 1.0 maps to exponential range)
Definition compressor.h:30
@ kAttack
Attack time control (0.0 to 1.0 maps to exponential range)
Definition compressor.h:29
@ kOutputGain
Output gain (dB)
Definition compressor.h:28
@ kLowerRatio
Lower ratio (expansion ratio below lower threshold)
Definition compressor.h:27
virtual void process(int num_samples) override
Processes audio using the input audio buffer, modifying output buffer in-place.
Definition compressor.cpp:83
poly_float output_mult_
Current multiplier for output gain (converted from dB).
Definition compressor.h:170
force_inline poly_float getInputMeanSquared()
Retrieves the current input RMS value (mean squared).
Definition compressor.h:112
A Linkwitz-Riley crossover filter splitting audio into low and high bands.
Definition linkwitz_riley_filter.h:17
void setOversampleAmount(int oversample_amount) override
Sets the internal oversample amount and recomputes filter coefficients.
Definition linkwitz_riley_filter.cpp:164
void reset(poly_mask reset_mask) override
Resets the internal states (delay lines) for the specified voices.
Definition linkwitz_riley_filter.cpp:173
void processWithInput(const poly_float *audio_in, int num_samples) override
Processes the provided audio input buffer and writes low and high outputs to the Processor’s buffers.
Definition linkwitz_riley_filter.cpp:38
void setSampleRate(int sample_rate) override
Sets the internal sample rate and recomputes filter coefficients.
Definition linkwitz_riley_filter.cpp:155
@ kAudioLow
Low-frequency output.
Definition linkwitz_riley_filter.h:33
@ kAudioHigh
High-frequency output.
Definition linkwitz_riley_filter.h:34
LinkwitzRileyFilter band_high_filter_
A Linkwitz-Riley filter splitting audio into band and high bands.
Definition compressor.h:368
@ kHighOutputMeanSquared
High band output mean squared.
Definition compressor.h:235
@ kLowOutputMeanSquared
Low band output mean squared.
Definition compressor.h:233
@ kBandOutputMeanSquared
Band output mean squared.
Definition compressor.h:234
@ kLowInputMeanSquared
Low band input mean squared.
Definition compressor.h:230
@ kBandInputMeanSquared
Band input mean squared.
Definition compressor.h:231
@ kAudioOut
Combined compressed output.
Definition compressor.h:229
@ kHighInputMeanSquared
High band input mean squared.
Definition compressor.h:232
cr::Output low_band_upper_threshold_
Definition compressor.h:349
@ kHighUpperThreshold
Upper threshold (dB) for high band.
Definition compressor.h:198
@ kLowLowerThreshold
Lower threshold (dB) for low band.
Definition compressor.h:199
@ kEnabledBands
Enabled bands (see BandOptions)
Definition compressor.h:207
@ kHighUpperRatio
Upper ratio for high band.
Definition compressor.h:192
@ kLowUpperThreshold
Upper threshold (dB) for low band.
Definition compressor.h:196
@ kHighLowerThreshold
Lower threshold (dB) for high band.
Definition compressor.h:201
@ kBandUpperRatio
Upper ratio for band.
Definition compressor.h:191
@ kHighOutputGain
Output gain (dB) for high band.
Definition compressor.h:204
@ kBandLowerThreshold
Lower threshold (dB) for band.
Definition compressor.h:200
@ kAttack
Global attack control.
Definition compressor.h:205
@ kLowLowerRatio
Lower ratio for low band.
Definition compressor.h:193
@ kRelease
Global release control.
Definition compressor.h:206
@ kMix
Dry/wet mix for all bands.
Definition compressor.h:208
@ kBandUpperThreshold
Upper threshold (dB) for band.
Definition compressor.h:197
@ kAudio
Input audio signal.
Definition compressor.h:189
@ kBandOutputGain
Output gain (dB) for band.
Definition compressor.h:203
@ kLowUpperRatio
Upper ratio for low band.
Definition compressor.h:190
@ kHighLowerRatio
Lower ratio for high band.
Definition compressor.h:195
@ kLowOutputGain
Output gain (dB) for low band.
Definition compressor.h:202
@ kBandLowerRatio
Lower ratio for band.
Definition compressor.h:194
MultibandCompressor()
Constructs a MultibandCompressor, creating internal compressors and filters.
Definition compressor.cpp:264
void setOversampleAmount(int oversample) override
Sets the amount of oversampling for the internal filters and compressors.
Definition compressor.cpp:299
void setSampleRate(int sample_rate) override
Sets the current sample rate for the internal filters and compressors.
Definition compressor.cpp:312
bool was_high_enabled_
Whether the high band was enabled on the previous process() call.
Definition compressor.h:337
cr::Output band_high_upper_ratio_
Definition compressor.h:346
Compressor band_high_compressor_
Compressor handling band + high, or high only if configured.
Definition compressor.h:378
void packLowBandCompressor(int num_samples, poly_float *dest)
Combines band filter outputs into a single buffer for the low band compressor.
Definition compressor.cpp:375
cr::Output band_high_upper_threshold_
Definition compressor.h:350
virtual void processWithInput(const poly_float *audio_in, int num_samples) override
Processes audio using the given input buffer and writes to output.
Definition compressor.cpp:433
cr::Output low_band_upper_ratio_
Outputs for the low/band compressor thresholds and ratios.
Definition compressor.h:345
void writeCompressorOutputs(Compressor *compressor, int num_samples, poly_float *dest)
Writes a single compressor’s output to a buffer when only one band is active.
Definition compressor.cpp:415
LinkwitzRileyFilter low_band_filter_
A Linkwitz-Riley filter splitting audio into low band and the rest (band + high).
Definition compressor.h:363
void writeAllCompressorOutputs(int num_samples, poly_float *dest)
Writes the combined output of both compressors to a buffer.
Definition compressor.cpp:394
virtual void process(int num_samples) override
Processes audio using the input audio buffer.
Definition compressor.cpp:345
Compressor low_band_compressor_
Compressor handling the low band.
Definition compressor.h:373
bool was_low_enabled_
Whether the low band was enabled on the previous process() call.
Definition compressor.h:332
cr::Output band_high_lower_ratio_
Definition compressor.h:348
cr::Output low_band_lower_ratio_
Definition compressor.h:347
void packFilterOutput(LinkwitzRileyFilter *filter, int num_samples, poly_float *dest)
Extracts the LinkwitzRileyFilter’s output into a combined buffer for further processing.
Definition compressor.cpp:358
void reset(poly_mask reset_mask) override
Resets internal states and filters.
Definition compressor.cpp:325
cr::Output low_band_lower_threshold_
Definition compressor.h:351
cr::Output low_band_output_gain_
Gain controls for low and band/high compressors.
Definition compressor.h:357
cr::Output band_high_output_gain_
Definition compressor.h:358
cr::Output band_high_lower_threshold_
Definition compressor.h:352
@ kHighBand
Only high band active.
Definition compressor.h:219
@ kLowBand
Only low band active.
Definition compressor.h:218
@ kMultiband
All three bands active.
Definition compressor.h:217
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 Input * input(unsigned int index=0) const
Retrieves the Input pointer at a given index.
Definition processor.h:587
force_inline int getSampleRate() const
Retrieves the current (effective) sample rate.
Definition processor.h:326
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
force_inline Output * output(unsigned int index=0) const
Retrieves the Output pointer at a given index.
Definition processor.h:616
virtual void setSampleRate(int sample_rate)
Updates the sample rate of this Processor (scaled by oversampling).
Definition processor.h:285
#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
const poly_mask kFirstMask
A mask identifying the first voice slots in a polyphonic vector.
Definition synth_constants.h:266
force_inline mono_float exp(mono_float exponent)
Definition futils.h:132
force_inline mono_float pow(mono_float base, mono_float exponent)
Definition futils.h:141
force_inline mono_float dbToMagnitude(mono_float decibels)
Converts decibels (dB) to magnitude (linear).
Definition futils.h:217
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 min(poly_float left, poly_float right)
Returns the minimum of two poly_floats lane-by-lane.
Definition poly_utils.h:334
force_inline bool isContained(poly_float value)
Checks if all lanes in a poly_float are within a broad range [-8000..8000].
Definition poly_utils.h:631
force_inline poly_float max(poly_float left, poly_float right)
Returns the maximum of two poly_floats lane-by-lane.
Definition poly_utils.h:327
force_inline poly_float swapVoices(poly_float value)
Swaps the first half of the lanes with the second half.
Definition poly_utils.h:437
force_inline void copyBuffer(mono_float *dest, const mono_float *source, int size)
Copies data from a source mono buffer to a destination mono buffer.
Definition poly_utils.h:586
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.
constexpr int kMsPerSec
Milliseconds per second.
Definition common.h:50
float mono_float
Definition common.h:33
poly_float * buffer
Pointer to the output buffer.
Definition processor.h:110
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
static force_inline mask_simd_type vector_call greaterThan(simd_type one, simd_type two)
Compares two SIMD float registers, element-wise, for greater than.
Definition poly_values.h:971
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56