Hi - here’s my Biquad HPF implementation for the petal. However I am not getting any output… Can someone identify why?
Edit: Actually it works for some values of fc like 6.5kHz - however the audio does not sound high-passed.
#include "daisy_petal.h"
#include "daisysp.h"
using namespace daisy;
using namespace daisysp;
DaisyPetal hw;
// High-pass filter coefficients
float h_a0, h_a1, h_a2, h_b1, h_b2;
// Filter state variables
float h_z1 = 0.0f, h_z2 = 0.0f;
// Function to initialize high-pass filter coefficients
void init_high_pass(float sampleRate, float fc, float Q, float gain_dB)
{
float K = tan(M_PI * fc / sampleRate);
float norm = 1 / (1 + K / Q + K * K);
float V0 = pow(10, gain_dB / 40.0);
h_a0 = K * K * norm * V0;
h_a1 = -2 * h_a0;
h_a2 = h_a0;
h_b1 = 2 * (K * K - 1) * norm;
h_b2 = (1 - K / Q + K * K) * norm;
}
// High-pass filter function
float high_pass(float inSample)
{
float outSampleF = h_a0 * inSample + h_a1 * h_z1 + h_a2 * h_z2 - h_b1 * h_z1 - h_b2 * h_z2;
h_z2 = h_z1;
h_z1 = inSample;
return outSampleF;
}
void AudioCallback(AudioHandle::InputBuffer in,
AudioHandle::OutputBuffer out,
size_t size)
{
hw.ProcessAllControls();
for(size_t i = 0; i < size; i++)
{
// Apply high-pass filter
out[0][i] = high_pass(in[0][i]);
}
}
int main(void)
{
// Initialize high-pass filter coefficients
init_high_pass(48000, 10729, 0.7071, 6);
hw.Init();
hw.SetAudioBlockSize(4); // number of samples handled per callback
hw.SetAudioSampleRate(SaiHandle::Config::SampleRate::SAI_48KHZ);
hw.StartAdc();
hw.StartAudio(AudioCallback);
while(1) {}
}