X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=audio_mixer.h;h=75b468a120f7d1f39aa293009e9b76153ae4e9a3;hb=c015407a3953235df07a601baa6aa8e02ba7b561;hp=6e1d5a9458fbb1ef3d808d7cae162591a2ae878d;hpb=01181e6e22e5cfc9d0cb17231f2c1866cc53b04a;p=nageru diff --git a/audio_mixer.h b/audio_mixer.h index 6e1d5a9..75b468a 100644 --- a/audio_mixer.h +++ b/audio_mixer.h @@ -7,9 +7,6 @@ // all together into one final audio signal. // // All operations on AudioMixer (except destruction) are thread-safe. -// -// TODO: There might be more audio stuff that should be moved here -// from Mixer. #include #include @@ -19,11 +16,14 @@ #include #include #include +#include #include "alsa_input.h" #include "bmusb/bmusb.h" +#include "correlation_measurer.h" #include "db.h" #include "defs.h" +#include "ebu_r128_proc.h" #include "filter.h" #include "resampling_queue.h" #include "stereocompressor.h" @@ -77,6 +77,7 @@ public: AudioMixer(unsigned num_cards); ~AudioMixer(); void reset_resampler(DeviceSpec device_spec); + void reset_meters(); // Add audio (or silence) to the given device's queue. Can return false if // the lock wasn't successfully taken; if so, you should simply try again. @@ -88,9 +89,6 @@ public: std::vector get_output(double pts, unsigned num_samples, ResamplingQueue::RateAdjustmentPolicy rate_adjustment_policy); - // See comments inside get_output(). - void set_current_loudness(double level_lufs) { loudness_lufs = level_lufs; } - void set_fader_volume(unsigned bus_index, float level_db) { fader_volume_db[bus_index] = level_db; } std::map get_devices() const; void set_name(DeviceSpec device_spec, const std::string &name); @@ -203,6 +201,15 @@ public: return final_makeup_gain_auto; } + typedef std::function audio_level_callback_t; + void set_audio_level_callback(audio_level_callback_t callback) + { + audio_level_callback = callback; + } + private: struct AudioDevice { std::unique_ptr resampling_queue; @@ -221,6 +228,8 @@ private: void reset_resampler_mutex_held(DeviceSpec device_spec); void reset_alsa_mutex_held(DeviceSpec device_spec); std::map get_devices_mutex_held() const; + void update_meters(const std::vector &samples); + void send_audio_level_callback(); unsigned num_cards; @@ -245,8 +254,6 @@ private: 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. - std::atomic loudness_lufs{ref_level_lufs}; - StereoCompressor limiter; std::atomic limiter_threshold_dbfs{ref_level_dbfs + 4.0f}; // 4 dB. std::atomic limiter_enabled{true}; @@ -259,6 +266,13 @@ private: InputMapping input_mapping; // Under audio_mutex. std::atomic fader_volume_db[MAX_BUSES] {{ 0.0f }}; + + audio_level_callback_t audio_level_callback = nullptr; + 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 peak{0.0f}; }; #endif // !defined(_AUDIO_MIXER_H)