juce-framework / JUCE

JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, LV2 and AAX audio plug-ins.
https://juce.com
Other
6.54k stars 1.73k forks source link

[Bug]: Core Audio Glitching #1347

Open lucenta opened 7 months ago

lucenta commented 7 months ago

Detailed steps on how to reproduce the bug

I have a plugin that uses a high amount of CPU depending on the parameters set in the plugin.

I noticed that in a DAW setting the plugin will have pops/clicks if the CPU is high enough. In the standalone app, I get weird glitches and buzzing (sounds like a buffer is repeating itself over and over). I traced the problem to juce_mac_CoreAudio.cpp producing the repetitive glitching.

In juce_mac_CoreAudio.cpp we have

           callback->audioDeviceIOCallbackWithContext (getTempBuffers (inStream),  numInputChans,
                                                        getTempBuffers (outStream), numOutputChans,
                                                        bufferSize,
                                                        { timeStamp != nullptr ? &nanos : nullptr });

If i change the last argument to { nullptr }, i get no repetitive glitching, just pops and clicks at very high CPU, similar to how my DAW behaves. I see that this line calls the function

        void audioDeviceIOCallbackWithContext (const float* const* inputChannelData,
                                               int numInputChannels,
                                               float* const* outputChannelData,
                                               int numOutputChannels,
                                               int numSamples,
                                               const AudioIODeviceCallbackContext& context) override

I see in that function we use the context to update the sample position in updateSampleTimeFromContext (context); I suspect that this is causing the problem.

What is the expected behaviour?

If CPU is high and we miss filling buffers, audio should just pop/click, not get stuck in a loop

Operating systems

macOS

What versions of the operating systems?

Any Mac version, including Intel based Macs.

Architectures

ARM

Stacktrace

No response

Plug-in formats (if applicable)

No response

Plug-in host applications (DAWs) (if applicable)

No response

Testing on the develop branch

The bug is present on the develop branch

Code of Conduct