From 81962bdc30471f9230aef1233bedd2776064eb39 Mon Sep 17 00:00:00 2001 From: Sam Aaron Date: Mon, 3 Jun 2024 18:46:42 +0100 Subject: [PATCH] Boot - enable separate input/output audio cards to be specified in config --- app/config/user-examples/audio-settings.toml | 9 ++++++++ app/server/ruby/bin/daemon.rb | 24 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/config/user-examples/audio-settings.toml b/app/config/user-examples/audio-settings.toml index f6077c8fcc..adc695f068 100644 --- a/app/config/user-examples/audio-settings.toml +++ b/app/config/user-examples/audio-settings.toml @@ -92,7 +92,16 @@ # num_inputs = 16 # num_outputs = 16 +## =========================================== +## Advanced - separate input/output soundcards +## =========================================== +# +# Note that these will override the sound_card_name option above. +# Also, these sound cards must be set to the same sample rate and +# the name must exactly match the full name of the sound card. +# input_sound_card_name = "" +# output_sound_card_name = "" ## ==================== ## Server Audio options diff --git a/app/server/ruby/bin/daemon.rb b/app/server/ruby/bin/daemon.rb index 86a9be2927..2f903da02d 100755 --- a/app/server/ruby/bin/daemon.rb +++ b/app/server/ruby/bin/daemon.rb @@ -1092,6 +1092,8 @@ class ScsynthBooter < ProcessBooter OPTS_TOML_KEY_CONVERSION = { sound_card_name: "-H", + input_sound_card_name: "__HI__", + output_sound_card_name: "__HO__", sound_card_sample_rate: "-S", sound_card_buffer_size: "-Z", num_inputs: "-i", @@ -1147,11 +1149,29 @@ def initialize(ports, no_scsynth_inputs=false) Util.log "Unified Audio Settings toml hash: #{opts.inspect}" opts = scsynth_inputs_hash.merge(opts) Util.log "Combined Audio Settings toml hash with GUI scsynth inputs hash: #{opts.inspect}" - opts = merge_opts(toml_opts_hash, opts) + opts = merge_scsynth_opts(toml_opts_hash, opts) Util.log "Merged Audio Settings toml hash: #{opts.inspect}" @num_inputs = opts["-i"].to_i @num_outputs = opts["-o"].to_i + + sound_card_name = opts.delete("-H") + input_sound_card_name = opts.delete("__HI__") + output_sound_card_name = opts.delete("__HO__") args = opts.to_a.flatten + + # handle multiargs for soundcard input/output + if input_sound_card_name && output_sound_card_name + args << "-H" << input_sound_card_name << output_sound_card_name + elsif input_sound_card_name && sound_card_name + args << "-H" << input_sound_card_name << sound_card_name + elsif input_sound_card_name + args << "-H" << input_sound_card_name + elsif output_sound_card_output_name + args << "-H" << output_sound_card_name + elsif sound_card_name + args << "-H" << sound_card_name + end + cmd = Paths.scsynth_path case Util.os @@ -1344,7 +1364,7 @@ def unify_toml_opts_hash(toml_opts_hash) opts end - def merge_opts(toml_opts_hash, opts) + def merge_scsynth_opts(toml_opts_hash, opts) # extract scsynth opts override begin clobber_opts_a = Shellwords.split(toml_opts_hash.fetch(:scsynth_opts_override, ""))