Skip to content

Commit

Permalink
Ensure we're flushing out our output FIFO if we stop receiving input.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Dec 3, 2024
1 parent 04504b7 commit a390463
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/pipeline/ResampleStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ResampleStep::ResampleStep(int inputSampleRate, int outputSampleRate)
soxr_runtime_spec_t runtimeSpec = soxr_runtime_spec(1);

qualSpec.passband_end = 0.912; // experimentally determined to reduce latency to acceptable levels (default 0.913)

resampleState_ = soxr_create(
inputSampleRate_,
outputSampleRate_,
Expand Down Expand Up @@ -77,7 +77,7 @@ std::shared_ptr<short> ResampleStep::execute(std::shared_ptr<short> inputSamples
if (numInputSamples > 0)
{
short outputBuffer[std::max(inputSampleRate_, outputSampleRate_)];
int expectedNumOutputSamples = (double)numInputSamples * ((double)outputSampleRate_ / (double)inputSampleRate_);
int expectedNumOutputSamples = (double)numInputSamples * ((double)outputSampleRate_ / (double)inputSampleRate_) + 0.5;
size_t inputUsed = 0;
size_t outputUsed = 0;
soxr_process(
Expand All @@ -101,6 +101,15 @@ std::shared_ptr<short> ResampleStep::execute(std::shared_ptr<short> inputSamples
*numOutputSamples = expectedNumOutputSamples;
}
}
else if (codec2_fifo_used(outputFifo_) > 0)
{
// If we have anything in our output FIFO, go ahead and send that over now.
*numOutputSamples = codec2_fifo_used(outputFifo_);
outputSamples = new short[*numOutputSamples];
assert(outputSamples != nullptr);

codec2_fifo_read(outputFifo_, outputSamples, *numOutputSamples);
}

return std::shared_ptr<short>(outputSamples, std::default_delete<short[]>());
}

0 comments on commit a390463

Please sign in to comment.