Kaynağa Gözat

Change Ladder filter API to be similar to other filters

dds
PaulStoffregen 3 yıl önce
ebeveyn
işleme
8a8cddaa9d
3 değiştirilmiş dosya ile 17 ekleme ve 16 silme
  1. +6
    -6
      filter_ladder.cpp
  2. +10
    -10
      filter_ladder.h
  3. +1
    -0
      keywords.txt

+ 6
- 6
filter_ladder.cpp Dosyayı Görüntüle

@@ -15,7 +15,7 @@
#include <stdint.h>
#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];
ft = ft * alpha + z1[i];
@@ -24,7 +24,7 @@ float HNMoog::LPF(float s, int i)
return ft;
}

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

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

void HNMoog::compute_coeffs(float c)
void AudioFilterLadder::compute_coeffs(float c)
{
if (c > 0.49 * AUDIO_SAMPLE_RATE_EXACT)
c = 0.49 * AUDIO_SAMPLE_RATE_EXACT;
@@ -53,13 +53,13 @@ void HNMoog::compute_coeffs(float c)
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;
return x * (27.0 + x2) / (27.0 + 9.0 * x2);
}

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

+ 10
- 10
filter_ladder.h Dosyayı Görüntüle

@@ -15,21 +15,21 @@
#include "Arduino.h"
#include "AudioStream.h"

class HNMoog : public AudioStream
class AudioFilterLadder: public AudioStream
{
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);
private:
float LPF(float s, int i);
void compute_coeffs(float fc);
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 overdrive = 1.0;
audio_block_t *inputQueueArray[2];

+ 1
- 0
keywords.txt Dosyayı Görüntüle

@@ -63,6 +63,7 @@ AudioEffectRectifier KEYWORD2
AudioFilterBiquad KEYWORD2
AudioFilterFIR KEYWORD2
AudioFilterStateVariable KEYWORD2
AudioFilterLadder KEYWORD2
AudioInputAnalog KEYWORD2
AudioInputAnalogStereo KEYWORD2
AudioMixer4 KEYWORD2

Yükleniyor…
İptal
Kaydet