mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Audio: Add AudioWorkgroup support
This allows real-time threads to join an audio workgroup on Apple platforms.
This commit is contained in:
parent
2843983a21
commit
7d9cdd3016
60 changed files with 4949 additions and 116 deletions
|
|
@ -172,6 +172,7 @@ void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
|
|||
return;
|
||||
|
||||
sampleCount = 0;
|
||||
currentWorkgroup.reset();
|
||||
|
||||
if (processorToPlay != nullptr && sampleRate > 0 && blockSize > 0)
|
||||
{
|
||||
|
|
@ -190,6 +191,7 @@ void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
|
|||
|
||||
processorToPlay->setProcessingPrecision (supportsDouble ? AudioProcessor::doublePrecision
|
||||
: AudioProcessor::singlePrecision);
|
||||
|
||||
processorToPlay->prepareToPlay (sampleRate, blockSize);
|
||||
}
|
||||
|
||||
|
|
@ -210,6 +212,8 @@ void AudioProcessorPlayer::setDoublePrecisionProcessing (bool doublePrecision)
|
|||
{
|
||||
const ScopedLock sl (lock);
|
||||
|
||||
currentWorkgroup.reset();
|
||||
|
||||
if (processor != nullptr)
|
||||
{
|
||||
processor->releaseResources();
|
||||
|
|
@ -218,6 +222,7 @@ void AudioProcessorPlayer::setDoublePrecisionProcessing (bool doublePrecision)
|
|||
|
||||
processor->setProcessingPrecision (supportsDouble ? AudioProcessor::doublePrecision
|
||||
: AudioProcessor::singlePrecision);
|
||||
|
||||
processor->prepareToPlay (sampleRate, blockSize);
|
||||
}
|
||||
|
||||
|
|
@ -244,6 +249,8 @@ void AudioProcessorPlayer::audioDeviceIOCallbackWithContext (const float* const*
|
|||
{
|
||||
const ScopedLock sl (lock);
|
||||
|
||||
jassert (currentDevice != nullptr);
|
||||
|
||||
// These should have been prepared by audioDeviceAboutToStart()...
|
||||
jassert (sampleRate > 0 && blockSize > 0);
|
||||
|
||||
|
|
@ -269,6 +276,9 @@ void AudioProcessorPlayer::audioDeviceIOCallbackWithContext (const float* const*
|
|||
|
||||
const ScopedLock sl2 (processor->getCallbackLock());
|
||||
|
||||
if (std::exchange (currentWorkgroup, currentDevice->getWorkgroup()) != currentDevice->getWorkgroup())
|
||||
processor->audioWorkgroupContextChanged (currentWorkgroup);
|
||||
|
||||
class PlayHead : private AudioPlayHead
|
||||
{
|
||||
public:
|
||||
|
|
@ -352,6 +362,7 @@ void AudioProcessorPlayer::audioDeviceIOCallbackWithContext (const float* const*
|
|||
|
||||
void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* const device)
|
||||
{
|
||||
currentDevice = device;
|
||||
auto newSampleRate = device->getCurrentSampleRate();
|
||||
auto newBlockSize = device->getCurrentBufferSizeSamples();
|
||||
auto numChansIn = device->getActiveInputChannels().countNumberOfSetBits();
|
||||
|
|
@ -367,6 +378,8 @@ void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* const device)
|
|||
|
||||
messageCollector.reset (sampleRate);
|
||||
|
||||
currentWorkgroup.reset();
|
||||
|
||||
if (processor != nullptr)
|
||||
{
|
||||
if (isPrepared)
|
||||
|
|
@ -389,6 +402,9 @@ void AudioProcessorPlayer::audioDeviceStopped()
|
|||
blockSize = 0;
|
||||
isPrepared = false;
|
||||
tempBuffer.setSize (1, 1);
|
||||
|
||||
currentDevice = nullptr;
|
||||
currentWorkgroup.reset();
|
||||
}
|
||||
|
||||
void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
|
||||
|
|
|
|||
|
|
@ -139,6 +139,9 @@ private:
|
|||
MidiOutput* midiOutput = nullptr;
|
||||
uint64_t sampleCount = 0;
|
||||
|
||||
AudioIODevice* currentDevice = nullptr;
|
||||
AudioWorkgroup currentWorkgroup;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioProcessorPlayer)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue