Hi everyone,
So I’m currently creating a plugin to generate white noise and filter it to produce a recursive resonator. I’ve managed to generate noise but having trouble with the filtering operation as when I call my filtering method it seems to not affect it and when I run the plugin in the debugger only the white noise is audible.
It seems to compile fine but isn’t doing anything. Here is the different sections of my code required to use the filter: (I decided to build these all within the PluginProcessor.cpp)
void KrotosResonatorAudioProcessor::Iirnotch(double f, double r) {
buffer1 = 0;
buffer2 = 0;
output_acc = 0.0;
b0 = 1;
b1 = -2*cos(2*M_PI*f);
b2 = 1;
a0 = 1;
a1 = -2*r*cos(2*M_PI*f);
a2 = r*r;
}
double KrotosResonatorAudioProcessor::myFilter(double data) {
double input_acc;
double output_acc;
input_acc = data;
input_acc = input_acc - (a1*buffer1);
input_acc = input_acc - (a2*buffer2);
//accumulator for the FIR part
output_acc = input_acc*b0;
output_acc = output_acc + (b1*buffer1);
output_acc = output_acc + (b2*buffer2);
buffer2 = buffer1;
buffer1 = input_acc;
return output_acc;
}
I set the IIR coefficients within the contructor, so that they are set as soon as the plugin is run:
KrotosResonatorAudioProcessor::KrotosResonatorAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor (BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput ("Input", AudioChannelSet::stereo(), true)
#endif
.withOutput ("Output", AudioChannelSet::stereo(), true)
#endif
)
#endif
{
random = new Random();
Iirnotch(f, r);
}
This is where I call the filtering operation ( within processBlock):
void KrotosResonatorAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
//std::cout << "Herroooo";
buffer.clear();
//MidiBuffer processedMidi;
//int time;
//MidiMessage m;
for(int chan=0; chan<buffer.getNumChannels(); chan++)
{
float * const float_buffer = buffer.getWritePointer(chan, 0);
for(int i = 0;i<buffer.getNumSamples();i++)
{
float_buffer[i] = random->nextFloat();
float_buffer[i] = myFilter(float_buffer[i]);
}
}
}
If anyone can spot where I’m going wrong here and point me in the right direction, that would be a massive help! oh and a bunch of things have been set in the header file for example:
double myFilter(double data);
void Iirnotch(double f, double r);
double buffer1 = 0;
double buffer2 = 0;
float output_acc = 0.0;
double f = 2000/44100;
float r = 0.999;
double b0;
float b1;
double b2;
double a0;
float a1;
float a2;