Browse Source

A few asio tweaks to avoid re-opening devices.

tags/2021-05-28
jules 12 years ago
parent
commit
e81f643734
1 changed files with 45 additions and 43 deletions
  1. +45
    -43
      modules/juce_audio_devices/native/juce_win32_ASIO.cpp

+ 45
- 43
modules/juce_audio_devices/native/juce_win32_ASIO.cpp View File

@@ -323,10 +323,12 @@ public:
optionalDllForDirectLoading (dllForDirectLoading), optionalDllForDirectLoading (dllForDirectLoading),
currentBitDepth (16), currentBitDepth (16),
currentSampleRate (0), currentSampleRate (0),
currentCallback (nullptr),
deviceIsOpen (false), deviceIsOpen (false),
isStarted (false), isStarted (false),
buffersCreated (false), buffersCreated (false),
postOutput (true), postOutput (true),
needToReset (false),
insideControlPanelModalLoop (false), insideControlPanelModalLoop (false),
shouldUsePreferredSize (false) shouldUsePreferredSize (false)
{ {
@@ -336,8 +338,6 @@ public:
jassert (currentASIODev [slotNumber] == nullptr); jassert (currentASIODev [slotNumber] == nullptr);
currentASIODev [slotNumber] = this; currentASIODev [slotNumber] = this;
openDevice();
} }
~ASIOAudioIODevice() ~ASIOAudioIODevice()
@@ -355,32 +355,37 @@ public:
{ {
// find a list of sample rates.. // find a list of sample rates..
const int possibleSampleRates[] = { 44100, 48000, 88200, 96000, 176400, 192000 }; const int possibleSampleRates[] = { 44100, 48000, 88200, 96000, 176400, 192000 };
sampleRates.clear();
Array<int> newRates;
if (asioObject != nullptr) if (asioObject != nullptr)
{ {
for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index) for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
{
const long err = asioObject->canSampleRate ((double) possibleSampleRates[index]);
JUCE_ASIO_LOG_ERROR ("canSampleRate " + String (possibleSampleRates[index]), err);
if (asioObject->canSampleRate ((double) possibleSampleRates[index]) == 0)
newRates.add (possibleSampleRates[index]);
}
if (err == 0)
{
sampleRates.add (possibleSampleRates[index]);
JUCE_ASIO_LOG ("rate: " + String (possibleSampleRates[index]));
}
}
if (newRates.size() == 0)
{
double cr = 0;
const long err = asioObject->getSampleRate (&cr);
JUCE_ASIO_LOG ("No sample rates supported - current rate: " + String ((int) cr));
JUCE_ASIO_LOG_ERROR ("getSampleRate", err);
if (sampleRates.size() == 0)
{
double cr = 0;
const long err = asioObject->getSampleRate (&cr);
JUCE_ASIO_LOG ("No sample rates supported - current rate: " + String ((int) cr));
JUCE_ASIO_LOG_ERROR ("getSampleRate", err);
if (err == 0)
newRates.add ((int) cr);
}
if (err == 0)
sampleRates.add ((int) cr);
}
if (sampleRates != newRates)
{
sampleRates.swapWithArray (newRates);
#if JUCE_ASIO_DEBUGGING
StringArray s;
for (int i = 0; i < sampleRates.size(); ++i)
s.add (String (sampleRates.getUnchecked(i)));
JUCE_ASIO_LOG ("Rates: " + s.joinIntoString (" "));
#endif
} }
} }
@@ -400,7 +405,7 @@ public:
int bufferSizeSamples) int bufferSizeSamples)
{ {
close(); close();
currentCallback = nullptr;
jassert (currentCallback == nullptr);
if (bufferSizeSamples <= 0) if (bufferSizeSamples <= 0)
shouldUsePreferredSize = true; shouldUsePreferredSize = true;
@@ -813,7 +818,6 @@ public:
{ {
stopTimer(); stopTimer();
// used to cause a reset
JUCE_ASIO_LOG ("restart request!"); JUCE_ASIO_LOG ("restart request!");
AudioIODeviceCallback* const oldCallback = currentCallback; AudioIODeviceCallback* const oldCallback = currentCallback;
@@ -1090,7 +1094,7 @@ private:
if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0) if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
{ {
// find a list of buffer sizes.. // find a list of buffer sizes..
JUCE_ASIO_LOG (String ((int) minSize) + " " + String ((int) maxSize) + " " + String ((int) preferredSize) + " " + String ((int) granularity));
JUCE_ASIO_LOG (String ((int) minSize) + "->" + String ((int) maxSize) + ", " + String ((int) preferredSize) + ", " + String ((int) granularity));
if (granularity >= 0) if (granularity >= 0)
{ {
@@ -1216,7 +1220,7 @@ private:
// ignore an error here, as it might start later after setting other stuff up // ignore an error here, as it might start later after setting other stuff up
JUCE_ASIO_LOG_ERROR ("start", err); JUCE_ASIO_LOG_ERROR ("start", err);
Thread::sleep (100);
Thread::sleep (80);
asioObject->stop(); asioObject->stop();
} }
else else
@@ -1250,6 +1254,7 @@ private:
deviceIsOpen = false; deviceIsOpen = false;
needToReset = false; needToReset = false;
stopTimer();
return error; return error;
} }
@@ -1365,27 +1370,16 @@ private:
switch (selector) switch (selector)
{ {
case kAsioSelectorSupported: case kAsioSelectorSupported:
if (value == kAsioResetRequest
|| value == kAsioEngineVersion
|| value == kAsioResyncRequest
|| value == kAsioLatenciesChanged
|| value == kAsioSupportsInputMonitor)
if (value == kAsioResetRequest || value == kAsioEngineVersion || value == kAsioResyncRequest
|| value == kAsioLatenciesChanged || value == kAsioSupportsInputMonitor)
return 1; return 1;
break; break;
case kAsioBufferSizeChange:
case kAsioResetRequest:
case kAsioResyncRequest:
if (currentASIODev[deviceIndex] != nullptr)
currentASIODev[deviceIndex]->resetRequest();
return 1;
case kAsioLatenciesChanged:
return 1;
case kAsioEngineVersion:
return 2;
case kAsioBufferSizeChange: JUCE_ASIO_LOG ("kAsioBufferSizeChange"); return sendResetRequest (deviceIndex);
case kAsioResetRequest: JUCE_ASIO_LOG ("kAsioResetRequest"); return sendResetRequest (deviceIndex);
case kAsioResyncRequest: JUCE_ASIO_LOG ("kAsioResyncRequest"); return sendResetRequest (deviceIndex);
case kAsioLatenciesChanged: JUCE_ASIO_LOG ("kAsioLatenciesChanged"); return 1;
case kAsioEngineVersion: return 2;
case kAsioSupportsTimeInfo: case kAsioSupportsTimeInfo:
case kAsioSupportsTimeCode: case kAsioSupportsTimeCode:
@@ -1395,6 +1389,14 @@ private:
return 0; return 0;
} }
static long sendResetRequest (int deviceIndex)
{
if (currentASIODev[deviceIndex] != nullptr)
currentASIODev[deviceIndex]->resetRequest();
return 1;
}
static void JUCE_ASIOCALLBACK sampleRateChangedCallback (ASIOSampleRate) static void JUCE_ASIOCALLBACK sampleRateChangedCallback (ASIOSampleRate)
{ {
} }


Loading…
Cancel
Save