]> git.sesse.net Git - nageru/blobdiff - mixer.h
Move most of the audio processing logic from Mixer into a new class, AudioMixer.
[nageru] / mixer.h
diff --git a/mixer.h b/mixer.h
index 75867ccce95b06d6ea79fdabe636c514fbcf5410..547691428ad5fcfe60f5f1720c5d4a36514e2fb2 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -24,6 +24,7 @@
 
 #include "bmusb/bmusb.h"
 #include "alsa_output.h"
+#include "audio_mixer.h"
 #include "ebu_r128_proc.h"
 #include "video_encoder.h"
 #include "httpd.h"
@@ -240,104 +241,8 @@ public:
                theme->set_wb(channel, r, g, b);
        }
 
-       void set_locut_cutoff(float cutoff_hz)
-       {
-               locut_cutoff_hz = cutoff_hz;
-       }
-
-       void set_locut_enabled(bool enabled)
-       {
-               locut_enabled = enabled;
-       }
-
-       bool get_locut_enabled() const
-       {
-               return locut_enabled;
-       }
-
-       float get_limiter_threshold_dbfs()
-       {
-               return limiter_threshold_dbfs;
-       }
-
-       float get_compressor_threshold_dbfs()
-       {
-               return compressor_threshold_dbfs;
-       }
-
-       void set_limiter_threshold_dbfs(float threshold_dbfs)
-       {
-               limiter_threshold_dbfs = threshold_dbfs;
-       }
-
-       void set_compressor_threshold_dbfs(float threshold_dbfs)
-       {
-               compressor_threshold_dbfs = threshold_dbfs;
-       }
-
-       void set_limiter_enabled(bool enabled)
-       {
-               limiter_enabled = enabled;
-       }
-
-       bool get_limiter_enabled() const
-       {
-               return limiter_enabled;
-       }
-
-       void set_compressor_enabled(bool enabled)
-       {
-               compressor_enabled = enabled;
-       }
-
-       bool get_compressor_enabled() const
-       {
-               return compressor_enabled;
-       }
-
-       void set_gain_staging_db(float gain_db)
-       {
-               std::unique_lock<std::mutex> lock(compressor_mutex);
-               level_compressor_enabled = false;
-               gain_staging_db = gain_db;
-       }
-
-       float get_gain_staging_db() const
-       {
-               std::unique_lock<std::mutex> lock(compressor_mutex);
-               return gain_staging_db;
-       }
-
-       void set_gain_staging_auto(bool enabled)
-       {
-               std::unique_lock<std::mutex> lock(compressor_mutex);
-               level_compressor_enabled = enabled;
-       }
-
-       bool get_gain_staging_auto() const
-       {
-               std::unique_lock<std::mutex> lock(compressor_mutex);
-               return level_compressor_enabled;
-       }
-
-       void set_final_makeup_gain_db(float gain_db)
-       {
-               std::unique_lock<std::mutex> lock(compressor_mutex);
-               final_makeup_gain_auto = false;
-               final_makeup_gain = pow(10.0f, gain_db / 20.0f);
-       }
-
-       void set_final_makeup_gain_auto(bool enabled)
-       {
-               std::unique_lock<std::mutex> lock(compressor_mutex);
-               final_makeup_gain_auto = enabled;
-       }
-
-       bool get_final_makeup_gain_auto() const
-       {
-               std::unique_lock<std::mutex> lock(compressor_mutex);
-               return final_makeup_gain_auto;
-       }
+       AudioMixer *get_audio_mixer() { return &audio_mixer; }
+       const AudioMixer *get_audio_mixer() const { return &audio_mixer; }
 
        void schedule_cut()
        {
@@ -418,7 +323,7 @@ private:
        void render_one_frame(int64_t duration);
        void send_audio_level_callback();
        void audio_thread_func();
-       void process_audio_one_frame(int64_t frame_pts_int, int num_samples, bool adjust_rate);
+       void process_audio_one_frame(int64_t frame_pts_int, int num_samples, ResamplingQueue::RateAdjustmentPolicy rate_adjustment_policy);
        void subsample_chroma(GLuint src_tex, GLuint dst_dst);
        void release_display_frame(DisplayFrame *frame);
        double pts() { return double(pts_int) / TIMEBASE; }
@@ -470,12 +375,10 @@ private:
                // frame rate is integer, will always stay zero.
                unsigned fractional_samples = 0;
 
-               std::mutex audio_mutex;
-               std::unique_ptr<ResamplingQueue> resampling_queue;  // Under audio_mutex.
                int last_timecode = -1;  // Unwrapped.
-               int64_t next_local_pts = 0;  // Beginning of next frame, in TIMEBASE units.
        };
        CaptureCard cards[MAX_CARDS];  // protected by <bmusb_mutex>
+       AudioMixer audio_mixer;
        void get_one_frame_from_each_card(unsigned master_card_index, CaptureCard::NewFrame new_frames[MAX_CARDS], bool has_new_frame[MAX_CARDS], int num_samples[MAX_CARDS]);
 
        InputState input_state;
@@ -519,35 +422,12 @@ private:
        std::atomic<bool> should_cut{false};
 
        audio_level_callback_t audio_level_callback = nullptr;
-       mutable std::mutex compressor_mutex;
-       Ebu_r128_proc r128;  // Under compressor_mutex.
-       CorrelationMeasurer correlation;  // Under compressor_mutex.
-
-       Resampler peak_resampler;
+       mutable std::mutex audio_measure_mutex;
+       Ebu_r128_proc r128;  // Under audio_measure_mutex.
+       CorrelationMeasurer correlation;  // Under audio_measure_mutex.
+       Resampler peak_resampler;  // Under audio_measure_mutex.
        std::atomic<float> peak{0.0f};
 
-       StereoFilter locut;  // Default cutoff 120 Hz, 24 dB/oct.
-       std::atomic<float> locut_cutoff_hz;
-       std::atomic<bool> locut_enabled{true};
-
-       // First compressor; takes us up to about -12 dBFS.
-       StereoCompressor level_compressor;  // Under compressor_mutex. Used to set/override gain_staging_db if <level_compressor_enabled>.
-       float gain_staging_db = 0.0f;  // Under compressor_mutex.
-       bool level_compressor_enabled = true;  // Under compressor_mutex.
-
-       static constexpr float ref_level_dbfs = -14.0f;  // Chosen so that we end up around 0 LU in practice.
-       static constexpr float ref_level_lufs = -23.0f;  // 0 LU, more or less by definition.
-
-       StereoCompressor limiter;
-       std::atomic<float> limiter_threshold_dbfs{ref_level_dbfs + 4.0f};   // 4 dB.
-       std::atomic<bool> limiter_enabled{true};
-       StereoCompressor compressor;
-       std::atomic<float> compressor_threshold_dbfs{ref_level_dbfs - 12.0f};  // -12 dB.
-       std::atomic<bool> compressor_enabled{true};
-
-       double final_makeup_gain = 1.0;  // Under compressor_mutex. Read/write by the user. Note: Not in dB, we want the numeric precision so that we can change it slowly.
-       bool final_makeup_gain_auto = true;  // Under compressor_mutex.
-
        std::unique_ptr<ALSAOutput> alsa;
 
        struct AudioTask {