Hi, I want to implement the IIRFilter class to the sinewave tutorial but having trouble wrapping my head around it. I.e. I get no sound when the filter is applied. It works fine otherwise.
N.B. I iterate through all samples before iterating through all channels, otherwise I’l get phasing issues.
This is my code so far:
void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override
{
lowPassFilter.reset();
const double localTargetFrequency = targetFrequency;
if ( localTargetFrequency != currentFrequency)
{
const double frequencyIncrement = (localTargetFrequency - currentFrequency) / bufferToFill.numSamples;
for (int sample = 0; sample < bufferToFill.numSamples; ++sample)
{
float currentSample = 0.0f;
currentFrequency += frequencyIncrement;
updateAngleDelta();
//calculate fourier series to generate squarewave from sinewave
for ( float i = 1.0f; i <= iterations; i += 2.0f )
{
currentSample += (float) std::sin ( currentAngle * i ) / i;
}
for (int channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel)
{
float* const buffer = bufferToFill.buffer->getWritePointer (channel, bufferToFill.startSample);
currentAngle += angleDelta;
float lpSample = lowPassFilter.processSingleSampleRaw( currentSample );
buffer[sample] = lpSample * currentLevel;
}
}
}
else
{
for (int sample = 0; sample < bufferToFill.numSamples; ++sample)
{
//calculate fourier series to generate squarewave from sinewave
float currentSample = 0.0f;
for ( float i = 1.0f; i <= iterations; i += 2.0f )
{
currentSample += (float) std::sin ( currentAngle * i ) / i;
}
for (int channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel)
{
float* const buffer = bufferToFill.buffer->getWritePointer (channel, bufferToFill.startSample);
currentAngle += angleDelta;
float lpSample = lowPassFilter.processSingleSampleRaw( currentSample );
buffer[sample] = lpSample * currentLevel;
}
}
}
}
Any help would be greatly appreciated!