]> git.sesse.net Git - nageru/blobdiff - nageru/audio_mixer.h
Begin working on a delay analyzer.
[nageru] / nageru / audio_mixer.h
index 9dc5c89d9702666bd8f936e5096604196aead143..0beaf103ab08dcfcd03ecef99eaed32ff83292df 100644 (file)
@@ -6,7 +6,8 @@
 // processing them with effects (if desired), and then mixing them
 // all together into one final audio signal.
 //
-// All operations on AudioMixer (except destruction) are thread-safe.
+// All operations on AudioMixer, except destruction and set_delay_analyzer(),
+// are thread-safe.
 
 #include <assert.h>
 #include <stdint.h>
@@ -31,6 +32,7 @@
 #include "resampling_queue.h"
 #include "stereocompressor.h"
 
+class DelayAnalyzerInterface;
 class DeviceSpecProto;
 
 namespace bmusb {
@@ -41,7 +43,7 @@ struct AudioFormat;
 // Assumes little-endian and chunky, signed PCM throughout.
 std::vector<int32_t> convert_audio_to_fixed32(const uint8_t *data, unsigned num_samples, bmusb::AudioFormat audio_format, unsigned num_destination_channels);
 
-// Similar, except converts ot floating-point instead, and converts only one channel.
+// Similar, except converts to floating-point instead, and converts only one channel.
 void convert_audio_to_fp32(float *dst, size_t out_channel, size_t out_num_channels,
                            const uint8_t *src, size_t in_channel, bmusb::AudioFormat in_audio_format,
                            size_t num_samples);
@@ -82,10 +84,15 @@ public:
        bool get_mute(unsigned bus_index) const { return mute[bus_index]; }
        void set_mute(unsigned bus_index, bool muted) { mute[bus_index] = muted; }
 
-       // Note: This operation holds all ALSA devices (see ALSAPool::get_devices()).
-       // You will need to call set_input_mapping() to get the hold state correctly,
-       // or every card will be held forever.
-       std::map<DeviceSpec, DeviceInfo> get_devices();
+       enum HoldDevices {
+               HOLD_NO_DEVICES,
+
+               // Note: Holds all ALSA devices (see ALSAPool::get_devices()).
+               // You will need to call set_input_mapping() to get the hold state correctly,
+               // or every card will be held forever.
+               HOLD_ALSA_DEVICES
+       };
+       std::map<DeviceSpec, DeviceInfo> get_devices(HoldDevices hold_devices);
 
        // See comments on ALSAPool::get_card_state().
        ALSAPool::Device::State get_alsa_card_state(unsigned index)
@@ -321,6 +328,12 @@ public:
        BusSettings get_bus_settings(unsigned bus_index) const;
        void set_bus_settings(unsigned bus_index, const BusSettings &settings);
 
+       // Does not take ownership. Not thread-safe (so only call when the mixer is being created).
+       void set_delay_analyzer(DelayAnalyzerInterface *delay_analyzer)
+       {
+               this->delay_analyzer = delay_analyzer;
+       }
+
 private:
        struct AudioDevice {
                std::unique_ptr<ResamplingQueue> resampling_queue;
@@ -435,6 +448,8 @@ private:
                std::atomic<double> compressor_attenuation_db{0.0/0.0};
        };
        std::unique_ptr<BusMetrics[]> bus_metrics;  // One for each bus in <input_mapping>.
+
+       DelayAnalyzerInterface *delay_analyzer = nullptr;
 };
 
 extern AudioMixer *global_audio_mixer;