|
|
|
|
|
|
|
|
#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; |