X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=resampling_queue.cpp;h=06dc6fbf417bb1a13aae39f4cbf527e7740e5b6f;hb=327534a3031a332423411c9599c741f2f81657df;hp=24811ebe5bbab43fa7cd68471c4ca69f82e673e8;hpb=d7257bb375432fe87f082876be995742f4891aa4;p=nageru diff --git a/resampling_queue.cpp b/resampling_queue.cpp index 24811eb..06dc6fb 100644 --- a/resampling_queue.cpp +++ b/resampling_queue.cpp @@ -49,6 +49,8 @@ void ResamplingQueue::add_input_samples(steady_clock::time_point ts, const float return; } + assert(duration(ts.time_since_epoch()).count() >= 0.0); + bool good_sample = (rate_adjustment_policy == ADJUST_RATE); if (good_sample && a1.good_sample) { a0 = a1; @@ -88,6 +90,12 @@ bool ResamplingQueue::get_output_samples(steady_clock::time_point ts, float *sam // good point. Note that we could be extrapolating backward or // forward, depending on the timing of the calls. const InputPoint &base_point = a1.good_sample ? a1 : a0; + assert(duration(base_point.ts.time_since_epoch()).count() >= 0.0); + + // NOTE: Due to extrapolation, input_samples_received can + // actually go negative here the few first calls (ie., we asked + // about a timestamp where we hadn't actually started producing + // samples yet), but that is harmless. const double input_samples_received = base_point.input_samples_received + current_estimated_freq_in * duration(ts - base_point.ts).count();