X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fresampling_queue.cpp;h=045d5c7b0f28460db1700e47b10aff339bbbed66;hb=ecaec75dd52d076ba53cafa1fed716ebc0d93da6;hp=ef7b73511ff596f7e93894fd703038ad370c8841;hpb=9b7d691b4cc5db7dbfc18c82e86c1207fcac4722;p=nageru diff --git a/nageru/resampling_queue.cpp b/nageru/resampling_queue.cpp index ef7b735..045d5c7 100644 --- a/nageru/resampling_queue.cpp +++ b/nageru/resampling_queue.cpp @@ -30,8 +30,8 @@ using namespace std; using namespace std::chrono; -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), +ResamplingQueue::ResamplingQueue(const std::string &debug_description, unsigned freq_in, unsigned freq_out, unsigned num_channels, double expected_delay_seconds) + : debug_description(debug_description), 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) { @@ -62,7 +62,7 @@ void ResamplingQueue::add_input_samples(steady_clock::time_point ts, const float current_estimated_freq_in = (a1.input_samples_received - a0.input_samples_received) / duration(a1.ts - a0.ts).count(); 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()); + debug_description.c_str()); current_estimated_freq_in = freq_in; } @@ -115,7 +115,7 @@ bool ResamplingQueue::get_output_samples(steady_clock::time_point ts, float *sam // so that we don't need a long period to stabilize at the beginning. if (err < 0.0) { int delay_samples_to_add = lrintf(-err); - for (ssize_t i = 0; i < delay_samples_to_add * num_channels; ++i) { + for (ssize_t i = 0; i < delay_samples_to_add * int(num_channels); ++i) { buffer.push_front(0.0f); } total_consumed_samples -= delay_samples_to_add; // Equivalent to increasing input_samples_received on a0 and a1. @@ -143,7 +143,7 @@ bool ResamplingQueue::get_output_samples(steady_clock::time_point ts, float *sam // (we start ResamplingQueues also when we e.g. switch sound sources), // but in general, a little bit of increased timing jitter is acceptable // right after a setup change like this. - double loop_bandwidth_hz = (total_consumed_samples < 4 * freq_in) ? 0.2 : 0.02; + double loop_bandwidth_hz = (total_consumed_samples < 4 * int(freq_in)) ? 0.2 : 0.02; // Set filters. The first filter much wider than the first one (20x as wide). double w = (2.0 * M_PI) * loop_bandwidth_hz * num_samples / freq_out; @@ -170,7 +170,7 @@ bool ResamplingQueue::get_output_samples(steady_clock::time_point ts, float *sam // This should never happen unless delay is set way too low, // or we're dropping a lot of data. 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); + debug_description.c_str(), int(vresampler.out_count), rcorr); memset(vresampler.out_data, 0, vresampler.out_count * num_channels * sizeof(float)); // Reset the loop filter.