MacOS: Bluetooth devices change channel count during usage.
knell opened this issue · 2 comments
Hey guys, I'm not sure is it a real issue or my mistake but the situation is the following.
I'm using #define RTAUDIO_VERSION "6.0.0beta1"
I have pretty straitforward code which enumerates the audio devices on start, like:
for (auto i = 0u; i < _dac->getDeviceCount(); i++)
{
const auto di = _dac->getDeviceInfo(i);
if (di.probed && di.outputChannels > 0)
{
vec.emplace_back(std::make_tuple(i, di.name));
}
}
next, I start playing incoming stream using the standard code:
const auto out_di = _dac->getDeviceInfo(_current_out_device);
out_params.deviceId = _current_out_device;
out_params.nChannels = 2;
out_params.firstChannel = 0;
if (ret = _dac->openStream(&out_params, nullptr, RTAUDIO_SINT16, sampleRate, &bufferFrames, cb, (void *)&uinfo, &opts);
ret != RtAudioErrorType::RTAUDIO_NO_ERROR)
{ /* ... */ }
if (ret = _dac->startStream(); ret != RtAudioErrorType::RTAUDIO_NO_ERROR)
{
if (_dac->isStreamOpen())
_dac->closeStream();
return false;
}
I'm using bluetooth Sony WH-1000XM3 on MacOS. Before the start the system shows me that the device is 2ch 48kHz, after start the device switches to the 1ch 48kHz after enumeration. When start the stream I have a pretty weird state then:
The RtAudio still thinks the we have 1ch 48kHz but in the system it's 1ch 16kHz and the sound is distorted. After I close the app the device gets back to 2ch 48kHz. The same situation is with AirPods, it changes channels count in runtime during using RtAudio. But after a couple of reconnecting of the device (on dis/connect I have a watcher wich makes the same procedure like enumerate and restart the stream) at somepoint it matches the proper channels/samplerate and sounds properly.
I would try with the version 6.0.0 beta1. From my own experience, AirPods run at 16 kHz and they are reported that way on my OS-X system.