feat: all filter types

This commit is contained in:
2024-01-17 08:56:59 +07:00
parent 29ceabca74
commit 2cfc49bac3
15 changed files with 110 additions and 234 deletions

View File

@@ -1,14 +1,17 @@
#pragma once
#include "Filter.h"
class BandPassFilter : public Filter {
private:
void CalculateCoefficients() override;
protected:
float GetSampleForFilterType() override;
public:
BandPassFilter();
BandPassFilter(Filter* filter);
BandPassFilter(float freq, float res, float q);
BandPassFilter(/* args */);
~BandPassFilter();
bool IsSameFilterType(FilterType type) override { return type == BandPass; };
};

View File

@@ -1,24 +1,25 @@
#pragma once
#include "IEffect.h"
#include "Settings.h"
enum FilterType {
LowPass,
BandPass,
HighPass
};
enum FilterType { LowPass, BandPass, HighPass };
class Filter : public IEffect {
protected:
float m_freq; // cutoff frequency
float m_q; // filter quantity (resonance)
float m_order; // filter order (peakGain)
/* todo: filter adsr */
float m_norm, m_v, m_k;
float m_a0, m_a1, m_a2, m_b1, m_b2;
float m_z1, m_z2;
void CalculateNormals();
virtual void CalculateCoefficients(){};
// float* m_output; // output buffer
float m_fs = SAMPLE_RATE; // sampling frequency;
float m_fc; // cutoff frequency normally something like: 440.0*pow(2.0,
// (midi_note - 69.0)/12.0);
float m_res; // resonance 0 to 1;
float m_drive; // internal distortion 0 to 0.1
float m_freq;
float m_damp;
float m_notcho; // notch output
float m_lowo; // low pass output
float m_higho; // high pass output
float m_bando; // band pass output
float m_peako; // peaking output = low - high
virtual float GetSampleForFilterType(){ return 0.0; };
public:
Filter(/* args */);
@@ -27,9 +28,9 @@ class Filter : public IEffect {
void Release() override final;
float Process(float in);
void Process(std::vector<float>& samples) override final;
void SetParameters(float freq, float res, float q);
float GetFreq() { return m_freq; }
float GetRes() { return m_q; }
float GetPeakGain() { return m_norm; }
virtual bool IsSameFilterType(FilterType type){ return false; };
void SetParameters(float freq, float res, float drive);
float GetFreq() { return m_fc; }
float GetRes() { return m_res; }
float GetPeakGain() { return m_drive; }
virtual bool IsSameFilterType(FilterType type) { return false; };
};

View File

@@ -2,8 +2,8 @@
#include "Filter.h"
class HighPassFilter : public Filter {
private:
void CalculateCoefficients() override;
protected:
float GetSampleForFilterType() override;
public:
HighPassFilter();

View File

@@ -4,7 +4,7 @@
class LowPassFilter : public Filter {
protected:
void CalculateCoefficients() override;
float GetSampleForFilterType() override;
public:
LowPassFilter();
@@ -13,3 +13,4 @@ class LowPassFilter : public Filter {
~LowPassFilter();
bool IsSameFilterType(FilterType type) override { return type == LowPass; };
};

View File

@@ -1,15 +0,0 @@
#pragma once
#include "StateVariableFilter.h"
class LowPassStateVariableFilter : StateVariableFilter {
protected:
float GetSampleForFilterType() override;
public:
LowPassStateVariableFilter();
LowPassStateVariableFilter(StateVariableFilter* filter);
LowPassStateVariableFilter(float freq, float res, float q);
~LowPassStateVariableFilter();
bool IsSameFilterType(FilterType type) override { return type == LowPass; };
};

View File

@@ -1,35 +0,0 @@
#pragma once
#include "Filter.h"
#include "IEffect.h"
#include "Settings.h"
class StateVariableFilter : public IEffect {
protected:
// float* m_output; // output buffer
float m_fs = SAMPLE_RATE; // sampling frequency;
float m_fc; // cutoff frequency normally something like: 440.0*pow(2.0,
// (midi_note - 69.0)/12.0);
float m_res; // resonance 0 to 1;
float m_drive; // internal distortion 0 to 0.1
float m_freq;
float m_damp;
float m_notcho; // notch output
float m_lowo; // low pass output
float m_higho; // high pass output
float m_bando; // band pass output
float m_peako; // peaking output = low - high
virtual float GetSampleForFilterType(){ return 0.0; };
public:
StateVariableFilter(/* args */);
virtual ~StateVariableFilter();
void Trigger() override final;
void Release() override final;
float Process(float in);
void Process(std::vector<float>& samples) override final;
void SetParameters(float freq, float res, float drive);
float GetFreq() { return m_fc; }
float GetRes() { return m_res; }
float GetPeakGain() { return m_drive; }
virtual bool IsSameFilterType(FilterType type) { return false; };
};

View File

@@ -1,7 +1,7 @@
#pragma once
#include "ADSR.h"
#include "StateVariableFilter.h"
#include "Filter.h"
#include "Adder.h"
#include "IEffect.h"
#include "Note.h"
@@ -35,6 +35,6 @@ class Synth {
const std::vector<Oscillator*>& GetOscillators() { return m_oscillators; }
const bool& GetIsNoteTriggered() { return is_note_triggered; }
ADSR* GetADSR() { return (ADSR*)m_effects[0]; }
StateVariableFilter* GetFilter() { return (StateVariableFilter*)m_effects[1]; }
Filter* GetFilter() { return (Filter*)m_effects[1]; }
void SetFilter(FilterType type);
};