X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=resampling_queue.h;h=339e41bc6c1c4b60de19dcac1df9ae3f24b7ee95;hb=d36667277c69bcb3f100aecc61e1d1dd0f2e5b9d;hp=e43e0ea073767e45b787b2d5c9913df36eb4b22e;hpb=c0bf9deb26205bf35758d49f587961f19bdb15b8;p=nageru diff --git a/resampling_queue.h b/resampling_queue.h index e43e0ea..339e41b 100644 --- a/resampling_queue.h +++ b/resampling_queue.h @@ -45,14 +45,25 @@ #include #include +#include "defs.h" + class ResamplingQueue { public: // card_num is for debugging outputs only. ResamplingQueue(unsigned card_num, unsigned freq_in, unsigned freq_out, unsigned num_channels = 2); + // If policy is DO_NOT_ADJUST_RATE, the resampling rate will not be changed. + // This is primarily useful if you have an extraordinary situation, such as + // dropped frames. + enum RateAdjustmentPolicy { + DO_NOT_ADJUST_RATE, + ADJUST_RATE + }; + // Note: pts is always in seconds. void add_input_samples(double pts, const float *samples, ssize_t num_samples); - bool get_output_samples(double pts, float *samples, ssize_t num_samples); // Returns false if underrun. + // Returns false if underrun. + bool get_output_samples(double pts, float *samples, ssize_t num_samples, RateAdjustmentPolicy rate_adjustment_policy); private: void init_loop_filter(double bandwidth_hz); @@ -83,7 +94,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. - double expected_delay = 4800.0; + double expected_delay = OUTPUT_FREQUENCY * 0.1; // 100 ms. // Input samples not yet fed into the resampler. // TODO: Use a circular buffer instead, for efficiency.