1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-28 02:30:05 +00:00

Fix for CoreAudio initialisation of devices that can't handle sample rate change requests

This commit is contained in:
jules 2015-10-05 12:12:27 +01:00
parent b0ae8bd4b4
commit 14e5d9dad8

View file

@ -397,11 +397,9 @@ public:
if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, nullptr, &size, &isAlive)) && isAlive == 0)
return;
Float64 sr;
size = sizeof (sr);
pa.mSelector = kAudioDevicePropertyNominalSampleRate;
if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, nullptr, &size, &sr)))
sampleRate = sr;
const double currentRate = getNominalSampleRate();
if (currentRate > 0)
sampleRate = currentRate;
UInt32 framesPerBuf = (UInt32) bufferSize;
size = sizeof (framesPerBuf);
@ -525,6 +523,30 @@ public:
}
}
double getNominalSampleRate() const
{
AudioObjectPropertyAddress pa;
pa.mSelector = kAudioDevicePropertyNominalSampleRate;
pa.mScope = kAudioObjectPropertyScopeGlobal;
pa.mElement = kAudioObjectPropertyElementMaster;
Float64 sr = 0;
UInt32 size = (UInt32) sizeof (sr);
return OK (AudioObjectGetPropertyData (deviceID, &pa, 0, nullptr, &size, &sr)) ? (double) sr : 0.0;
}
bool setNominalSampleRate (double newSampleRate) const
{
if (std::abs (getNominalSampleRate() - newSampleRate) < 1.0)
return true;
AudioObjectPropertyAddress pa;
pa.mSelector = kAudioDevicePropertyNominalSampleRate;
pa.mScope = kAudioObjectPropertyScopeGlobal;
pa.mElement = kAudioObjectPropertyElementMaster;
Float64 sr = newSampleRate;
return OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr));
}
//==============================================================================
String reopen (const BigInteger& inputChannels,
const BigInteger& outputChannels,
@ -549,25 +571,23 @@ public:
numInputChans = activeInputChans.countNumberOfSetBits();
numOutputChans = activeOutputChans.countNumberOfSetBits();
// set sample rate
AudioObjectPropertyAddress pa;
pa.mSelector = kAudioDevicePropertyNominalSampleRate;
pa.mScope = kAudioObjectPropertyScopeGlobal;
pa.mElement = kAudioObjectPropertyElementMaster;
Float64 sr = newSampleRate;
if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
if (! setNominalSampleRate (newSampleRate))
{
updateDetailsFromDevice();
error = "Couldn't change sample rate";
}
else
{
// change buffer size
UInt32 framesPerBuf = (UInt32) bufferSizeSamples;
AudioObjectPropertyAddress pa;
pa.mSelector = kAudioDevicePropertyBufferFrameSize;
pa.mScope = kAudioObjectPropertyScopeGlobal;
pa.mElement = kAudioObjectPropertyElementMaster;
UInt32 framesPerBuf = (UInt32) bufferSizeSamples;
if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
{
updateDetailsFromDevice();
error = "Couldn't change buffer size";
}
else