This would happen if we stared asking for samples before the first insert,
causing the correction factor to become NaN and everything to go south.
This would also seemingly eventually cause panic messages when we believed we
were out of data in the same queue.
#include "resampling_queue.h"
#include "resampling_queue.h"
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <math.h>
#include <stddef.h>
#include <stdio.h>
void ResamplingQueue::add_input_samples(double pts, const float *samples, ssize_t num_samples)
{
void ResamplingQueue::add_input_samples(double pts, const float *samples, ssize_t num_samples)
{
+ if (num_samples == 0) {
+ return;
+ }
if (first_input) {
// Synthesize a fake length.
last_input_len = double(num_samples) / freq_in;
if (first_input) {
// Synthesize a fake length.
last_input_len = double(num_samples) / freq_in;
bool ResamplingQueue::get_output_samples(double pts, float *samples, ssize_t num_samples)
{
bool ResamplingQueue::get_output_samples(double pts, float *samples, ssize_t num_samples)
{
+ if (first_input) {
+ // No data yet, just return zeros.
+ memset(samples, 0, num_samples * 2 * sizeof(float));
+ return true;
+ }
+
double last_output_len;
if (first_output) {
// Synthesize a fake length.
double last_output_len;
if (first_output) {
// Synthesize a fake length.
// Using the time point since just before the last call to add_input_samples() as a base,
// estimate actual delay based on activity since then, measured in number of input samples:
double actual_delay = 0.0;
// Using the time point since just before the last call to add_input_samples() as a base,
// estimate actual delay based on activity since then, measured in number of input samples:
double actual_delay = 0.0;
+ assert(last_input_len != 0);
actual_delay += (k_a1 - k_a0) * last_output_len / last_input_len; // Inserted samples since k_a0, rescaled for the different time periods.
actual_delay += k_a0 - total_consumed_samples; // Samples inserted before k_a0 but not consumed yet.
actual_delay += vresampler.inpdist(); // Delay in the resampler itself.
actual_delay += (k_a1 - k_a0) * last_output_len / last_input_len; // Inserted samples since k_a0, rescaled for the different time periods.
actual_delay += k_a0 - total_consumed_samples; // Samples inserted before k_a0 but not consumed yet.
actual_delay += vresampler.inpdist(); // Delay in the resampler itself.
double rcorr = 1.0 - z2 - z3;
if (rcorr > 1.05) rcorr = 1.05;
if (rcorr < 0.95) rcorr = 0.95;
double rcorr = 1.0 - z2 - z3;
if (rcorr > 1.05) rcorr = 1.05;
if (rcorr < 0.95) rcorr = 0.95;
vresampler.set_rratio(rcorr);
// Finally actually resample, consuming exactly <num_samples> output samples.
vresampler.set_rratio(rcorr);
// Finally actually resample, consuming exactly <num_samples> output samples.