thestk / rtaudio

A set of C++ classes that provide a common API for realtime audio input/output across Linux (native ALSA, JACK, PulseAudio and OSS), Macintosh OS X (CoreAudio and JACK), and Windows (DirectSound, ASIO, and WASAPI) operating systems.
Other
1.49k stars 317 forks source link

MacOS: Bluetooth devices change channel count during usage. #394

Open knell opened 1 year ago

knell commented 1 year ago

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:

image

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.

garyscavone commented 1 year ago

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.