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

Restricted sample rate changes for composite audio devices to common sample rates only

This commit is contained in:
tpoole 2017-02-14 15:48:20 +00:00
parent f1bbead360
commit 0b3e192567

View file

@ -1560,16 +1560,32 @@ private:
{
const ScopedLock sl (callbackLock);
currentSampleRate = device->getCurrentSampleRate();
bool sampleRateChanges = false;
auto newSampleRate = device->getCurrentSampleRate();
auto commonRates = getAvailableSampleRates();
if (! commonRates.contains (newSampleRate))
{
commonRates.sort();
if (newSampleRate < commonRates.getFirst() || newSampleRate > commonRates.getLast())
newSampleRate = jlimit (commonRates.getFirst(), commonRates.getLast(), newSampleRate);
else
for (auto it = commonRates.begin(); it < commonRates.end() - 1; ++it)
if (it[0] < newSampleRate && it[1] > newSampleRate)
{
newSampleRate = newSampleRate - it[0] < it[1] - newSampleRate ? it[0] : it[1];
break;
}
}
currentSampleRate = newSampleRate;
bool anySampleRateChanges = false;
for (int i = 0; i < devices.size(); ++i)
if (devices.getUnchecked(i)->getCurrentSampleRate() != currentSampleRate)
{
devices.getUnchecked(i)->setCurrentSampleRate (currentSampleRate);
sampleRateChanges = true;
anySampleRateChanges = true;
}
if (sampleRateChanges)
if (anySampleRateChanges)
owner.audioDeviceListChanged();
if (callback != nullptr)