diff --git a/modules/juce_audio_devices/native/juce_win32_ASIO.cpp b/modules/juce_audio_devices/native/juce_win32_ASIO.cpp index 76b373594b..eda949c533 100644 --- a/modules/juce_audio_devices/native/juce_win32_ASIO.cpp +++ b/modules/juce_audio_devices/native/juce_win32_ASIO.cpp @@ -26,14 +26,6 @@ #undef WINDOWS #undef log -// #define ASIO_DEBUGGING 1 - -#if ASIO_DEBUGGING - #define log(a) { Logger::writeToLog (a); DBG (a) } -#else - #define log(a) {} -#endif - /* The ASIO SDK *should* declare its callback functions as being __cdecl, but different versions seem to be pretty random about whether or not they do this. If you hit an error using these functions it'll be because you're trying to build using __stdcall, in which case you'd need to either get hold of @@ -44,7 +36,7 @@ //============================================================================== namespace ASIODebugging { - #if ASIO_DEBUGGING + #if ASIO_DEBUGGING static void log (const String& context, long error) { const char* err = "unknown error"; @@ -57,13 +49,15 @@ namespace ASIODebugging else if (error == ASE_NoClock) err = "No Clock"; else if (error == ASE_NoMemory) err = "Out of memory"; - log ("!!error: " + context + " - " + err); + log ("ASIO error: " + context + " - " + err); } + #define log(a) { Logger::writeToLog (a); DBG (a) } #define logError(a, b) ASIODebugging::log ((a), (b)) - #else + #else + #define log(a) {} #define logError(a, b) {} - #endif + #endif } //============================================================================== @@ -304,12 +298,12 @@ class ASIOAudioIODevice : public AudioIODevice, private Timer { public: - ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber, - const String& optionalDllForDirectLoading_) - : AudioIODevice (name_, "ASIO"), + ASIOAudioIODevice (const String& devName, const CLSID clsID, const int slotNumber, + const String& dllForDirectLoading) + : AudioIODevice (devName, "ASIO"), asioObject (nullptr), - classId (classId_), - optionalDllForDirectLoading (optionalDllForDirectLoading_), + classId (clsID), + optionalDllForDirectLoading (dllForDirectLoading), currentBitDepth (16), currentSampleRate (0), deviceIsOpen (false), @@ -319,7 +313,9 @@ public: insideControlPanelModalLoop (false), shouldUsePreferredSize (false) { - name = name_; + name = devName; + inBuffers.calloc (4); + outBuffers.calloc (4); jassert (currentASIODev [slotNumber] == nullptr); currentASIODev [slotNumber] = this; @@ -446,8 +442,8 @@ public: currentBlockSizeSamples = bufferSizeSamples; currentChansOut.clear(); currentChansIn.clear(); - zeromem (inBuffers, sizeof (inBuffers)); - zeromem (outBuffers, sizeof (outBuffers)); + inBuffers.clear (totalNumInputChans + 1); + outBuffers.clear (totalNumOutputChans + 1); updateSampleRates(); @@ -621,7 +617,7 @@ public: Array types; currentBitDepth = 16; - for (int i = 0; i < jmin ((int) totalNumInputChans, (int) maxASIOChannels); ++i) + for (int i = 0; i < (int) totalNumInputChans; ++i) { if (inputChannels[i]) { @@ -643,7 +639,7 @@ public: jassert (numActiveInputChans == n); n = 0; - for (int i = 0; i < jmin ((int) totalNumOutputChans, (int) maxASIOChannels); ++i) + for (int i = 0; i < (int) totalNumOutputChans; ++i) { if (outputChannels[i]) { @@ -915,14 +911,9 @@ private: AudioIODeviceCallback* volatile currentCallback; CriticalSection callbackLock; - enum { maxASIOChannels = 160 }; - - ASIOBufferInfo bufferInfos [maxASIOChannels]; - float* inBuffers [maxASIOChannels]; - float* outBuffers [maxASIOChannels]; - - ASIOSampleFormat inputFormat [maxASIOChannels]; - ASIOSampleFormat outputFormat [maxASIOChannels]; + HeapBlock bufferInfos; + HeapBlock inBuffers, outBuffers; + HeapBlock inputFormat, outputFormat; WaitableEvent event1; HeapBlock tempBuffer; @@ -1051,6 +1042,13 @@ private: { log (String ((int) totalNumInputChans) + " in, " + String ((int) totalNumOutputChans) + " out"); + const int chansToAllocate = totalNumInputChans + totalNumOutputChans + 4; + bufferInfos.calloc (chansToAllocate); + inBuffers.calloc (chansToAllocate); + outBuffers.calloc (chansToAllocate); + inputFormat.calloc (chansToAllocate); + outputFormat.calloc (chansToAllocate); + if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0) { // find a list of buffer sizes.. @@ -1300,11 +1298,11 @@ private: { for (int i = 0; i < numActiveInputChans; ++i) { - jassert (inBuffers[i]!= nullptr); + jassert (inBuffers[i] != nullptr); inputFormat[i].convertToFloat (infos[i].buffers[bi], inBuffers[i], samps); } - currentCallback->audioDeviceIOCallback ((const float**) inBuffers, numActiveInputChans, + currentCallback->audioDeviceIOCallback (const_cast (inBuffers.getData()), numActiveInputChans, outBuffers, numActiveOutputChans, samps); for (int i = 0; i < numActiveOutputChans; ++i) @@ -1612,8 +1610,7 @@ AudioIODeviceType* AudioIODeviceType::createAudioIODeviceType_ASIO() return new ASIOAudioIODeviceType(); } -AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name, - void* guid, +AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name, void* guid, const String& optionalDllForDirectLoading) { const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();