Audio latency in my plugin and the output buffer

Hey everyone,
So, I’ve been using JUCE for a couple of months to make an audio plug-in for my university project. It is something like an harmonizer and I have a small latency problem. Let me explain the details:

I use an open source library which is called SoundTouch for pitch shifting. The way it works is: you create a SoundTouch object (I think I should explain how it works before I ask my question), you input the sampleRate, the pitch shift factor etc. and input the audio data. It gives the output from an output buffer when it’s done with processing.

From the beggining, i had some problems with latency but I always thought it was because of Windows and when i would run it with ASIO on FL Studio, it would be better. Today, I finally could try that but unfortunately there is still some latency. (I believe I have correctly set up the ASIO drivers etc.) Today, after some debugging, I think I have an idea about why this may be.

In my processBlock, I do something like the following:

But what I noticed today is, the number of ready output samples from the SoundTouch object is always bigger than my output buffer size and sometimes even 2 or 3 times so. Of course, then i tried to put all the ready samples to the output buffer but I had an assertion error and I guess that’s not how audio buffers work :smiley:

So yeah, sorry about the lengthy post. Do you have any idea about what i can do about this? Can I for example make my output buffer size larger while keeping my input buffer size the same (so that i wont have extra delay waiting for the input buffer to be full)?

SoundTouch inherently has latency (up to thousands of samples), you can’t really do much about that when processing live (real time) inputs.

I understand that, but do you think what I’m describing may have an impact as well? Because even though i have enough ready samples in the SoundTouch output, i simply can’t output them through the buffer because of its limited size

If it’s always bigger than the buffer size by N, then in the first processBlock you can discard N of the initial samples coming out of SoundTouch to reduce latency.

But you can’t change the output buffer size.

Hmm, this actually makes sense. Although I fear this may cause discontinouties in the sound, I will still try it out though! Thanks