AudioDeviceManager::getDefaultBufferSize sometimes wrong


#1

Hi Jules,

CoreAudioIODevice::getDefaultBufferSize gives an invalid answer when used on a device that does not allow a buffer size >= 512 : it always replies 512 for those . This happens for example when one uses JackOSX pseudo device, which accepts only one sample rate and one buffer size.

I suggest to change

[code] int getDefaultBufferSize()
{
for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
if (getBufferSizeSamples(i) >= 512)
return getBufferSizeSamples(i);

    return 512;
}

[/code]

with something like:

[code] int getDefaultBufferSize()
{
int best = 0;
for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
if (best == 0 || std::abs(getBufferSizeSamples(i) - 512) < std::abs(best - 512))
best = getBufferSizeSamples(i);

    return (best ? best : 512);
}

[/code]


#2

Good point, thanks! I’ll sort something out there…