diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-07-25 16:29:49 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-07-26 11:39:59 +0200 |
| commit | 98b7a493933a5a47c6e1abb21ef2710ad2730a0e (patch) | |
| tree | 840ec2ca3fd693e052207b971d54e080318c71a7 | |
| parent | 349b0ca2ef8ab16d95d57d121960480ecce0cb7f (diff) | |
Add AudioBackend::device_output_channels().
| -rw-r--r-- | src/wx/audio_backend.cc | 30 | ||||
| -rw-r--r-- | src/wx/audio_backend.h | 2 | ||||
| -rw-r--r-- | src/wx/config_dialog.cc | 23 |
3 files changed, 33 insertions, 22 deletions
diff --git a/src/wx/audio_backend.cc b/src/wx/audio_backend.cc index 3cb2b8d4f..9c8b1c386 100644 --- a/src/wx/audio_backend.cc +++ b/src/wx/audio_backend.cc @@ -24,6 +24,9 @@ using std::string; using std::vector; +using boost::optional; + + AudioBackend* AudioBackend::_instance = nullptr; @@ -122,6 +125,33 @@ AudioBackend::default_device_name() } +optional<int> +AudioBackend::device_output_channels(string name) +{ +#if (RTAUDIO_VERSION_MAJOR >= 6) + for (auto device_id: _rtaudio.getDeviceIds()) { + auto info = audio.getDeviceInfo(device_id); + if (info.name == name) { + return info.outputChannels; + } + } +#else + for (unsigned int i = 0; i < _rtaudio.getDeviceCount(); ++i) { + try { + auto info = _rtaudio.getDeviceInfo(i); + if (info.name == name) { + return info.outputChannels; + } + } catch (RtAudioError&) { + /* Never mind */ + } + } +#endif + + return {}; +} + + void AudioBackend::abort_stream_if_running() { diff --git a/src/wx/audio_backend.h b/src/wx/audio_backend.h index f2a44a5fb..aa4adf13c 100644 --- a/src/wx/audio_backend.h +++ b/src/wx/audio_backend.h @@ -41,6 +41,8 @@ public: std::vector<std::string> output_device_names(); boost::optional<std::string> default_device_name(); + boost::optional<int> device_output_channels(std::string name); + void abort_stream_if_running(); boost::optional<std::string> start_stream(); diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index d97eeecc5..12e914742 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -964,28 +964,7 @@ SoundPage::config_changed () apis[RtAudio::LINUX_OSS] = _("OSS"); apis[RtAudio::RTAUDIO_DUMMY] = _("Dummy"); - int channels = 0; - if (configured_so) { -#if (RTAUDIO_VERSION_MAJOR >= 6) - for (auto device_id: audio.getDeviceIds()) { - auto info = audio.getDeviceInfo(device_id); - if (info.name == *configured_so && info.outputChannels > 0) { - channels = info.outputChannels; - } - } -#else - for (unsigned int i = 0; i < audio.getDeviceCount(); ++i) { - try { - auto info = audio.getDeviceInfo(i); - if (info.name == *configured_so && info.outputChannels > 0) { - channels = info.outputChannels; - } - } catch (RtAudioError&) { - /* Never mind */ - } - } -#endif - } + int const channels = configured_so ? AudioBackend::instance()->device_output_channels(*configured_so).get_value_or(0) : 0; _sound_output_details->SetLabel ( wxString::Format(_("%d channels on %s"), channels, apis[audio.getCurrentApi()]) |
