- Edited
Hello,
This source can be found here: examples/Audio/filterbanks/render.cpp
/*
____ _____ _ _
| __ )| ____| | / \
| _ \| _| | | / _ \
| |_) | |___| |___ / ___ \
|____/|_____|_____/_/ \_\
http://bela.io
*/
#include <Bela.h>
#include <vector>
#include <libraries/Biquad/QuadBiquad.h>
std::vector<QuadBiquad> bs(150);
bool setup(BelaContext *context, void *userData)
{
BiquadCoeff::Settings s = {
.fs = context->audioSampleRate,
.q = 0.8,
.peakGainDb = 0,
};
// Setting cutoff and type for all the filters
for(unsigned int b = 0; b < bs.size(); ++b)
{
if(b < bs.size() / 2) {
// the first half of the filters are lowpass
s.type = BiquadCoeff::lowpass;
s.cutoff= 2000;
} else {
// the other half are highpass
s.type = BiquadCoeff::highpass;
s.cutoff = 500;
}
for(unsigned int q = 0; q < 4; ++q)
{
// Each QuadBiquad object contains four filters (in parallel), which
// are completely independent of each other and you could set each
// to a different type of filter, cutoff, Q, etc
// Here we give to each of these four an increasing cutoff.
// This will result, for instance, in the right channel being
// brighter than the left channel.
bs[b].filters[q].setup(s);
s.cutoff *= 1.3;
}
// after updating the filter coefficients of the individual
// filters, tell the QuadBiquad object to refresh its internal
// registers
bs[b].update();
}
return true;
}
void render(BelaContext *context, void *userData)
{
unsigned int len = bs.size() & (~3);
for(unsigned int n = 0; n < context->audioFrames; ++n)
{
const unsigned int datasz = 4;
float data[datasz];
// the data array is used for input and output of the four parallel filters in each QuadBiquad
// we fill it with however audio inputs we have
for(unsigned int c = 0; c < context->audioInChannels && c < datasz; ++c)
data[c] = audioRead(context, n, c);
// we then process it through all the filters in series
for(unsigned int b = 0; b < len; ++b) {
bs[b].process(data);
// after each call to process(), data contains the output of the filter.
// by processing it over and over, we effectively place the filters in series.
}
// last, we output the results to however many audio channels we have
for(unsigned int c = 0; c < context->audioOutChannels && c < datasz; ++c)
audioWrite(context, n, c, data[c]);
}
}
void cleanup(BelaContext *context, void *userData)
{
}
I am using this source to promote a sound fluctuation on the violin to a speaker w/ BELA/BBB as the median.
Anyway, am I way off here or is this what this source is attempting to perform?
Seth
P.S. I will try some other ideas while I prepare for the answer. If you have time, jump on in. I can use any ideas you have available. So far, I am just getting a bypass of sound w/out distortion.