Skip to content

Commit

Permalink
Add delays to make sure we don't process audio too quickly.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Sep 4, 2024
1 parent a23f62e commit 6f0c6eb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/pipeline/ExternVocoderStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,19 @@ int ExternVocoderStep::getOutputSampleRate() const

std::shared_ptr<short> ExternVocoderStep::execute(std::shared_ptr<short> inputSamples, int numInputSamples, int* numOutputSamples)
{
const int MAX_OUTPUT_SAMPLES = 1024;

*numOutputSamples = 0;
short* outputSamples = nullptr;

// Write input samples to thread for processing
if (numInputSamples > 0)
{
codec2_fifo_write(inputSampleFifo_, inputSamples.get(), numInputSamples);
#ifdef _WIN32
// XXX: simulate required processing time as actual I/O is handled
// by another thread. For some reason this is only needed on Windows.
int timeToSleep = (numInputSamples * 1000 / getInputSampleRate()) >> 2;
if (timeToSleep > 0) Sleep(timeToSleep);
#endif // _WIN32
}

// Read and return output samples from thread.
Expand Down

0 comments on commit 6f0c6eb

Please sign in to comment.