1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

WASAPI: Use more early returns

This commit is contained in:
reuk 2025-06-02 15:03:55 +01:00
parent b20df8d713
commit 86e0248f79
No known key found for this signature in database

View file

@ -465,9 +465,9 @@ public:
client = createClient();
if (client != nullptr
&& tryInitialisingWithBufferSize (bufferSizeSamples))
{
if (client == nullptr || ! tryInitialisingWithBufferSize (bufferSizeSamples))
return false;
sampleRateHasChanged = false;
shouldShutdown = false;
@ -487,9 +487,6 @@ public:
return check (client->SetEventHandle (clientEvent));
}
return false;
}
void closeClient()
{
if (client != nullptr)
@ -606,12 +603,12 @@ private:
client->GetService (__uuidof (IAudioSessionControl),
(void**) audioSessionControl.resetAndGetPointerAddress());
if (audioSessionControl != nullptr)
{
if (audioSessionControl == nullptr)
return;
sessionEventCallback = becomeComSmartPtrOwner (new SessionEventCallback (*this));
audioSessionControl->RegisterAudioSessionNotification (sessionEventCallback);
}
}
void deleteSessionEventCallback()
{
@ -670,9 +667,10 @@ private:
lowLatencyBufferSizeMultiple = (int) fundamentalPeriod;
}
}
return;
}
else
{
REFERENCE_TIME defaultPeriod, minPeriod;
if (! check (audioClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
@ -681,7 +679,6 @@ private:
minBufferSize = refTimeToSamples (minPeriod, defaultSampleRate);
defaultBufferSize = refTimeToSamples (defaultPeriod, defaultSampleRate);
}
}
void querySupportedSampleRates (WAVEFORMATEXTENSIBLE format, ComSmartPtr<IAudioClient>& audioClient)
{
@ -894,13 +891,17 @@ private:
bool tryInitialisingWithBufferSize (int bufferSizeSamples)
{
if (auto format = findSupportedFormat (client, numChannels, sampleRate))
{
auto format = findSupportedFormat (client, numChannels, sampleRate);
if (! format.has_value())
return false;
auto isInitialised = isLowLatencyMode (deviceMode) ? initialiseLowLatencyClient (bufferSizeSamples, *format)
: initialiseStandardClient (bufferSizeSamples, *format);
if (isInitialised)
{
if (! isInitialised)
return false;
actualNumChannels = format->Format.nChannels;
const bool isFloat = format->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format->SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
bytesPerSample = format->Format.wBitsPerSample / 8;
@ -910,10 +911,6 @@ private:
return true;
}
}
return false;
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WASAPIDeviceBase)
};
@ -1310,9 +1307,11 @@ public:
StringArray getOutputChannelNames() override
{
if (outputDevice == nullptr)
return {};
StringArray outChannels;
if (outputDevice != nullptr)
for (int i = 1; i <= outputDevice->maxNumChannels; ++i)
outChannels.add ("Output channel " + String (i));
@ -1321,9 +1320,11 @@ public:
StringArray getInputChannelNames() override
{
if (inputDevice == nullptr)
return {};
StringArray inChannels;
if (inputDevice != nullptr)
for (int i = 1; i <= inputDevice->maxNumChannels; ++i)
inChannels.add ("Input channel " + String (i));
@ -1456,8 +1457,9 @@ public:
void start (AudioIODeviceCallback* call) override
{
if (isOpen_ && call != nullptr && ! isStarted)
{
if (! isOpen_ || call == nullptr || isStarted)
return;
if (! isThreadRunning())
{
// something's gone wrong and the thread's stopped..
@ -1471,12 +1473,12 @@ public:
callback = call;
isStarted = true;
}
}
void stop() override
{
if (isStarted)
{
if (! isStarted)
return;
auto* callbackLocal = callback;
{
@ -1487,7 +1489,6 @@ public:
if (callbackLocal != nullptr)
callbackLocal->audioDeviceStopped();
}
}
void setMMThreadPriority()
{
@ -1495,14 +1496,14 @@ public:
JUCE_LOAD_WINAPI_FUNCTION (dll, AvSetMmThreadCharacteristicsW, avSetMmThreadCharacteristics, HANDLE, (LPCWSTR, LPDWORD))
JUCE_LOAD_WINAPI_FUNCTION (dll, AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, (HANDLE, AVRT_PRIORITY))
if (avSetMmThreadCharacteristics != nullptr && avSetMmThreadPriority != nullptr)
{
if (avSetMmThreadCharacteristics == nullptr || avSetMmThreadPriority == nullptr)
return;
DWORD dummy = 0;
if (auto h = avSetMmThreadCharacteristics (L"Pro Audio", &dummy))
avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
}
}
void run() override
{