X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=resampling_queue.cpp;h=ef7b73511ff596f7e93894fd703038ad370c8841;hb=e5a0d3dfb676087bdcef4c82876234782e46604c;hp=06dc6fbf417bb1a13aae39f4cbf527e7740e5b6f;hpb=d517937bac393a7e62b709824bac9909705c2c51;p=nageru diff --git a/resampling_queue.cpp b/resampling_queue.cpp index 06dc6fb..ef7b735 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) { @@ -60,7 +60,11 @@ void ResamplingQueue::add_input_samples(steady_clock::time_point ts, const float a1.good_sample = good_sample; if (a0.good_sample && a1.good_sample) { current_estimated_freq_in = (a1.input_samples_received - a0.input_samples_received) / duration(a1.ts - a0.ts).count(); - assert(current_estimated_freq_in >= 0.0); + if (!(current_estimated_freq_in >= 0.0)) { + fprintf(stderr, "%s: PANIC: Input audio clock going backwards, ignoring.\n", + spec_to_string(device_spec).c_str()); + current_estimated_freq_in = freq_in; + } // Bound the frequency, so that a single wild result won't throw the filter off guard. current_estimated_freq_in = min(current_estimated_freq_in, 1.2 * freq_in); @@ -165,8 +169,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.