Vital
Loading...
Searching...
No Matches
dc_filter.cpp
Go to the documentation of this file.
1#include "dc_filter.h"
2
3namespace vital {
4
8 DcFilter::DcFilter() : Processor(DcFilter::kNumInputs, 1) {
9 coefficient_ = 0.0f;
11 }
12
18 void DcFilter::setSampleRate(int sample_rate) {
19 Processor::setSampleRate(sample_rate);
20 coefficient_ = 1.0f - kCoefficientToSrConstant / getSampleRate();
21 }
22
28 void DcFilter::process(int num_samples) {
30 processWithInput(input(kAudio)->source->buffer, num_samples);
31 }
32
39 void DcFilter::processWithInput(const poly_float* audio_in, int num_samples) {
40 // Check if we need to reset any voices
41 poly_mask reset_mask = getResetMask(kReset);
42 if (reset_mask.anyMask())
43 reset(reset_mask);
44
45 poly_float* audio_out = output()->buffer;
46 for (int i = 0; i < num_samples; ++i)
47 tick(audio_in[i], audio_out[i]);
48 }
49
56 force_inline void DcFilter::tick(const poly_float& audio_in, poly_float& audio_out) {
57 // y[n] = y[n-1] + (x[n] - x[n-1]) * coefficient
58 audio_out = utils::mulAdd(audio_in - past_in_, past_out_, coefficient_);
59 past_out_ = audio_out;
60 past_in_ = audio_in;
61 }
62
68 void DcFilter::reset(poly_mask reset_mask) {
69 past_in_ = utils::maskLoad(past_in_, 0.0f, reset_mask);
70 past_out_ = utils::maskLoad(past_in_, 0.0f, reset_mask);
71 }
72
73} // namespace vital
A simple DC blocking filter implemented as a one-pole high-pass filter.
Definition dc_filter.h:16
virtual void processWithInput(const poly_float *audio_in, int num_samples) override
Processes a block of samples using the provided input buffer.
Definition dc_filter.cpp:39
@ kReset
Reset trigger input.
Definition dc_filter.h:32
@ kAudio
Audio input buffer.
Definition dc_filter.h:31
void setSampleRate(int sample_rate) override
Sets the sample rate for this filter, recalculating the filter’s coefficient.
Definition dc_filter.cpp:18
virtual void process(int num_samples) override
Processes a block of samples, pulling from the kAudio input.
Definition dc_filter.cpp:28
DcFilter()
Constructs a DcFilter Processor with default parameters.
Definition dc_filter.cpp:8
static constexpr mono_float kCoefficientToSrConstant
A constant used to compute the one-pole filter’s coefficient from the sample rate.
Definition dc_filter.h:24
void tick(const poly_float &audio_in, poly_float &audio_out)
Processes a single sample pair (input to output).
Definition dc_filter.cpp:56
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
force_inline int getSampleRate() const
Retrieves the current (effective) sample rate.
Definition processor.h:326
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
force_inline poly_mask getResetMask(int input_index) const
Retrieves a mask indicating which voices triggered a note-on event. Compares the input's trigger_valu...
Definition processor.h:360
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
#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 mulAdd(poly_float a, poly_float b, poly_float c)
Performs a fused multiply-add on SIMD data: (a * b) + c.
Definition poly_utils.h:61
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
Contains classes and functions used within the Vital synthesizer framework.
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
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56
static force_inline uint32_t vector_call anyMask(simd_type value)
Returns a bitmask that indicates which bytes/elements in the register are non-zero.
Definition poly_values.h:352