mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Updated old code where the 'volatile' keyword was still being used
This commit is contained in:
parent
5faef29f3e
commit
e2dcc32f88
17 changed files with 580 additions and 649 deletions
|
|
@ -77,11 +77,7 @@ struct ASIOSampleFormat
|
|||
{
|
||||
ASIOSampleFormat() noexcept {}
|
||||
|
||||
ASIOSampleFormat (const long type) noexcept
|
||||
: bitDepth (24),
|
||||
littleEndian (true),
|
||||
formatIsFloat (false),
|
||||
byteStride (4)
|
||||
ASIOSampleFormat (long type) noexcept
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
|
@ -114,7 +110,7 @@ struct ASIOSampleFormat
|
|||
}
|
||||
}
|
||||
|
||||
void convertToFloat (const void* const src, float* const dst, const int samps) const noexcept
|
||||
void convertToFloat (const void* src, float* dst, int samps) const noexcept
|
||||
{
|
||||
if (formatIsFloat)
|
||||
{
|
||||
|
|
@ -132,7 +128,7 @@ struct ASIOSampleFormat
|
|||
}
|
||||
}
|
||||
|
||||
void convertFromFloat (const float* const src, void* const dst, const int samps) const noexcept
|
||||
void convertFromFloat (const float* src, void* dst, int samps) const noexcept
|
||||
{
|
||||
if (formatIsFloat)
|
||||
{
|
||||
|
|
@ -150,18 +146,18 @@ struct ASIOSampleFormat
|
|||
}
|
||||
}
|
||||
|
||||
void clear (void* dst, const int numSamps) noexcept
|
||||
void clear (void* dst, int numSamps) noexcept
|
||||
{
|
||||
if (dst != nullptr)
|
||||
zeromem (dst, numSamps * byteStride);
|
||||
}
|
||||
|
||||
int bitDepth, byteStride;
|
||||
bool formatIsFloat, littleEndian;
|
||||
int bitDepth = 24, byteStride = 4;
|
||||
bool formatIsFloat = false, littleEndian = true;
|
||||
|
||||
private:
|
||||
static void convertInt16ToFloat (const char* src, float* dest, const int srcStrideBytes,
|
||||
int numSamples, const bool littleEndian) noexcept
|
||||
static void convertInt16ToFloat (const char* src, float* dest, int srcStrideBytes,
|
||||
int numSamples, bool littleEndian) noexcept
|
||||
{
|
||||
const double g = 1.0 / 32768.0;
|
||||
|
||||
|
|
@ -183,8 +179,8 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
static void convertFloatToInt16 (const float* src, char* dest, const int dstStrideBytes,
|
||||
int numSamples, const bool littleEndian) noexcept
|
||||
static void convertFloatToInt16 (const float* src, char* dest, int dstStrideBytes,
|
||||
int numSamples, bool littleEndian) noexcept
|
||||
{
|
||||
const double maxVal = (double) 0x7fff;
|
||||
|
||||
|
|
@ -206,8 +202,8 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
static void convertInt24ToFloat (const char* src, float* dest, const int srcStrideBytes,
|
||||
int numSamples, const bool littleEndian) noexcept
|
||||
static void convertInt24ToFloat (const char* src, float* dest, int srcStrideBytes,
|
||||
int numSamples, bool littleEndian) noexcept
|
||||
{
|
||||
const double g = 1.0 / 0x7fffff;
|
||||
|
||||
|
|
@ -229,8 +225,8 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
static void convertFloatToInt24 (const float* src, char* dest, const int dstStrideBytes,
|
||||
int numSamples, const bool littleEndian) noexcept
|
||||
static void convertFloatToInt24 (const float* src, char* dest, int dstStrideBytes,
|
||||
int numSamples, bool littleEndian) noexcept
|
||||
{
|
||||
const double maxVal = (double) 0x7fffff;
|
||||
|
||||
|
|
@ -252,8 +248,8 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
static void convertInt32ToFloat (const char* src, float* dest, const int srcStrideBytes,
|
||||
int numSamples, const bool littleEndian) noexcept
|
||||
static void convertInt32ToFloat (const char* src, float* dest, int srcStrideBytes,
|
||||
int numSamples, bool littleEndian) noexcept
|
||||
{
|
||||
const double g = 1.0 / 0x7fffffff;
|
||||
|
||||
|
|
@ -275,8 +271,8 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
static void convertFloatToInt32 (const float* src, char* dest, const int dstStrideBytes,
|
||||
int numSamples, const bool littleEndian) noexcept
|
||||
static void convertFloatToInt32 (const float* src, char* dest, int dstStrideBytes,
|
||||
int numSamples, bool littleEndian) noexcept
|
||||
{
|
||||
const double maxVal = (double) 0x7fffffff;
|
||||
|
||||
|
|
@ -300,8 +296,9 @@ private:
|
|||
};
|
||||
|
||||
//==============================================================================
|
||||
constexpr int maxNumASIODevices = 16;
|
||||
class ASIOAudioIODevice;
|
||||
static ASIOAudioIODevice* volatile currentASIODev[16] = { 0 };
|
||||
static ASIOAudioIODevice* currentASIODev[maxNumASIODevices] = {};
|
||||
|
||||
extern HWND juce_messageWindowHandle;
|
||||
|
||||
|
|
@ -314,33 +311,10 @@ class ASIOAudioIODevice : public AudioIODevice,
|
|||
{
|
||||
public:
|
||||
ASIOAudioIODevice (ASIOAudioIODeviceType* ownerType, const String& devName,
|
||||
const CLSID clsID, const int slotNumber)
|
||||
CLSID clsID, int slotNumber)
|
||||
: AudioIODevice (devName, "ASIO"),
|
||||
owner (ownerType),
|
||||
asioObject (nullptr),
|
||||
classId (clsID),
|
||||
inputLatency (0),
|
||||
outputLatency (0),
|
||||
minBufferSize (0), maxBufferSize (0),
|
||||
preferredBufferSize (0),
|
||||
bufferGranularity (0),
|
||||
numClockSources (0),
|
||||
currentBlockSizeSamples (0),
|
||||
currentBitDepth (16),
|
||||
currentSampleRate (0),
|
||||
currentCallback (nullptr),
|
||||
bufferIndex (0),
|
||||
numActiveInputChans (0),
|
||||
numActiveOutputChans (0),
|
||||
deviceIsOpen (false),
|
||||
isStarted (false),
|
||||
buffersCreated (false),
|
||||
calledback (false),
|
||||
littleEndian (false),
|
||||
postOutput (true),
|
||||
needToReset (false),
|
||||
insideControlPanelModalLoop (false),
|
||||
shouldUsePreferredSize (false)
|
||||
classId (clsID)
|
||||
{
|
||||
::CoInitialize (nullptr);
|
||||
|
||||
|
|
@ -348,15 +322,15 @@ public:
|
|||
inBuffers.calloc (4);
|
||||
outBuffers.calloc (4);
|
||||
|
||||
jassert (currentASIODev [slotNumber] == nullptr);
|
||||
currentASIODev [slotNumber] = this;
|
||||
jassert (currentASIODev[slotNumber] == nullptr);
|
||||
currentASIODev[slotNumber] = this;
|
||||
|
||||
openDevice();
|
||||
}
|
||||
|
||||
~ASIOAudioIODevice()
|
||||
{
|
||||
for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
|
||||
for (int i = 0; i < maxNumASIODevices; ++i)
|
||||
if (currentASIODev[i] == this)
|
||||
currentASIODev[i] = nullptr;
|
||||
|
||||
|
|
@ -381,7 +355,7 @@ public:
|
|||
|
||||
if (newRates.isEmpty())
|
||||
{
|
||||
double cr = getSampleRate();
|
||||
auto cr = getSampleRate();
|
||||
JUCE_ASIO_LOG ("No sample rates supported - current rate: " + String ((int) cr));
|
||||
|
||||
if (cr > 0)
|
||||
|
|
@ -394,8 +368,9 @@ public:
|
|||
|
||||
#if JUCE_ASIO_DEBUGGING
|
||||
StringArray s;
|
||||
for (int i = 0; i < sampleRates.size(); ++i)
|
||||
s.add (String (sampleRates.getUnchecked(i)));
|
||||
|
||||
for (auto r : sampleRates)
|
||||
s.add (String (r));
|
||||
|
||||
JUCE_ASIO_LOG ("Rates: " + s.joinIntoString (" "));
|
||||
#endif
|
||||
|
|
@ -425,21 +400,20 @@ public:
|
|||
|
||||
if (asioObject == nullptr)
|
||||
{
|
||||
const String openingError (openDevice());
|
||||
auto openingError = openDevice();
|
||||
|
||||
if (asioObject == nullptr)
|
||||
return openingError;
|
||||
}
|
||||
|
||||
isStarted = false;
|
||||
bufferIndex = -1;
|
||||
|
||||
long err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans);
|
||||
auto err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans);
|
||||
jassert (err == ASE_OK);
|
||||
|
||||
bufferSizeSamples = readBufferSizes (bufferSizeSamples);
|
||||
|
||||
double sampleRate = sr;
|
||||
auto sampleRate = sr;
|
||||
currentSampleRate = sampleRate;
|
||||
currentBlockSizeSamples = bufferSizeSamples;
|
||||
currentChansOut.clear();
|
||||
|
|
@ -450,9 +424,11 @@ public:
|
|||
if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
|
||||
sampleRate = sampleRates[0];
|
||||
|
||||
jassert (sampleRate != 0);
|
||||
if (sampleRate == 0)
|
||||
{
|
||||
jassertfalse;
|
||||
sampleRate = 44100.0;
|
||||
}
|
||||
|
||||
updateClockSources();
|
||||
currentSampleRate = getSampleRate();
|
||||
|
|
@ -486,7 +462,7 @@ public:
|
|||
needToReset = false;
|
||||
}
|
||||
|
||||
const int totalBuffers = resetBuffers (inputChannels, outputChannels);
|
||||
auto totalBuffers = resetBuffers (inputChannels, outputChannels);
|
||||
|
||||
setCallbackFunctions();
|
||||
|
||||
|
|
@ -508,7 +484,7 @@ public:
|
|||
if (err == ASE_OK)
|
||||
{
|
||||
buffersCreated = true;
|
||||
tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
|
||||
ioBufferSpace.calloc (totalBuffers * currentBlockSizeSamples + 32);
|
||||
|
||||
int n = 0;
|
||||
Array<int> types;
|
||||
|
|
@ -518,7 +494,7 @@ public:
|
|||
{
|
||||
if (inputChannels[i])
|
||||
{
|
||||
inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
|
||||
inBuffers[n] = ioBufferSpace + (currentBlockSizeSamples * n);
|
||||
|
||||
ASIOChannelInfo channelInfo = { 0 };
|
||||
channelInfo.channel = i;
|
||||
|
|
@ -540,7 +516,7 @@ public:
|
|||
{
|
||||
if (outputChannels[i])
|
||||
{
|
||||
outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
|
||||
outBuffers[n] = ioBufferSpace + (currentBlockSizeSamples * (numActiveInputChans + n));
|
||||
|
||||
ASIOChannelInfo channelInfo = { 0 };
|
||||
channelInfo.channel = i;
|
||||
|
|
@ -564,8 +540,8 @@ public:
|
|||
|
||||
for (int i = 0; i < numActiveOutputChans; ++i)
|
||||
{
|
||||
outputFormat[i].clear (bufferInfos [numActiveInputChans + i].buffers[0], currentBlockSizeSamples);
|
||||
outputFormat[i].clear (bufferInfos [numActiveInputChans + i].buffers[1], currentBlockSizeSamples);
|
||||
outputFormat[i].clear (bufferInfos[numActiveInputChans + i].buffers[0], currentBlockSizeSamples);
|
||||
outputFormat[i].clear (bufferInfos[numActiveInputChans + i].buffers[1], currentBlockSizeSamples);
|
||||
}
|
||||
|
||||
readLatencies();
|
||||
|
|
@ -615,7 +591,7 @@ public:
|
|||
isStarted = false;
|
||||
deviceIsOpen = false;
|
||||
|
||||
const String errorCopy (error);
|
||||
auto errorCopy = error;
|
||||
close(); // (this resets the error string)
|
||||
error = errorCopy;
|
||||
}
|
||||
|
|
@ -678,7 +654,7 @@ public:
|
|||
|
||||
void stop() override
|
||||
{
|
||||
AudioIODeviceCallback* const lastCallback = currentCallback;
|
||||
auto* lastCallback = currentCallback;
|
||||
|
||||
{
|
||||
const ScopedLock sl (callbackLock);
|
||||
|
|
@ -698,15 +674,13 @@ public:
|
|||
|
||||
bool done = false;
|
||||
insideControlPanelModalLoop = true;
|
||||
|
||||
const uint32 started = Time::getMillisecondCounter();
|
||||
auto started = Time::getMillisecondCounter();
|
||||
|
||||
if (asioObject != nullptr)
|
||||
{
|
||||
asioObject->controlPanel();
|
||||
|
||||
const int spent = (int) Time::getMillisecondCounter() - (int) started;
|
||||
|
||||
auto spent = (int) (Time::getMillisecondCounter() - started);
|
||||
JUCE_ASIO_LOG ("spent: " + String (spent));
|
||||
|
||||
if (spent > 300)
|
||||
|
|
@ -730,13 +704,10 @@ public:
|
|||
if (! insideControlPanelModalLoop)
|
||||
{
|
||||
stopTimer();
|
||||
|
||||
JUCE_ASIO_LOG ("restart request!");
|
||||
|
||||
AudioIODeviceCallback* const oldCallback = currentCallback;
|
||||
|
||||
auto* oldCallback = currentCallback;
|
||||
close();
|
||||
|
||||
needToReset = true;
|
||||
open (BigInteger (currentChansIn), BigInteger (currentChansOut),
|
||||
currentSampleRate, currentBlockSizeSamples);
|
||||
|
|
@ -757,51 +728,49 @@ public:
|
|||
private:
|
||||
//==============================================================================
|
||||
WeakReference<ASIOAudioIODeviceType> owner;
|
||||
IASIO* volatile asioObject;
|
||||
IASIO* asioObject = {};
|
||||
ASIOCallbacks callbacks;
|
||||
|
||||
CLSID classId;
|
||||
String error;
|
||||
|
||||
long totalNumInputChans, totalNumOutputChans;
|
||||
long totalNumInputChans = 0, totalNumOutputChans = 0;
|
||||
StringArray inputChannelNames, outputChannelNames;
|
||||
|
||||
Array<double> sampleRates;
|
||||
Array<int> bufferSizes;
|
||||
long inputLatency, outputLatency;
|
||||
long minBufferSize, maxBufferSize, preferredBufferSize, bufferGranularity;
|
||||
ASIOClockSource clocks[32];
|
||||
int numClockSources;
|
||||
long inputLatency = 0, outputLatency = 0;
|
||||
long minBufferSize = 0, maxBufferSize = 0, preferredBufferSize = 0, bufferGranularity = 0;
|
||||
ASIOClockSource clocks[32] = {};
|
||||
int numClockSources = 0;
|
||||
|
||||
int volatile currentBlockSizeSamples;
|
||||
int volatile currentBitDepth;
|
||||
double volatile currentSampleRate;
|
||||
int currentBlockSizeSamples = 0;
|
||||
int currentBitDepth = 16;
|
||||
double currentSampleRate = 0;
|
||||
BigInteger currentChansOut, currentChansIn;
|
||||
AudioIODeviceCallback* volatile currentCallback;
|
||||
AudioIODeviceCallback* currentCallback = {};
|
||||
CriticalSection callbackLock;
|
||||
|
||||
HeapBlock<ASIOBufferInfo> bufferInfos;
|
||||
HeapBlock<float*> inBuffers, outBuffers;
|
||||
HeapBlock<float> ioBufferSpace;
|
||||
HeapBlock<ASIOSampleFormat> inputFormat, outputFormat;
|
||||
int numActiveInputChans = 0, numActiveOutputChans = 0;
|
||||
|
||||
WaitableEvent event1;
|
||||
HeapBlock<float> tempBuffer;
|
||||
int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
|
||||
|
||||
bool deviceIsOpen, isStarted, buffersCreated;
|
||||
bool volatile calledback;
|
||||
bool volatile littleEndian, postOutput, needToReset;
|
||||
bool volatile insideControlPanelModalLoop;
|
||||
bool volatile shouldUsePreferredSize;
|
||||
bool deviceIsOpen = false, isStarted = false, buffersCreated = false;
|
||||
std::atomic<bool> calledback { false };
|
||||
bool littleEndian = false, postOutput = true, needToReset = false;
|
||||
bool insideControlPanelModalLoop = false;
|
||||
bool shouldUsePreferredSize = false;
|
||||
int xruns = 0;
|
||||
|
||||
//==============================================================================
|
||||
static String convertASIOString (char* const text, int length)
|
||||
static String convertASIOString (char* text, int length)
|
||||
{
|
||||
if (CharPointer_UTF8::isValidString (text, length))
|
||||
return String::fromUTF8 (text, length);
|
||||
|
||||
WCHAR wideVersion [64] = { 0 };
|
||||
WCHAR wideVersion[64] = {};
|
||||
MultiByteToWideChar (CP_ACP, 0, text, length, wideVersion, numElementsInArray (wideVersion));
|
||||
return wideVersion;
|
||||
}
|
||||
|
|
@ -867,7 +836,7 @@ private:
|
|||
if (shouldUsePreferredSize)
|
||||
{
|
||||
JUCE_ASIO_LOG ("Using preferred size for buffer..");
|
||||
long err = refreshBufferSizes();
|
||||
auto err = refreshBufferSizes();
|
||||
|
||||
if (err == ASE_OK)
|
||||
{
|
||||
|
|
@ -890,8 +859,8 @@ private:
|
|||
{
|
||||
numActiveInputChans = 0;
|
||||
numActiveOutputChans = 0;
|
||||
auto* info = bufferInfos.get();
|
||||
|
||||
ASIOBufferInfo* info = bufferInfos;
|
||||
for (int i = 0; i < totalNumInputChans; ++i)
|
||||
{
|
||||
if (inputChannels[i])
|
||||
|
|
@ -952,7 +921,7 @@ private:
|
|||
double getSampleRate() const
|
||||
{
|
||||
double cr = 0;
|
||||
long err = asioObject->getSampleRate (&cr);
|
||||
auto err = asioObject->getSampleRate (&cr);
|
||||
JUCE_ASIO_LOG_ERROR ("getSampleRate", err);
|
||||
return cr;
|
||||
}
|
||||
|
|
@ -962,7 +931,7 @@ private:
|
|||
if (currentSampleRate != newRate)
|
||||
{
|
||||
JUCE_ASIO_LOG ("rate change: " + String (currentSampleRate) + " to " + String (newRate));
|
||||
long err = asioObject->setSampleRate (newRate);
|
||||
auto err = asioObject->setSampleRate (newRate);
|
||||
|
||||
if (err == ASE_NoClock && numClockSources > 0)
|
||||
{
|
||||
|
|
@ -970,7 +939,6 @@ private:
|
|||
Thread::sleep (10);
|
||||
err = asioObject->setClockSource (clocks[0].index);
|
||||
JUCE_ASIO_LOG_ERROR ("setClockSource2", err);
|
||||
|
||||
Thread::sleep (10);
|
||||
err = asioObject->setSampleRate (newRate);
|
||||
}
|
||||
|
|
@ -1009,7 +977,7 @@ private:
|
|||
if (numClockSources > 1 && ! isSourceSet)
|
||||
{
|
||||
JUCE_ASIO_LOG ("setting clock source");
|
||||
long err = asioObject->setClockSource (clocks[0].index);
|
||||
auto err = asioObject->setClockSource (clocks[0].index);
|
||||
JUCE_ASIO_LOG_ERROR ("setClockSource1", err);
|
||||
Thread::sleep (20);
|
||||
}
|
||||
|
|
@ -1035,7 +1003,7 @@ private:
|
|||
numActiveInputChans = 0;
|
||||
numActiveOutputChans = 0;
|
||||
|
||||
ASIOBufferInfo* info = bufferInfos;
|
||||
auto* info = bufferInfos.get();
|
||||
int numChans = 0;
|
||||
|
||||
for (int i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
|
||||
|
|
@ -1064,7 +1032,7 @@ private:
|
|||
|
||||
if (preferredSize > 0)
|
||||
{
|
||||
long err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
|
||||
auto err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
|
||||
JUCE_ASIO_LOG_ERROR ("dummy buffers", err);
|
||||
}
|
||||
|
||||
|
|
@ -1094,8 +1062,8 @@ private:
|
|||
if (i < 2)
|
||||
{
|
||||
// clear the channels that are used with the dummy stuff
|
||||
outputFormat[i].clear (bufferInfos [outputBufferIndex + i].buffers[0], preferredBufferSize);
|
||||
outputFormat[i].clear (bufferInfos [outputBufferIndex + i].buffers[1], preferredBufferSize);
|
||||
outputFormat[i].clear (bufferInfos[outputBufferIndex + i].buffers[0], preferredBufferSize);
|
||||
outputFormat[i].clear (bufferInfos[outputBufferIndex + i].buffers[1], preferredBufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1140,7 +1108,7 @@ private:
|
|||
String getLastDriverError() const
|
||||
{
|
||||
jassert (asioObject != nullptr);
|
||||
char buffer [512] = { 0 };
|
||||
char buffer[512] = {};
|
||||
asioObject->getErrorMessage (buffer);
|
||||
return String (buffer, sizeof (buffer) - 1);
|
||||
}
|
||||
|
|
@ -1163,7 +1131,7 @@ private:
|
|||
|
||||
if (driverError.isEmpty())
|
||||
{
|
||||
char buffer [512];
|
||||
char buffer[512] = {};
|
||||
asioObject->getDriverName (buffer); // just in case any flimsy drivers expect this to be called..
|
||||
}
|
||||
|
||||
|
|
@ -1187,7 +1155,6 @@ private:
|
|||
numActiveOutputChans = 0;
|
||||
xruns = 0;
|
||||
currentCallback = nullptr;
|
||||
|
||||
error.clear();
|
||||
|
||||
if (getName().isEmpty())
|
||||
|
|
@ -1220,7 +1187,7 @@ private:
|
|||
{
|
||||
addBufferSizes (minBufferSize, maxBufferSize, preferredBufferSize, bufferGranularity);
|
||||
|
||||
double currentRate = getSampleRate();
|
||||
auto currentRate = getSampleRate();
|
||||
|
||||
if (currentRate < 1.0 || currentRate > 192001.0)
|
||||
{
|
||||
|
|
@ -1232,13 +1199,12 @@ private:
|
|||
}
|
||||
|
||||
currentSampleRate = currentRate;
|
||||
|
||||
postOutput = (asioObject->outputReady() == 0);
|
||||
|
||||
if (postOutput)
|
||||
JUCE_ASIO_LOG ("outputReady true");
|
||||
|
||||
updateSampleRates();
|
||||
|
||||
readLatencies(); // ..doing these steps because cubase does so at this stage
|
||||
createDummyBuffers (preferredBufferSize); // in initialisation, and some devices fail if we don't.
|
||||
readLatencies();
|
||||
|
|
@ -1294,12 +1260,11 @@ private:
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
void JUCE_ASIOCALLBACK callback (const long index)
|
||||
void JUCE_ASIOCALLBACK callback (long index)
|
||||
{
|
||||
if (isStarted)
|
||||
{
|
||||
bufferIndex = index;
|
||||
processBuffer();
|
||||
processBuffer (index);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1310,23 +1275,21 @@ private:
|
|||
calledback = true;
|
||||
}
|
||||
|
||||
void processBuffer()
|
||||
void processBuffer (long bufferIndex)
|
||||
{
|
||||
const ASIOBufferInfo* const infos = bufferInfos;
|
||||
const int bi = bufferIndex;
|
||||
|
||||
const ScopedLock sl (callbackLock);
|
||||
|
||||
if (bi >= 0)
|
||||
if (bufferIndex >= 0)
|
||||
{
|
||||
const int samps = currentBlockSizeSamples;
|
||||
auto* infos = bufferInfos.get();
|
||||
auto samps = currentBlockSizeSamples;
|
||||
|
||||
if (currentCallback != nullptr)
|
||||
{
|
||||
for (int i = 0; i < numActiveInputChans; ++i)
|
||||
{
|
||||
jassert (inBuffers[i] != nullptr);
|
||||
inputFormat[i].convertToFloat (infos[i].buffers[bi], inBuffers[i], samps);
|
||||
inputFormat[i].convertToFloat (infos[i].buffers[bufferIndex], inBuffers[i], samps);
|
||||
}
|
||||
|
||||
currentCallback->audioDeviceIOCallback (const_cast<const float**> (inBuffers.getData()), numActiveInputChans,
|
||||
|
|
@ -1335,13 +1298,13 @@ private:
|
|||
for (int i = 0; i < numActiveOutputChans; ++i)
|
||||
{
|
||||
jassert (outBuffers[i] != nullptr);
|
||||
outputFormat[i].convertFromFloat (outBuffers[i], infos [numActiveInputChans + i].buffers[bi], samps);
|
||||
outputFormat[i].convertFromFloat (outBuffers[i], infos[numActiveInputChans + i].buffers[bufferIndex], samps);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < numActiveOutputChans; ++i)
|
||||
outputFormat[i].clear (infos[numActiveInputChans + i].buffers[bi], samps);
|
||||
outputFormat[i].clear (infos[numActiveInputChans + i].buffers[bufferIndex], samps);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1359,15 +1322,15 @@ private:
|
|||
return 1;
|
||||
break;
|
||||
|
||||
case kAsioBufferSizeChange: JUCE_ASIO_LOG ("kAsioBufferSizeChange"); resetRequest(); return 1;
|
||||
case kAsioResetRequest: JUCE_ASIO_LOG ("kAsioResetRequest"); resetRequest(); return 1;
|
||||
case kAsioResyncRequest: JUCE_ASIO_LOG ("kAsioResyncRequest"); resetRequest(); return 1;
|
||||
case kAsioLatenciesChanged: JUCE_ASIO_LOG ("kAsioLatenciesChanged"); return 1;
|
||||
case kAsioEngineVersion: return 2;
|
||||
case kAsioBufferSizeChange: JUCE_ASIO_LOG ("kAsioBufferSizeChange"); resetRequest(); return 1;
|
||||
case kAsioResetRequest: JUCE_ASIO_LOG ("kAsioResetRequest"); resetRequest(); return 1;
|
||||
case kAsioResyncRequest: JUCE_ASIO_LOG ("kAsioResyncRequest"); resetRequest(); return 1;
|
||||
case kAsioLatenciesChanged: JUCE_ASIO_LOG ("kAsioLatenciesChanged"); return 1;
|
||||
case kAsioEngineVersion: return 2;
|
||||
|
||||
case kAsioSupportsTimeInfo:
|
||||
case kAsioSupportsTimeCode: return 0;
|
||||
case kAsioOverload: xruns++; return 1;
|
||||
case kAsioOverload: ++xruns; return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -1379,29 +1342,30 @@ private:
|
|||
{
|
||||
static ASIOTime* JUCE_ASIOCALLBACK bufferSwitchTimeInfoCallback (ASIOTime*, long index, long)
|
||||
{
|
||||
if (currentASIODev[deviceIndex] != nullptr)
|
||||
currentASIODev[deviceIndex]->callback (index);
|
||||
if (auto* d = currentASIODev[deviceIndex])
|
||||
d->callback (index);
|
||||
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
static void JUCE_ASIOCALLBACK bufferSwitchCallback (long index, long)
|
||||
{
|
||||
if (currentASIODev[deviceIndex] != nullptr)
|
||||
currentASIODev[deviceIndex]->callback (index);
|
||||
if (auto* d = currentASIODev[deviceIndex])
|
||||
d->callback (index);
|
||||
}
|
||||
|
||||
static long JUCE_ASIOCALLBACK asioMessagesCallback (long selector, long value, void*, double*)
|
||||
{
|
||||
return currentASIODev[deviceIndex] != nullptr
|
||||
? currentASIODev[deviceIndex]->asioMessagesCallback (selector, value)
|
||||
: 0;
|
||||
if (auto* d = currentASIODev[deviceIndex])
|
||||
return d->asioMessagesCallback (selector, value);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static void JUCE_ASIOCALLBACK sampleRateChangedCallback (ASIOSampleRate)
|
||||
{
|
||||
if (currentASIODev[deviceIndex] != nullptr)
|
||||
currentASIODev[deviceIndex]->resetRequest();
|
||||
if (auto* d = currentASIODev[deviceIndex])
|
||||
d->resetRequest();
|
||||
}
|
||||
|
||||
static void setCallbacks (ASIOCallbacks& callbacks) noexcept
|
||||
|
|
@ -1430,7 +1394,7 @@ private:
|
|||
};
|
||||
|
||||
template <>
|
||||
struct ASIOAudioIODevice::ASIOCallbackFunctions <sizeof(currentASIODev) / sizeof(currentASIODev[0])>
|
||||
struct ASIOAudioIODevice::ASIOCallbackFunctions<maxNumASIODevices>
|
||||
{
|
||||
static void setCallbacksForDevice (ASIOCallbacks&, ASIOAudioIODevice*) noexcept {}
|
||||
};
|
||||
|
|
@ -1442,10 +1406,9 @@ public:
|
|||
ASIOAudioIODeviceType() : AudioIODeviceType ("ASIO") {}
|
||||
|
||||
//==============================================================================
|
||||
void scanForDevices()
|
||||
void scanForDevices() override
|
||||
{
|
||||
hasScanned = true;
|
||||
|
||||
deviceNames.clear();
|
||||
classIds.clear();
|
||||
|
||||
|
|
@ -1454,7 +1417,7 @@ public:
|
|||
|
||||
if (RegOpenKey (HKEY_LOCAL_MACHINE, _T("software\\asio"), &hk) == ERROR_SUCCESS)
|
||||
{
|
||||
TCHAR name [256];
|
||||
TCHAR name[256] = {};
|
||||
|
||||
while (RegEnumKey (hk, index++, name, numElementsInArray (name)) == ERROR_SUCCESS)
|
||||
addDriverInfo (name, hk);
|
||||
|
|
@ -1463,14 +1426,13 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
StringArray getDeviceNames (bool /*wantInputNames*/) const
|
||||
StringArray getDeviceNames (bool /*wantInputNames*/) const override
|
||||
{
|
||||
jassert (hasScanned); // need to call scanForDevices() before doing this
|
||||
|
||||
return deviceNames;
|
||||
}
|
||||
|
||||
int getDefaultDeviceIndex (bool) const
|
||||
int getDefaultDeviceIndex (bool) const override
|
||||
{
|
||||
jassert (hasScanned); // need to call scanForDevices() before doing this
|
||||
|
||||
|
|
@ -1489,8 +1451,8 @@ public:
|
|||
|
||||
static int findFreeSlot()
|
||||
{
|
||||
for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
|
||||
if (currentASIODev[i] == 0)
|
||||
for (int i = 0; i < maxNumASIODevices; ++i)
|
||||
if (currentASIODev[i] == nullptr)
|
||||
return i;
|
||||
|
||||
jassertfalse; // unfortunately you can only have a finite number
|
||||
|
|
@ -1498,29 +1460,29 @@ public:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int getIndexOfDevice (AudioIODevice* d, bool /*asInput*/) const
|
||||
int getIndexOfDevice (AudioIODevice* d, bool /*asInput*/) const override
|
||||
{
|
||||
jassert (hasScanned); // need to call scanForDevices() before doing this
|
||||
|
||||
return d == nullptr ? -1 : deviceNames.indexOf (d->getName());
|
||||
}
|
||||
|
||||
bool hasSeparateInputsAndOutputs() const { return false; }
|
||||
bool hasSeparateInputsAndOutputs() const override { return false; }
|
||||
|
||||
AudioIODevice* createDevice (const String& outputDeviceName,
|
||||
const String& inputDeviceName)
|
||||
const String& inputDeviceName) override
|
||||
{
|
||||
// ASIO can't open two different devices for input and output - they must be the same one.
|
||||
jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
|
||||
jassert (hasScanned); // need to call scanForDevices() before doing this
|
||||
|
||||
const String deviceName (outputDeviceName.isNotEmpty() ? outputDeviceName
|
||||
: inputDeviceName);
|
||||
const int index = deviceNames.indexOf (deviceName);
|
||||
auto deviceName = outputDeviceName.isNotEmpty() ? outputDeviceName
|
||||
: inputDeviceName;
|
||||
auto index = deviceNames.indexOf (deviceName);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
const int freeSlot = findFreeSlot();
|
||||
auto freeSlot = findFreeSlot();
|
||||
|
||||
if (freeSlot >= 0)
|
||||
return new ASIOAudioIODevice (this, deviceName,
|
||||
|
|
@ -1552,7 +1514,7 @@ private:
|
|||
if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
|
||||
{
|
||||
int index = 0;
|
||||
TCHAR name [512];
|
||||
TCHAR name[512] = {};
|
||||
|
||||
while (RegEnumKey (hk, index++, name, numElementsInArray (name)) == ERROR_SUCCESS)
|
||||
{
|
||||
|
|
@ -1564,7 +1526,7 @@ private:
|
|||
{
|
||||
if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
|
||||
{
|
||||
TCHAR pathName [1024] = { 0 };
|
||||
TCHAR pathName[1024] = {};
|
||||
DWORD dtype = REG_SZ;
|
||||
DWORD dsize = sizeof (pathName);
|
||||
|
||||
|
|
@ -1596,7 +1558,7 @@ private:
|
|||
|
||||
if (RegOpenKeyEx (hk, keyName.toWideCharPointer(), 0, KEY_READ, &subKey) == ERROR_SUCCESS)
|
||||
{
|
||||
TCHAR buf [256] = { 0 };
|
||||
TCHAR buf[256] = {};
|
||||
DWORD dtype = REG_SZ;
|
||||
DWORD dsize = sizeof (buf);
|
||||
|
||||
|
|
@ -1605,6 +1567,7 @@ private:
|
|||
if (dsize > 0 && checkClassIsOk (buf))
|
||||
{
|
||||
CLSID classId;
|
||||
|
||||
if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
|
||||
{
|
||||
dtype = REG_SZ;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue