Procházet zdrojové kódy

Change Ladder filter API to be similar to other filters

dds
PaulStoffregen před 3 roky
rodič
revize
8a8cddaa9d
3 změnil soubory, kde provedl 17 přidání a 16 odebrání
  1. +6
    -6
      filter_ladder.cpp
  2. +10
    -10
      filter_ladder.h
  3. +1
    -0
      keywords.txt

+ 6
- 6
filter_ladder.cpp Zobrazit soubor

#include <stdint.h> #include <stdint.h>
#define MOOG_PI 3.14159265358979323846264338327950288 #define MOOG_PI 3.14159265358979323846264338327950288


float HNMoog::LPF(float s, int i)
float AudioFilterLadder::LPF(float s, int i)
{ {
float ft = s * (1/1.3) + (0.3/1.3) * z0[i] - z1[i]; float ft = s * (1/1.3) + (0.3/1.3) * z0[i] - z1[i];
ft = ft * alpha + z1[i]; ft = ft * alpha + z1[i];
return ft; return ft;
} }


void HNMoog::SetResonance(float res)
void AudioFilterLadder::resonance(float res)
{ {
// maps resonance = 0->1 to K = 0 -> 4 // maps resonance = 0->1 to K = 0 -> 4
if (res > 1) { if (res > 1) {
K = 4.0 * res; K = 4.0 * res;
} }


void HNMoog::SetCutoff(float c)
void AudioFilterLadder::frequency(float c)
{ {
Fbase = c; Fbase = c;
compute_coeffs(c); compute_coeffs(c);
} }


void HNMoog::compute_coeffs(float c)
void AudioFilterLadder::compute_coeffs(float c)
{ {
if (c > 0.49 * AUDIO_SAMPLE_RATE_EXACT) if (c > 0.49 * AUDIO_SAMPLE_RATE_EXACT)
c = 0.49 * AUDIO_SAMPLE_RATE_EXACT; c = 0.49 * AUDIO_SAMPLE_RATE_EXACT;
alpha = 0.9892f * wc - 0.4324f * wc2 + 0.1381f * wc * wc2 - 0.0202f * wc2 * wc2; alpha = 0.9892f * wc - 0.4324f * wc2 + 0.1381f * wc * wc2 - 0.0202f * wc2 * wc2;
} }


inline float fast_tanh(float x)
static inline float fast_tanh(float x)
{ {
float x2 = x * x; float x2 = x * x;
return x * (27.0 + x2) / (27.0 + 9.0 * x2); return x * (27.0 + x2) / (27.0 + 9.0 * x2);
} }


void HNMoog::update(void)
void AudioFilterLadder::update(void)
{ {
audio_block_t *blocka, *blockb; audio_block_t *blocka, *blockb;
float ftot, FCmod; float ftot, FCmod;

+ 10
- 10
filter_ladder.h Zobrazit soubor

#include "Arduino.h" #include "Arduino.h"
#include "AudioStream.h" #include "AudioStream.h"


class HNMoog : public AudioStream
class AudioFilterLadder: public AudioStream
{ {
public: public:
HNMoog() : AudioStream(2,inputQueueArray) {};
void SetCutoff(float FC);
void SetResonance(float reson);
float LPF(float s, int i);
void compute_coeffs(float fc);
AudioFilterLadder() : AudioStream(2, inputQueueArray) {};
void frequency(float FC);
void resonance(float reson);
virtual void update(void); virtual void update(void);
private: private:
float LPF(float s, int i);
void compute_coeffs(float fc);
float alpha = 1.0; float alpha = 1.0;
float beta[4] = {0};
float z0[4] = {0};
float z1[4] = {0};
float K;
float beta[4] = {0.0, 0.0, 0.0, 0.0};
float z0[4] = {0.0, 0.0, 0.0, 0.0};
float z1[4] = {0.0, 0.0, 0.0, 0.0};
float K = 1.0;
float Fbase = 1000; float Fbase = 1000;
float overdrive = 1.0; float overdrive = 1.0;
audio_block_t *inputQueueArray[2]; audio_block_t *inputQueueArray[2];

+ 1
- 0
keywords.txt Zobrazit soubor

AudioFilterBiquad KEYWORD2 AudioFilterBiquad KEYWORD2
AudioFilterFIR KEYWORD2 AudioFilterFIR KEYWORD2
AudioFilterStateVariable KEYWORD2 AudioFilterStateVariable KEYWORD2
AudioFilterLadder KEYWORD2
AudioInputAnalog KEYWORD2 AudioInputAnalog KEYWORD2
AudioInputAnalogStereo KEYWORD2 AudioInputAnalogStereo KEYWORD2
AudioMixer4 KEYWORD2 AudioMixer4 KEYWORD2

Načítá se…
Zrušit
Uložit