JUCE icon indicating copy to clipboard operation
JUCE copied to clipboard

[Bug]: Core Audio Glitching

Open lucenta opened this issue 1 year ago • 0 comments
trafficstars

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

  • [X] I agree to follow the Code of Conduct

lucenta avatar Feb 09 '24 00:02 lucenta