]> git.sesse.net Git - nageru/commitdiff
When the delay analyzer wants audio from an ALSA card, temporarily auto-enable captur... audio-delay
authorSteinar H. Gunderson <steinar+nageru@gunderson.no>
Sun, 11 Aug 2019 21:17:33 +0000 (23:17 +0200)
committerSteinar H. Gunderson <steinar+nageru@gunderson.no>
Sun, 25 Aug 2019 22:39:08 +0000 (00:39 +0200)
nageru/audio_mixer.cpp
nageru/audio_mixer.h
nageru/delay_analyzer.cpp

index e441aac19ff9bd1bb73c3c2b5a7094270ed0a31f..a04d204f21f0b765b5a6f8855d2c6c0c0f52f122 100644 (file)
@@ -1291,6 +1291,16 @@ InputMapping AudioMixer::get_input_mapping() const
        return input_mapping;
 }
 
+void AudioMixer::set_extra_devices(const set<DeviceSpec> &devices)
+{
+       lock_guard<timed_mutex> 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<timed_mutex> 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 {
index 2b9aa4b9f77d412dc9a6d93950f4596cfff7ad00..fac2fc92445420901ef084043356670d6a250bf7 100644 (file)
@@ -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<DeviceSpec> &devices);
+
        unsigned num_buses() const;
 
        void set_locut_cutoff(float cutoff_hz)
@@ -451,6 +454,13 @@ private:
        std::unique_ptr<BusMetrics[]> bus_metrics;  // One for each bus in <input_mapping>.
 
        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<DeviceSpec> extra_devices;
 };
 
 extern AudioMixer *global_audio_mixer;
index b3127c4630567db073871b7f1505218a1028999b..5ad72e0003e81c7f7a433d1be734ae304cd79fd2 100644 (file)
@@ -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<DeviceSpec> 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).");
 }