I wrote a small project to recreate an issue I am having with my plugin. It is a sequencer that can perform FFT processing. The issue is that I hear an artifact under a certain condition and I am out of ideas on how to get rid of it. I am attaching the source files and the wav sample I use so if anyone has the time and is looking for a small debugging challenge I will be happy to learn what is the reason for my problem (my project is call TestProject and the wav file is in Source directory).
AudioOutEngine object is a polyphonic audio channel. It holds an array of FileToPlay objects (called fileQue) where each FileToPlay object in this array has a pointer to the same audio source but has its own startSample value. fileQue size is equal to the number of active voices and is dynamically changing accordingly when new voices enter and old voices exit. A voice is added when an external sequencer hits a note-on step. It than calls AddAutioToQue function in AudioOutEngine and this will make fileQue grow by 1 and set the newly created object to have a startSample = 0 value.
The actual processing happens in AudioOutEngine::sendToOutput() which is being called by pluginProcessor::processBlock() to fill its buffer. At the end of each call the plugin checks if any voice has reached its endSample value and if so, it is being removed from fileQue.
AudioOutEngine also has one FTT object to perform FFT and iFFT before sending the audio to the main output (note that this is not a JUCE object, but it still works…). This is optional so sound can also flow directly without passing through FFT.
FFT is not performed on each voice separately. If FFT processing is enabled, AudioOutEngine will first calculate the summation of all active voices (FileToPlay objects in fileQue) at the current sample of the buffer before passing the total result to the FFT object. The FFT object receives this data sample-by-sample and each 512 samples performs a transform and an inverse transform.
My problem is when FFT is enabled and there are 2 or more active voices, there might be an artifact right when a voice ends, like this:
I created 3 buttons in the project to show that:
- There is no problem with playing just one sound with FFT processing.
- There is no problem playing several voices without FFT processing. But –
- Playing several voices with FFT enabled produces noticeable clicks. Sometimes loud and sometimes barely noticeable.
I wonder if this is just a perforamce issue. The length of the FFT calculation is determined by a variable called FFT_LEN and if I decrease it from 1024 to 256 it does seem to help a bit, but not completly. The fact that the clicking occurs at the exact time when an object is being removed from the que might suggest something else.
Any input on this would be appreciated.
Project files here:
Source.zip (163.8 KB)