From 5156378d4ad09d54791083e4067cf002e5431cb5 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 11 Aug 2019 23:17:33 +0200 Subject: [PATCH] When the delay analyzer wants audio from an ALSA card, temporarily auto-enable capture from it. --- nageru/audio_mixer.cpp | 12 +++++++++++- nageru/audio_mixer.h | 10 ++++++++++ nageru/delay_analyzer.cpp | 7 +++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/nageru/audio_mixer.cpp b/nageru/audio_mixer.cpp index e441aac..a04d204 100644 --- a/nageru/audio_mixer.cpp +++ b/nageru/audio_mixer.cpp @@ -1291,6 +1291,16 @@ InputMapping AudioMixer::get_input_mapping() const return input_mapping; } +void AudioMixer::set_extra_devices(const set &devices) +{ + lock_guard lock(audio_mutex); + extra_devices = devices; + for (unsigned card_index = 0; card_index < MAX_ALSA_CARDS; ++card_index) { + const DeviceSpec device_spec{InputSourceType::ALSA_INPUT, card_index}; + start_or_stop_alsa_capture(device_spec); + } +} + unsigned AudioMixer::num_buses() const { lock_guard lock(audio_mutex); @@ -1329,7 +1339,7 @@ void AudioMixer::start_or_stop_alsa_capture(DeviceSpec device_spec) assert(device_spec.type == InputSourceType::ALSA_INPUT); AudioDevice *device = find_audio_device(device_spec); bool previously_held = alsa_pool.device_is_held(device_spec.index); - bool should_be_held = !device->interesting_channels.empty(); + bool should_be_held = !device->interesting_channels.empty() || extra_devices.count(device_spec); if (should_be_held) { alsa_pool.hold_device(device_spec.index); } else { diff --git a/nageru/audio_mixer.h b/nageru/audio_mixer.h index 2b9aa4b..fac2fc9 100644 --- a/nageru/audio_mixer.h +++ b/nageru/audio_mixer.h @@ -136,6 +136,9 @@ public: MappingMode get_mapping_mode() const; InputMapping get_input_mapping() const; + // See extra_devices. + void set_extra_devices(const std::set &devices); + unsigned num_buses() const; void set_locut_cutoff(float cutoff_hz) @@ -451,6 +454,13 @@ private: std::unique_ptr bus_metrics; // One for each bus in . DelayAnalyzerInterface *delay_analyzer = nullptr; + + // A set of devices (potentially empty) that should be kept open even + // if they're not used in any bus. This allows the delay analyzer to + // make sure a given ALSA device is opened to tap into its data, even if + // there is no bus using it. (Non-ALSA devices are allowed to be here, + // but won't do anything.) + std::set extra_devices; }; extern AudioMixer *global_audio_mixer; diff --git a/nageru/delay_analyzer.cpp b/nageru/delay_analyzer.cpp index b3127c4..5ad72e0 100644 --- a/nageru/delay_analyzer.cpp +++ b/nageru/delay_analyzer.cpp @@ -59,6 +59,11 @@ void DelayAnalyzer::grab_clicked() ui->peak_display_2->reset_base(); ui->peak_display_1->audio_clip_updated(); ui->peak_display_2->audio_clip_updated(); + + set devices; + devices.insert(get_selected_device(ui->card_combo_1)); + devices.insert(get_selected_device(ui->card_combo_2)); + global_audio_mixer->set_extra_devices(devices); } void DelayAnalyzer::card_selected(QComboBox *card_combo, int selected_index) @@ -154,6 +159,7 @@ void DelayAnalyzer::add_audio(DeviceSpec device_spec, const uint8_t *data, unsig clip2.get_length_seconds_after_base(base) >= 1.0) { post_to_main_thread([this] { grab_timeout->stop(); + global_audio_mixer->set_extra_devices({}); // Put on another thread so that we don't get recursive locking. }); grabbing = false; @@ -184,5 +190,6 @@ void DelayAnalyzer::estimate_delay() void DelayAnalyzer::grab_timed_out() { grabbing = false; + global_audio_mixer->set_extra_devices({}); ui->delay_estimate_label->setText("Could not capture audio (timed out)."); } -- 2.39.2