From 8f10b382758eebb37108aa5a31f1581b45408aeb Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 11 Aug 2015 12:52:03 +0200 Subject: [PATCH] coreaudio backend: SR/BS query for separate devices --- libs/backends/coreaudio/coreaudio_backend.cc | 58 ++++++++++++++------ libs/backends/coreaudio/coreaudio_backend.h | 2 + 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/libs/backends/coreaudio/coreaudio_backend.cc b/libs/backends/coreaudio/coreaudio_backend.cc index 1eb55ca61e..732c83c41a 100644 --- a/libs/backends/coreaudio/coreaudio_backend.cc +++ b/libs/backends/coreaudio/coreaudio_backend.cc @@ -211,51 +211,68 @@ CoreAudioBackend::enumerate_output_devices () const } std::vector -CoreAudioBackend::available_sample_rates (const std::string&) const +CoreAudioBackend::available_sample_rates (const std::string& device) const +{ + std::vector sr; + _pcmio->available_sample_rates (name_to_id (device), sr); + return sr; +} + +std::vector +CoreAudioBackend::available_sample_rates (const std::string& input_device, const std::string& output_device) const { std::vector sr; std::vector sr_in; std::vector sr_out; - const uint32_t inp = name_to_id(_input_audio_device); - const uint32_t out = name_to_id(_output_audio_device); + const uint32_t inp = name_to_id (input_device); + const uint32_t out = name_to_id (output_device); + if (inp == UINT32_MAX && out == UINT32_MAX) { return sr; } else if (inp == UINT32_MAX) { - _pcmio->available_sample_rates(out, sr_out); + _pcmio->available_sample_rates (out, sr_out); return sr_out; } else if (out == UINT32_MAX) { - _pcmio->available_sample_rates(inp, sr_in); + _pcmio->available_sample_rates (inp, sr_in); return sr_in; } else { - _pcmio->available_sample_rates(inp, sr_in); - _pcmio->available_sample_rates(out, sr_out); + _pcmio->available_sample_rates (inp, sr_in); + _pcmio->available_sample_rates (out, sr_out); // TODO allow to use different SR per device, tweak aggregate - std::set_intersection(sr_in.begin(), sr_in.end(), sr_out.begin(), sr_out.end(), std::back_inserter(sr)); + std::set_intersection (sr_in.begin(), sr_in.end(), sr_out.begin(), sr_out.end(), std::back_inserter(sr)); return sr; } } std::vector -CoreAudioBackend::available_buffer_sizes (const std::string&) const +CoreAudioBackend::available_buffer_sizes (const std::string& device) const +{ + std::vector bs; + _pcmio->available_buffer_sizes (name_to_id (device), bs); + return bs; +} + +std::vector +CoreAudioBackend::available_buffer_sizes (const std::string& input_device, const std::string& output_device) const { std::vector bs; std::vector bs_in; std::vector bs_out; - const uint32_t inp = name_to_id(_input_audio_device); - const uint32_t out = name_to_id(_output_audio_device); + const uint32_t inp = name_to_id (input_device); + const uint32_t out = name_to_id (output_device); if (inp == UINT32_MAX && out == UINT32_MAX) { return bs; } else if (inp == UINT32_MAX) { - _pcmio->available_buffer_sizes(out, bs_out); + _pcmio->available_buffer_sizes (out, bs_out); return bs_out; } else if (out == UINT32_MAX) { - _pcmio->available_buffer_sizes(out, bs_in); + _pcmio->available_buffer_sizes (inp, bs_in); return bs_in; } else { - _pcmio->available_buffer_sizes(inp, bs_in); - _pcmio->available_buffer_sizes(out, bs_out); - std::set_intersection(bs_in.begin(), bs_in.end(), bs_out.begin(), bs_out.end(), std::back_inserter(bs)); + _pcmio->available_buffer_sizes (inp, bs_in); + _pcmio->available_buffer_sizes (out, bs_out); + std::set_intersection (bs_in.begin(), bs_in.end(), bs_out.begin(), bs_out.end(), std::back_inserter(bs)); return bs; } } @@ -315,7 +332,7 @@ CoreAudioBackend::set_output_device_name (const std::string& d) int CoreAudioBackend::set_sample_rate (float sr) { - std::vector srs = available_sample_rates (/* really ignored */_input_audio_device); + std::vector srs = available_sample_rates (_input_audio_device, _output_audio_device); if (std::find(srs.begin(), srs.end(), sr) == srs.end()) { return -1; } @@ -463,7 +480,12 @@ CoreAudioBackend::midi_option () const void CoreAudioBackend::launch_control_app () { - _pcmio->launch_control_app(name_to_id(_input_audio_device)); + if (name_to_id (_input_audio_device) != UINT32_MAX) { + _pcmio->launch_control_app(name_to_id(_input_audio_device)); + } + if (name_to_id (_output_audio_device) != UINT32_MAX) { + _pcmio->launch_control_app(name_to_id(_output_audio_device)); + } } /* State Control */ diff --git a/libs/backends/coreaudio/coreaudio_backend.h b/libs/backends/coreaudio/coreaudio_backend.h index 0d598f586a..82c451af9e 100644 --- a/libs/backends/coreaudio/coreaudio_backend.h +++ b/libs/backends/coreaudio/coreaudio_backend.h @@ -171,7 +171,9 @@ class CoreAudioBackend : public AudioBackend { std::vector enumerate_output_devices () const; std::vector available_sample_rates (const std::string& device) const; + std::vector available_sample_rates (const std::string&, const std::string&) const; std::vector available_buffer_sizes (const std::string& device) const; + std::vector available_buffer_sizes (const std::string&, const std::string&) const; uint32_t available_input_channel_count (const std::string& device) const; uint32_t available_output_channel_count (const std::string& device) const;