@@ -31,6 +31,10 @@ class AudioSink : SinkManager::Sink {
3131 monoPacker.init (&s2m.out , 512 );
3232 stereoPacker.init (_stream->sinkOut , 512 );
3333
34+ #if RTAUDIO_VERSION_MAJOR >= 6
35+ audio.setErrorCallback (&errorCallback);
36+ #endif
37+
3438 bool created = false ;
3539 std::string device = " " ;
3640 config.acquire ();
@@ -42,21 +46,27 @@ class AudioSink : SinkManager::Sink {
4246 device = config.conf [_streamName][" device" ];
4347 config.release (created);
4448
45- int count = audio.getDeviceCount ();
4649 RtAudio::DeviceInfo info;
50+ #if RTAUDIO_VERSION_MAJOR >= 6
51+ for (int i : audio.getDeviceIds ()) {
52+ #else
53+ int count = audio.getDeviceCount ();
4754 for (int i = 0 ; i < count; i++) {
55+ #endif
4856 try {
4957 info = audio.getDeviceInfo (i);
58+ #if !defined(RTAUDIO_VERSION_MAJOR) || RTAUDIO_VERSION_MAJOR < 6
5059 if (!info.probed ) { continue ; }
60+ #endif
5161 if (info.outputChannels == 0 ) { continue ; }
5262 if (info.isDefaultOutput ) { defaultDevId = devList.size (); }
5363 devList.push_back (info);
5464 deviceIds.push_back (i);
5565 txtDevList += info.name ;
5666 txtDevList += ' \0 ' ;
5767 }
58- catch (std::exception e) {
59- flog::error (" AudioSinkModule Error getting audio device info: {0} " , e.what ());
68+ catch (const std::exception& e) {
69+ flog::error (" AudioSinkModule Error getting audio device ({}) info: {} " , i , e.what ());
6070 }
6171 }
6272 selectByName (device);
@@ -156,6 +166,22 @@ class AudioSink : SinkManager::Sink {
156166 }
157167 }
158168
169+ #if RTAUDIO_VERSION_MAJOR >= 6
170+ static void errorCallback (RtAudioErrorType type, const std::string& errorText) {
171+ switch (type) {
172+ case RtAudioErrorType::RTAUDIO_NO_ERROR:
173+ return ;
174+ case RtAudioErrorType::RTAUDIO_WARNING:
175+ case RtAudioErrorType::RTAUDIO_NO_DEVICES_FOUND:
176+ case RtAudioErrorType::RTAUDIO_DEVICE_DISCONNECT:
177+ flog::warn (" AudioSinkModule Warning: {} ({})" , errorText, (int )type);
178+ break ;
179+ default :
180+ throw std::runtime_error (errorText);
181+ }
182+ }
183+ #endif
184+
159185private:
160186 bool doStart () {
161187 RtAudio::StreamParameters parameters;
@@ -172,8 +198,8 @@ class AudioSink : SinkManager::Sink {
172198 audio.startStream ();
173199 stereoPacker.start ();
174200 }
175- catch (RtAudioError & e) {
176- flog::error (" Could not open audio device" );
201+ catch (const std::exception & e) {
202+ flog::error (" Could not open audio device {0} " , e. what () );
177203 return false ;
178204 }
179205
0 commit comments