This relates to the FFT that I made a post about before.
When I apply my FFT to the buffer in the processBlock method, nothing happens in my DAW! I set the new values of the buffer using write pointers.
I poke at the original buffer with my debugger and see that the values are changed in it after my operations, and are different from the readPointers that I initially request from it.
Could this be because I resize the buffer inside of processBlock? Is this allowed? Any thoughts?
Here is a snippit.
The calculations not shown cause the values in bufferInput and bufferInput to be different than the values of buffer.getSample(0, 0) and buffer.getSample(0, 1). But what is returned from the DAW is the unchanged sound.
// Inside of process block
// Resize buffer to fftSize. Saves the data that is already in the buffer.
buffer.setSize(buffer.getNumChannels(), fftSize, true, true);
for (int channel = 0; channel < buffer.getNumChannels(); ++channel)
float* bufferWriters = buffer.getWritePointer(channel);
const float* bufferInput = buffer.getReadPointer(channel);
// Calculations I cant show because this is my senior project ;)
for (int sample = 0; sample < fftSize; ++sample)
bufferWriters[sample] = bufferCopy[sample];
Any glaring issues in this, or must I dig deeper in what I am doing in what isn’t shown?
Yeah, if that’s the buffer that the host passed into processBlock for you to fill, then obviously changing its size will allocate new memory, so you’ll no longer be writing to the memory the host actually asked you for! (And changing its size also makes no sense at all in this context)
Ahh, I see. This yielded results, thanks again!
I was resizing originally because I was under the impression that the resulting data from the convolution would be longer than the buffer coming in if my impulse response length was longer than the buffer. How do I add this new data then?
Well, you’d need your own FIFO to collect and process the data.
Ahh that’d made sense.
How would I clear the FIFO when processBlock is no longer called and the FIFO still has data? I am looking at the AudioProcessor documentation and nothing is standing out to me.
Clear your FIFO in the prepareToPlay and/or releaseResources calls. (But be also prepared for the situation the host application might not make those calls as often as expected.)
If you use juce’s AbstractFifo, you don’t need to clear, because the prepareToRead takes into account, if the data was already read. It will not read unless valid data was written to it.
You can check getNumReady() to see, how much data is there to read.
Okay, that makes sense. When I was referring to ‘clear’ I was meaning adding the data in the FIFO to the end of the processed data. So the data isn’t lost, just tacked on to the end.
When the host stops calling processBlock() then that’s because it no longer needs any more data, so you can safely not worry about the dregs left in your buffer.
Great that’s what I was wondering!