[feat]: Filter LFO (#23)
Reviewed-on: #23 Co-authored-by: HiveBeats <e1lama@protonmail.com> Co-committed-by: HiveBeats <e1lama@protonmail.com>
This commit is contained in:
@@ -1,36 +1,50 @@
|
||||
#include "Filter.h"
|
||||
#include "Settings.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
Filter::Filter(/* args */) {}
|
||||
|
||||
Filter::~Filter() {}
|
||||
|
||||
void Filter::CalculateNormals() {
|
||||
m_v = powf(10, fabs(m_order) / 20.0);
|
||||
m_k = tanf(M_PI * m_freq);
|
||||
}
|
||||
|
||||
void Filter::Trigger() {}
|
||||
|
||||
void Filter::Release() {}
|
||||
|
||||
float Filter::Process(float in) {
|
||||
// may move to a compile-time dictionary calculation, if needed
|
||||
CalculateCoefficients();
|
||||
float out = in * m_a0 + m_z1;
|
||||
m_z1 = in * m_a1 + m_z2 - m_b1 * out;
|
||||
m_z2 = in * m_a2 - m_b2 * out;
|
||||
return out;
|
||||
}
|
||||
|
||||
void Filter::Process(std::vector<float>& samples) {
|
||||
for (std::size_t i = 0; i < samples.size(); i++) {
|
||||
samples[i] = Process(samples[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void Filter::SetParameters(float freq, float res, float q) {
|
||||
m_freq = freq / SAMPLE_RATE;
|
||||
m_q = res;
|
||||
m_order = q;
|
||||
|
||||
float Filter::Process(float in) {
|
||||
m_notcho = in - m_damp * m_bando;
|
||||
m_lowo = m_lowo + m_freq * m_bando;
|
||||
m_higho = m_notcho - m_lowo;
|
||||
m_bando =
|
||||
m_freq * m_higho + m_bando - m_drive * m_bando * m_bando * m_bando;
|
||||
// (m_notcho or m_lowo or m_higho or m_bando or m_peako)
|
||||
float out = 0.5 * GetSampleForFilterType();
|
||||
m_notcho = in - m_damp * m_bando;
|
||||
m_lowo = m_lowo + m_freq * m_bando;
|
||||
m_higho = m_notcho - m_lowo;
|
||||
m_bando =
|
||||
m_freq * m_higho + m_bando - m_drive * m_bando * m_bando * m_bando;
|
||||
out += 0.5 * GetSampleForFilterType();
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void Filter::SetParameters(float freq, float res, float drive) {
|
||||
m_fc = freq;
|
||||
m_res = res;
|
||||
m_drive = drive;
|
||||
|
||||
// the fs*2 is because it's double sampled
|
||||
m_freq =
|
||||
2.0 * std::sinf(SYNTH_PI * std::min(0.25f, m_fc / (m_fs * 2)));
|
||||
|
||||
m_damp = std::min(2.0f * (1.0f - std::powf(m_res, 0.25f)),
|
||||
std::min(2.0f, 2.0f / m_freq - m_freq * 0.5f));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user