]> git.sesse.net Git - nageru/blobdiff - resampling_queue.cpp
Initialize stats buffers in speed control correctly
[nageru] / resampling_queue.cpp
index ab20b410623b348d3fab0b6ff65753f128e1747e..62c4413792b2cdba4be07119d692173dc0fb7b7f 100644 (file)
@@ -26,8 +26,8 @@
 #include <string.h>
 #include <zita-resampler/vresampler.h>
 
-ResamplingQueue::ResamplingQueue(unsigned freq_in, unsigned freq_out, unsigned num_channels)
-       : freq_in(freq_in), freq_out(freq_out), num_channels(num_channels),
+ResamplingQueue::ResamplingQueue(unsigned card_num, unsigned freq_in, unsigned freq_out, unsigned num_channels)
+       : card_num(card_num), freq_in(freq_in), freq_out(freq_out), num_channels(num_channels),
          ratio(double(freq_out) / double(freq_in))
 {
        vresampler.setup(ratio, num_channels, /*hlen=*/32);
@@ -95,8 +95,8 @@ bool ResamplingQueue::get_output_samples(double pts, float *samples, ssize_t num
                }
                total_consumed_samples -= delay_samples_to_add;  // Equivalent to increasing k_a0 and k_a1.
                err += delay_samples_to_add;
-               first_output = false;
        }
+       first_output = false;
 
        // Compute loop filter coefficients for the two filters. We need to compute them
        // every time, since they depend on the number of samples the user asked for.
@@ -129,8 +129,8 @@ bool ResamplingQueue::get_output_samples(double pts, float *samples, ssize_t num
                if (buffer.empty()) {
                        // This should never happen unless delay is set way too low,
                        // or we're dropping a lot of data.
-                       fprintf(stderr, "PANIC: Out of input samples to resample, still need %d output samples!\n",
-                               int(vresampler.out_count));
+                       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);
                        memset(vresampler.out_data, 0, vresampler.out_count * 2 * sizeof(float));
                        return false;
                }
@@ -147,7 +147,8 @@ bool ResamplingQueue::get_output_samples(double pts, float *samples, ssize_t num
                vresampler.inp_count = num_input_samples;
                vresampler.inp_data = inbuf;
 
-               vresampler.process();
+               int err = vresampler.process();
+               assert(err == 0);
 
                size_t consumed_samples = num_input_samples - vresampler.inp_count;
                total_consumed_samples += consumed_samples;