mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
DSP: Ensure that IRs are loaded immediately when Convolution is prepared
Previously, if `loadImpulseResponse` was called before `prepareToPlay`, the IR wasn't guaranteed to have loaded before the first call to `processSamples`. Now, we flush the queue of pending IR-load commands during `prepareToPlay`, which should ensure that the most recently-loaded IR is ready to use immediately.
This commit is contained in:
parent
c213796951
commit
cd41e31cb5
2 changed files with 88 additions and 12 deletions
|
|
@ -86,6 +86,12 @@ public:
|
|||
// This function is only safe to call from a single thread at a time.
|
||||
bool push (IncomingCommand& command) { return queue.push (command); }
|
||||
|
||||
void popAll()
|
||||
{
|
||||
const ScopedLock lock (popMutex);
|
||||
queue.popAll ([] (IncomingCommand& command) { command(); command = nullptr; });
|
||||
}
|
||||
|
||||
using Thread::startThread;
|
||||
using Thread::stopThread;
|
||||
|
||||
|
|
@ -94,13 +100,23 @@ private:
|
|||
{
|
||||
while (! threadShouldExit())
|
||||
{
|
||||
if (queue.hasPendingMessages())
|
||||
const auto tryPop = [&]
|
||||
{
|
||||
const ScopedLock lock (popMutex);
|
||||
|
||||
if (! queue.hasPendingMessages())
|
||||
return false;
|
||||
|
||||
queue.pop ([] (IncomingCommand& command) { command(); command = nullptr;});
|
||||
else
|
||||
return true;
|
||||
};
|
||||
|
||||
if (! tryPop())
|
||||
sleep (10);
|
||||
}
|
||||
}
|
||||
|
||||
CriticalSection popMutex;
|
||||
Queue<IncomingCommand> queue;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BackgroundMessageQueue)
|
||||
|
|
@ -892,7 +908,6 @@ public:
|
|||
std::unique_ptr<MultichannelEngine> getEngine() { return factory.getEngine(); }
|
||||
|
||||
private:
|
||||
|
||||
template <typename Fn>
|
||||
void callLater (Fn&& fn)
|
||||
{
|
||||
|
|
@ -1017,9 +1032,13 @@ public:
|
|||
|
||||
void prepare (const ProcessSpec& spec)
|
||||
{
|
||||
messageQueue->pimpl->popAll();
|
||||
mixer.prepare (spec);
|
||||
engineQueue->prepare (spec);
|
||||
currentEngine = engineQueue->getEngine();
|
||||
|
||||
if (auto newEngine = engineQueue->getEngine())
|
||||
currentEngine = std::move (newEngine);
|
||||
|
||||
previousEngine = nullptr;
|
||||
jassert (currentEngine != nullptr);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue