diff --git a/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp b/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp index f7f3e5585a..e5d2741c67 100644 --- a/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp +++ b/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp @@ -1292,8 +1292,11 @@ public: } fifos.setSize (chanIndex, fifoSize); + fifoReadPointers = fifos.getArrayOfReadPointers(); + fifoWritePointers = fifos.getArrayOfWritePointers(); fifos.clear(); startThread (9); + threadInitialised.wait(); return {}; } @@ -1401,6 +1404,9 @@ private: bool active = false; String lastError; AudioBuffer fifos; + const float** fifoReadPointers = nullptr; + float** fifoWritePointers = nullptr; + WaitableEvent threadInitialised; void run() override { @@ -1428,6 +1434,8 @@ private: jassert (numInputChans + numOutputChans == buffer.getNumChannels()); + threadInitialised.signal(); + while (! threadShouldExit()) { readInput (buffer, numSamples, blockSizeMs); @@ -1679,7 +1687,7 @@ private: { auto index = inputIndex + i; auto dest = destBuffer.getWritePointer (index); - auto src = owner.fifos.getReadPointer (index); + auto src = owner.fifoReadPointers[index]; if (size1 > 0) FloatVectorOperations::copy (dest, src + start1, size1); if (size2 > 0) FloatVectorOperations::copy (dest + size1, src + start2, size2); @@ -1704,7 +1712,7 @@ private: for (int i = 0; i < numOutputChans; ++i) { auto index = outputIndex + i; - auto dest = owner.fifos.getWritePointer (index); + auto dest = owner.fifoWritePointers[index]; auto src = srcBuffer.getReadPointer (index); if (size1 > 0) FloatVectorOperations::copy (dest + start1, src, size1); @@ -1718,8 +1726,6 @@ private: float** outputChannelData, int numOutputChannels, int numSamples) override { - auto& buf = owner.fifos; - if (numInputChannels > 0) { int start1, size1, start2, size2; @@ -1733,19 +1739,22 @@ private: for (int i = 0; i < numInputChannels; ++i) { - auto dest = buf.getWritePointer (inputIndex + i); + auto dest = owner.fifoWritePointers[inputIndex + i]; auto src = inputChannelData[i]; if (size1 > 0) FloatVectorOperations::copy (dest + start1, src, size1); if (size2 > 0) FloatVectorOperations::copy (dest + start2, src + size1, size2); } - inputFifo.finishedWrite (size1 + size2); + auto totalSize = size1 + size2; + inputFifo.finishedWrite (totalSize); - if (numSamples > size1 + size2) + if (numSamples > totalSize) { + auto samplesRemaining = numSamples - totalSize; + for (int i = 0; i < numInputChans; ++i) - buf.clear (inputIndex + i, size1 + size2, numSamples - (size1 + size2)); + FloatVectorOperations::clear (owner.fifoWritePointers[inputIndex + i] + totalSize, samplesRemaining); owner.underrun(); } @@ -1765,18 +1774,21 @@ private: for (int i = 0; i < numOutputChannels; ++i) { auto dest = outputChannelData[i]; - auto src = buf.getReadPointer (outputIndex + i); + auto src = owner.fifoReadPointers[outputIndex + i]; if (size1 > 0) FloatVectorOperations::copy (dest, src + start1, size1); if (size2 > 0) FloatVectorOperations::copy (dest + size1, src + start2, size2); } - outputFifo.finishedRead (size1 + size2); + auto totalSize = size1 + size2; + outputFifo.finishedRead (totalSize); - if (numSamples > size1 + size2) + if (numSamples > totalSize) { + auto samplesRemaining = numSamples - totalSize; + for (int i = 0; i < numOutputChannels; ++i) - FloatVectorOperations::clear (outputChannelData[i] + (size1 + size2), numSamples - (size1 + size2)); + FloatVectorOperations::clear (outputChannelData[i] + totalSize, samplesRemaining); owner.underrun(); } diff --git a/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h b/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h index e7e607d90c..b7cb0d2d86 100644 --- a/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h +++ b/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h @@ -295,7 +295,7 @@ public: if (settings != nullptr) { - savedState = settings->getXmlValue ("audioSetup"); + savedState = settings->getXmlValue ("audioSetup"); #if ! (JUCE_IOS || JUCE_ANDROID) shouldMuteInput.setValue (settings->getBoolValue ("shouldMuteInput", true)); diff --git a/modules/juce_core/threads/juce_Thread.cpp b/modules/juce_core/threads/juce_Thread.cpp index 85f6e3d870..1db59dce89 100644 --- a/modules/juce_core/threads/juce_Thread.cpp +++ b/modules/juce_core/threads/juce_Thread.cpp @@ -123,7 +123,7 @@ void Thread::startThread() { const ScopedLock sl (startStopLock); - shouldExit = false; + shouldExit = 0; if (threadHandle.get() == nullptr) { @@ -170,7 +170,7 @@ Thread* JUCE_CALLTYPE Thread::getCurrentThread() //============================================================================== void Thread::signalThreadShouldExit() { - shouldExit = true; + shouldExit = 1; listeners.call ([] (Listener& l) { l.exitSignalSent(); }); } diff --git a/modules/juce_core/threads/juce_Thread.h b/modules/juce_core/threads/juce_Thread.h index 3dd8761b8f..a1bbede37f 100644 --- a/modules/juce_core/threads/juce_Thread.h +++ b/modules/juce_core/threads/juce_Thread.h @@ -153,7 +153,7 @@ public: @see signalThreadShouldExit, currentThreadShouldExit */ - bool threadShouldExit() const { return shouldExit; } + bool threadShouldExit() const { return shouldExit.get() != 0; } /** Checks whether the current thread has been told to stop running. On the message thread, this will always return false, otherwise @@ -333,7 +333,7 @@ private: size_t threadStackSize; uint32 affinityMask = 0; bool deleteOnThreadEnd = false; - bool volatile shouldExit = false; + Atomic shouldExit { 0 }; ListenerList> listeners; #if JUCE_ANDROID