Author Topic: How do I get a list of supported sample rates of USB DAC?  (Read 166 times)

alerma

  • Posts: 16
Friends,

I searched the forum, but can't find an answer to my question. I know there is BASS_GetInfo() which can provide minrate and maxrate values, but those work only on Windows, and I am on Mac OS.
Is there any way to get a list of supported samples rates from a device, like:
44.1, 48, 88.2, 96, 176.4, 192, 352.8, 384 kHz?

Thanks

Ian @ un4seen

  • Administrator
  • Posts: 20396
It should be possible to get the device's available sample rates via the kAudioDevicePropertyAvailableNominalSampleRates property, something like this:

Code: [Select]
BASS_DEVICEINFO info;
BASS_GetDeviceInfo(device, &info); // get device info (can use BASS_GetDevice to get current device)
CFStringRef cs=CFStringCreateWithCString(0, info.driver, 0); // driver = device's UID
AudioDeviceID did;
AudioValueTranslation vt={&cs, sizeof(cs), &did, sizeof(did)};
UInt32 s=sizeof(vt);
AudioHardwareGetProperty(kAudioHardwarePropertyDeviceForUID, &s, &vt); // translate device's UID to AudioDeviceID
CFRelease(cs);
AudioObjectPropertyAddress pa={kAudioDevicePropertyAvailableNominalSampleRates, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster};
AudioObjectGetPropertyDataSize(did, &pa, 0, NULL, &s); // get size of available sample rates array
AudioValueRange *vr=new AudioValueRange[s/sizeof(AudioValueRange)]; // allocate it
AudioObjectGetPropertyData(did, &pa, 0, NULL, &z, vr); // get the available sample rates
for (int a=0; a<s/sizeof(AudioValueRange); a++)
printf("%g - %g\n", vr.mMinimum, vr.mMaximum);
delete[] vr;

The "mMinimum" and "mMaximum" values will usually be the same from what I've seen.

If that isn't giving you the correct rates for your device, check what OSX's Audio MIDI Setup app says.