X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=audio_mixer.h;h=5a36475b6c1d9122ffd1b4b6725b2db275bea6e7;hb=41c91a56e836c4e81fcee2f3728ca09c0cc2a7bd;hp=8e15f543d48ac7921a7da0b6e98a3855436167fc;hpb=35e2c9dbbd5899d6dd3b2f926f95eeba72d038ba;p=nageru diff --git a/audio_mixer.h b/audio_mixer.h index 8e15f54..5a36475 100644 --- a/audio_mixer.h +++ b/audio_mixer.h @@ -14,8 +14,10 @@ #include #include #include +#include #include #include +#include #include #include "bmusb/bmusb.h" @@ -29,6 +31,19 @@ namespace bmusb { struct AudioFormat; } // namespace bmusb +enum class InputSourceType { SILENCE, CAPTURE_CARD }; + +struct InputMapping { + struct Bus { + std::string name; + InputSourceType input_source_type; + unsigned input_source_index; + int source_channel[2] { -1, -1 }; // Left and right. -1 = none. + }; + + std::vector buses; +}; + class AudioMixer { public: AudioMixer(unsigned num_cards); @@ -42,7 +57,12 @@ public: // See comments inside get_output(). void set_current_loudness(double level_lufs) { loudness_lufs = level_lufs; } - void set_fader_volume(unsigned card_index, float level_db) { cards[card_index].fader_volume_db = level_db; } + void set_fader_volume(unsigned bus_index, float level_db) { fader_volume_db[bus_index] = level_db; } + std::vector get_names() const; + void set_name(unsigned card_index, const std::string &name); + + void set_input_mapping(const InputMapping &input_mapping); + InputMapping get_input_mapping() const; void set_locut_cutoff(float cutoff_hz) { @@ -150,15 +170,21 @@ public: } private: + void find_sample_src_from_capture_card(const std::vector *samples_card, unsigned card_index, int source_channel, const float **srcptr, unsigned *stride); + void reset_card_mutex_held(unsigned card_index); + unsigned num_cards; + mutable std::mutex audio_mutex; + struct CaptureCard { - std::mutex audio_mutex; - std::unique_ptr resampling_queue; // Under audio_mutex. - int64_t next_local_pts = 0; // Beginning of next frame, in TIMEBASE units. Under audio_mutex. - std::atomic fader_volume_db{0.0f}; + std::unique_ptr resampling_queue; + int64_t next_local_pts = 0; + std::string name; + // Which channels we consider interesting (ie., are part of some input_mapping). + std::set interesting_channels; }; - CaptureCard cards[MAX_CARDS]; + CaptureCard cards[MAX_CARDS]; // Under audio_mutex. StereoFilter locut; // Default cutoff 120 Hz, 24 dB/oct. std::atomic locut_cutoff_hz; @@ -184,6 +210,9 @@ private: 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. + + InputMapping input_mapping; // Under audio_mutex. + std::atomic fader_volume_db[MAX_BUSES] {{ 0.0f }}; }; #endif // !defined(_AUDIO_MIXER_H)