]> git.sesse.net Git - nageru/blobdiff - audio_mixer.cpp
Upgrade bmusb.
[nageru] / audio_mixer.cpp
index e4d95a49422250e44dced2a84f11dc866ac878f6..6a08f2167d62a434a1b31a7af160ff61a6378b3d 100644 (file)
@@ -184,7 +184,18 @@ AudioMixer::AudioMixer(unsigned num_cards)
        set_limiter_enabled(global_flags.limiter_enabled);
        set_final_makeup_gain_auto(global_flags.final_makeup_gain_auto);
 
+       r128.init(2, OUTPUT_FREQUENCY);
+       r128.integr_start();
+
+       // hlen=16 is pretty low quality, but we use quite a bit of CPU otherwise,
+       // and there's a limit to how important the peak meter is.
+       peak_resampler.setup(OUTPUT_FREQUENCY, OUTPUT_FREQUENCY * 4, /*num_channels=*/2, /*hlen=*/16, /*frel=*/1.0);
+
+       global_audio_mixer = this;
+       alsa_pool.init();
+
        if (!global_flags.input_mapping_filename.empty()) {
+               // Must happen after ALSAPool is initialized, as it needs to know the card list.
                current_mapping_mode = MappingMode::MULTICHANNEL;
                InputMapping new_input_mapping;
                if (!load_input_mapping_from_file(get_devices(),
@@ -201,16 +212,6 @@ AudioMixer::AudioMixer(unsigned num_cards)
                        current_mapping_mode = MappingMode::MULTICHANNEL;
                }
        }
-
-       r128.init(2, OUTPUT_FREQUENCY);
-       r128.integr_start();
-
-       // hlen=16 is pretty low quality, but we use quite a bit of CPU otherwise,
-       // and there's a limit to how important the peak meter is.
-       peak_resampler.setup(OUTPUT_FREQUENCY, OUTPUT_FREQUENCY * 4, /*num_channels=*/2, /*hlen=*/16, /*frel=*/1.0);
-
-       global_audio_mixer = this;
-       alsa_pool.init();
 }
 
 void AudioMixer::reset_resampler(DeviceSpec device_spec)
@@ -273,6 +274,12 @@ bool AudioMixer::add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned
                }
        }
 
+       // If we changed frequency since last frame, we'll need to reset the resampler.
+       if (audio_format.sample_rate != device->capture_frequency) {
+               device->capture_frequency = audio_format.sample_rate;
+               reset_resampler_mutex_held(device_spec);
+       }
+
        // Now add it.
        device->resampling_queue->add_input_samples(frame_time, audio.get(), num_samples, ResamplingQueue::ADJUST_RATE);
        return true;