mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
CoreAudio: Refactoring
This commit is contained in:
parent
9f99f02eb2
commit
f9b6e2ef69
1 changed files with 27 additions and 30 deletions
|
|
@ -460,8 +460,8 @@ public:
|
||||||
auto newBufferSizes = getBufferSizesFromDevice();
|
auto newBufferSizes = getBufferSizesFromDevice();
|
||||||
auto newSampleRates = getSampleRatesFromDevice();
|
auto newSampleRates = getSampleRatesFromDevice();
|
||||||
|
|
||||||
std::unique_ptr<Stream> newInput (inStream != nullptr ? new Stream (true, *this, activeIns) : nullptr);
|
auto newInput = rawToUniquePtr (inStream != nullptr ? new Stream (true, *this, activeIns) : nullptr);
|
||||||
std::unique_ptr<Stream> newOutput (outStream != nullptr ? new Stream (false, *this, activeOuts) : nullptr);
|
auto newOutput = rawToUniquePtr (outStream != nullptr ? new Stream (false, *this, activeOuts) : nullptr);
|
||||||
|
|
||||||
auto newBitDepth = jmax (getBitDepth (newInput), getBitDepth (newOutput));
|
auto newBitDepth = jmax (getBitDepth (newInput), getBitDepth (newOutput));
|
||||||
|
|
||||||
|
|
@ -616,8 +616,9 @@ public:
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
String reopen (const BigInteger& ins, const BigInteger& outs, double newSampleRate, int bufferSizeSamples)
|
String reopen (const BigInteger& ins, const BigInteger& outs, double newSampleRate, int bufferSizeSamples)
|
||||||
{
|
{
|
||||||
String error;
|
|
||||||
callbacksAllowed = false;
|
callbacksAllowed = false;
|
||||||
|
const ScopeGuard scope { [&] { callbacksAllowed = true; } };
|
||||||
|
|
||||||
stopTimer();
|
stopTimer();
|
||||||
|
|
||||||
stop (false);
|
stop (false);
|
||||||
|
|
@ -625,37 +626,33 @@ public:
|
||||||
if (! setNominalSampleRate (newSampleRate))
|
if (! setNominalSampleRate (newSampleRate))
|
||||||
{
|
{
|
||||||
updateDetailsFromDevice (ins, outs);
|
updateDetailsFromDevice (ins, outs);
|
||||||
error = "Couldn't change sample rate";
|
return "Couldn't change sample rate";
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (! audioObjectSetProperty (deviceID, { kAudioDevicePropertyBufferFrameSize,
|
||||||
|
kAudioObjectPropertyScopeGlobal,
|
||||||
|
juceAudioObjectPropertyElementMain },
|
||||||
|
static_cast<UInt32> (bufferSizeSamples), err2log()))
|
||||||
{
|
{
|
||||||
if (! audioObjectSetProperty (deviceID, { kAudioDevicePropertyBufferFrameSize,
|
updateDetailsFromDevice (ins, outs);
|
||||||
kAudioObjectPropertyScopeGlobal,
|
return "Couldn't change buffer size";
|
||||||
juceAudioObjectPropertyElementMain },
|
|
||||||
static_cast<UInt32> (bufferSizeSamples), err2log()))
|
|
||||||
{
|
|
||||||
updateDetailsFromDevice (ins, outs);
|
|
||||||
error = "Couldn't change buffer size";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Annoyingly, after changing the rate and buffer size, some devices fail to
|
|
||||||
// correctly report their new settings until some random time in the future, so
|
|
||||||
// after calling updateDetailsFromDevice, we need to manually bodge these values
|
|
||||||
// to make sure we're using the correct numbers..
|
|
||||||
updateDetailsFromDevice (ins, outs);
|
|
||||||
sampleRate = newSampleRate;
|
|
||||||
bufferSize = bufferSizeSamples;
|
|
||||||
|
|
||||||
if (sampleRates.size() == 0)
|
|
||||||
error = "Device has no available sample-rates";
|
|
||||||
else if (bufferSizes.size() == 0)
|
|
||||||
error = "Device has no available buffer-sizes";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callbacksAllowed = true;
|
// Annoyingly, after changing the rate and buffer size, some devices fail to
|
||||||
return error;
|
// correctly report their new settings until some random time in the future, so
|
||||||
|
// after calling updateDetailsFromDevice, we need to manually bodge these values
|
||||||
|
// to make sure we're using the correct numbers..
|
||||||
|
updateDetailsFromDevice (ins, outs);
|
||||||
|
sampleRate = newSampleRate;
|
||||||
|
bufferSize = bufferSizeSamples;
|
||||||
|
|
||||||
|
if (sampleRates.size() == 0)
|
||||||
|
return "Device has no available sample-rates";
|
||||||
|
|
||||||
|
if (bufferSizes.size() == 0)
|
||||||
|
return "Device has no available buffer-sizes";
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool start (AudioIODeviceCallback* callbackToNotify)
|
bool start (AudioIODeviceCallback* callbackToNotify)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue