I am getting a lot of crackling in my synth when I actually trigger it with my midi keyboard within (my host application) Reaper. I think it is because I have set the (int) startSample argument within synth.renderNextBlock() to zero, which I did because I could not find a way to get the startSample from the buffer, as is possible from within a standalone AudioApp during the getNextAudioBlock() call.
So my question is this: without the AudioSourceChannelInfo providing bufferToFill.startSample, how do I get this same information from the straight AudioBuffer that is provided by PluginProcessor::processBlock()?
Do I need to count the samples that pass from the original NoteOn event and use the last count to set the startSample argument? That was my most recent guess, but I have yet to attempt an implementation. Or should the startSample be derived from some other host-provided data that I’m unaware of?
In AudioProcessors, which plugin projects use, the buffer given to processBlock should be filled from index 0 with the full buffer length (Gotten from AudioBuffer::getNumSamples).
Right, so then I am correct to set the startSample to zero and the length to numSamples? So that means the crackling is caused by some other problem… sigh
@Xenakios The channel config is {0,2} in the plugin setup. Host is {2,2} I would think. The synth itself I believe produces one channel, which the SynthesizerVoice class copies to the other channel, if I remember correctly.
It occurs to me that my rig might be to blame rather than the code. I’m using a laptop with built-in sound at the moment. I’ll try this again with an ASIO device attached and see if I still get crackling. Thanks for your responses, in any case. Much appreciated!
Good point! However, the crackles persist for the synth despite a Release build. On the other hand, I’ve noticed I don’t have the same problem when I load a wave file sample (via SamplerSound) and trigger that via the same Synthesiser object. Something about generating the sine wave seems to be at issue. At any rate, my goal is to build a sampler not a sine synth, so I’m going to set this matter aside for now. Thanks for the tip, though!
That is very good to know about and watch out for, and sounds like something I would do unwittingly, so I greatly appreciate the link! However, in this case, I have simply copied the tutorial sine synth code as-is. The only difference is that it now gets called from AudioProcessor::processBlock(AudioBuffer, etc.) instead of AudioApp::getNextAudioBlock(HostChannelInfo, etc.) so unless there is some auto-magical process taking place in the AudioApp version of the loop that I’m unaware of, it should be the same. Also, it looks to me like a single channel source that is merely duplicated to the other channel to provide stereo, which I would think obviates this particular problem described in the link about separate states for the channel data. But if I’m wrong about that, I would love to learn what exactly is going on in getNextAudioBlock() that is fundamentally different from processBlock() and how I need to handle them differently.
For anyone who was dying to find out… I’ve confirmed that my rig was the problem, as I suspected. Installing an M-Audio device caused the artifacts to magically vanish. Now it works as expected (without crackles) in Reaper using either ASIO or DirectSound driver.