]> git.sesse.net Git - nageru/blobdiff - resampling_queue.cpp
Fix an issue where the mixer lagging too much behind CEF would cause us to display...
[nageru] / resampling_queue.cpp
index add0e50ac5bb7bcb065c012a8ba7845798917701..24811ebe5bbab43fa7cd68471c4ca69f82e673e8 100644 (file)
@@ -77,6 +77,11 @@ bool ResamplingQueue::get_output_samples(steady_clock::time_point ts, float *sam
                return true;
        }
 
+       // This can happen when we get dropped frames on the master card.
+       if (duration<double>(ts.time_since_epoch()).count() <= 0.0) {
+               rate_adjustment_policy = DO_NOT_ADJUST_RATE;
+       }
+
        if (rate_adjustment_policy == ADJUST_RATE && (a0.good_sample || a1.good_sample)) {
                // Estimate the current number of input samples produced at
                // this instant in time, by extrapolating from the last known
@@ -143,8 +148,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 <num_samples> output samples.
@@ -157,6 +160,10 @@ bool ResamplingQueue::get_output_samples(steady_clock::time_point ts, float *sam
                        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 * num_channels * sizeof(float));
+
+                       // Reset the loop filter.
+                       z1 = z2 = z3 = 0.0;
+
                        return false;
                }