X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=resampling_queue.cpp;h=a1a2395533ae168abf1efe2a737cf710a9722e0a;hb=4a0187ffb4075b4d217b8d9e9c96cac548b199d8;hp=7286d5cba535ebad5b757bc3ed1c2d2399d6d528;hpb=e0dd9e22b11a7e812b9ff708370426c564ac8005;p=nageru diff --git a/resampling_queue.cpp b/resampling_queue.cpp index 7286d5c..a1a2395 100644 --- a/resampling_queue.cpp +++ b/resampling_queue.cpp @@ -30,8 +30,8 @@ using namespace std; using namespace std::chrono; -ResamplingQueue::ResamplingQueue(unsigned card_num, unsigned freq_in, unsigned freq_out, unsigned num_channels, double expected_delay_seconds) - : card_num(card_num), freq_in(freq_in), freq_out(freq_out), num_channels(num_channels), +ResamplingQueue::ResamplingQueue(DeviceSpec device_spec, unsigned freq_in, unsigned freq_out, unsigned num_channels, double expected_delay_seconds) + : device_spec(device_spec), freq_in(freq_in), freq_out(freq_out), num_channels(num_channels), current_estimated_freq_in(freq_in), ratio(double(freq_out) / double(freq_in)), expected_delay(expected_delay_seconds * OUTPUT_FREQUENCY) { @@ -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(); @@ -148,8 +156,6 @@ bool ResamplingQueue::get_output_samples(steady_clock::time_point ts, float *sam if (rcorr < 0.95) rcorr = 0.95; assert(!isnan(rcorr)); vresampler.set_rratio(rcorr); - } else { - assert(rate_adjustment_policy == DO_NOT_ADJUST_RATE); } // Finally actually resample, producing exactly output samples. @@ -159,8 +165,8 @@ bool ResamplingQueue::get_output_samples(steady_clock::time_point ts, float *sam if (buffer.empty()) { // This should never happen unless delay is set way too low, // or we're dropping a lot of data. - fprintf(stderr, "Card %u: PANIC: Out of input samples to resample, still need %d output samples! (correction factor is %f)\n", - card_num, int(vresampler.out_count), rcorr); + fprintf(stderr, "%s: PANIC: Out of input samples to resample, still need %d output samples! (correction factor is %f)\n", + spec_to_string(device_spec).c_str(), int(vresampler.out_count), rcorr); memset(vresampler.out_data, 0, vresampler.out_count * num_channels * sizeof(float)); // Reset the loop filter.