ma0pla I would like to sample every 5th or 6th element but before that apply an anti-aliasing filter. I am aiming in building ANC.
right, you don't need to change the block size for that. Just count samples. E.g.:
#include <libraries/Biquad/Biquad.h>
Biquad lowpass;
unsigned int gCount = 0;
bool setup(BelaContext* context, void()
{
lowpass.setup({
.fs = context->audioSampleRate,
.type = BiquadCoeff::lowpass,
.cutoff = context->audioSampleRate / 12, // adjust to taste
.q = 0.707,
.peakGainDb = 0,
});
return true;
}
void render(BelaContext* context, void*)
{
for(unsigned int n = 0; n < context->audioFrames; ++n)
{
// apply low-pass filter
float value = lowpass.process(audioRead(context, n, 0));
gCount++;
// pick one sample every 6
if(6 == gCount)
{
gCount = 0;
//TODO: use value for your purposes
}
}
}
The above code uses a second order butterworth as an anti-aliasing filter. Perhaps a poor choice, but straightforward. You can otherwise the Decimator class from here https://github.com/BelaPlatform/Bela/pull/677
ma0pla I thought about reducing the sample rate on the I2C codec level, but then I do not know how to apply an anti-aliasing filter. Is it possible?
You could reduce the sampling rate and that would also lower the cutoff frequency of the ADC's built-in anti-aliasing filter, assuming you don't need the full-sampling rate signal anywhere.