]> git.sesse.net Git - nageru/blobdiff - nageru/resampling_queue.h
Make it possible to adjust the delay without resetting the resampler.
[nageru] / nageru / resampling_queue.h
index f0e2499cbf3300e9b4340430b85bf33f25862006..6288415a8cae453bcf55fbf233b86f65384de0d0 100644 (file)
@@ -63,6 +63,11 @@ public:
        void add_input_samples(std::chrono::steady_clock::time_point ts, const float *samples, ssize_t num_samples, RateAdjustmentPolicy rate_adjustment_policy);
        // Returns false if underrun.
        bool get_output_samples(std::chrono::steady_clock::time_point ts, float *samples, ssize_t num_samples, RateAdjustmentPolicy rate_adjustment_policy);
+       // Instantly change delay by removing samples, or adding zeros.
+       // Does not correct a queue that is in bad shape; e.g., if you change
+       // delay from 100 to 110 ms but your queue had a real delay of 200 ms,
+       // 10 ms worth of zeros will be inserted nevertheless.
+       void change_expected_delay(double expected_delay_seconds);
 
 private:
        void init_loop_filter(double bandwidth_hz);
@@ -89,6 +94,9 @@ private:
        };
        InputPoint a0, a1;
 
+       // If nonzero, how many samples we've added or removed as part of change_expected_delay().
+       int adjustment_samples = 0;
+
        // The current rate at which we seem to get input samples, in Hz.
        // For an ideal input, identical to freq_in.
        double current_estimated_freq_in;
@@ -108,7 +116,7 @@ private:
        // How much delay we are expected to have, in input samples.
        // If actual delay drifts too much away from this, we will start
        // changing the resampling ratio to compensate.
-       const double expected_delay;
+       double expected_delay;
 
        // Input samples not yet fed into the resampler.
        // TODO: Use a circular buffer instead, for efficiency.