Skip to content

Commit

Permalink
Make sure we don't accidentally overflow the output FIFO when transmi…
Browse files Browse the repository at this point in the history
…tting EOO.
  • Loading branch information
tmiw committed Dec 4, 2024
1 parent f8b647c commit e2a1e58
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmake/BuildRADE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ExternalProject_Add(build_rade
SOURCE_DIR rade_src
BINARY_DIR rade_build
GIT_REPOSITORY https://github.com/drowe67/radae.git
GIT_TAG dr-cport
GIT_TAG dr-timing-bug
CMAKE_ARGS ${RADE_CMAKE_ARGS}
#CMAKE_CACHE_ARGS -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
INSTALL_COMMAND ""
Expand Down
15 changes: 15 additions & 0 deletions src/pipeline/RADETransmitStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ std::shared_ptr<short> RADETransmitStep::execute(std::shared_ptr<short> inputSam
{
short* outputSamples = nullptr;
*numOutputSamples = 0;

if (numInputSamples == 0)
{
// Special case logic for EOO -- make sure we only send 20ms worth at a time
*numOutputSamples = std::min(codec2_fifo_used(outputSampleFifo_), (int)(8000*.02));
if (*numOutputSamples > 0)
{
outputSamples = new short[*numOutputSamples];
assert(outputSamples != nullptr);

codec2_fifo_read(outputSampleFifo_, outputSamples, *numOutputSamples);
}

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

short* inputPtr = inputSamples.get();
while (numInputSamples > 0 && inputPtr != nullptr)
Expand Down
27 changes: 14 additions & 13 deletions src/pipeline/TxRxThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,24 +651,25 @@ void TxRxThread::txProcessing_()
int nread = codec2_fifo_read(cbData->infifo2, insound_card, nsam_in_48);
if (nread != 0 && endingTx)
{
if (freedvInterface.getCurrentMode() >= FREEDV_MODE_RADE && !hasEooBeenSent_)
if (freedvInterface.getCurrentMode() >= FREEDV_MODE_RADE)
{
log_info("Triggering sending of EOO");

// Special case for handling RADE EOT
freedvInterface.restartTxVocoder();
hasEooBeenSent_ = true;
if (!hasEooBeenSent_)
{
log_info("Triggering sending of EOO");

// Special case for handling RADE EOT
freedvInterface.restartTxVocoder();
hasEooBeenSent_ = true;
}

short* inputSamples = new short[1];
auto inputSamplesPtr = std::shared_ptr<short>(inputSamples, std::default_delete<short[]>());
do
auto outputSamples = pipeline_->execute(inputSamplesPtr, 0, &nout);
if (nout > 0 && outputSamples.get() != nullptr)
{
auto outputSamples = pipeline_->execute(inputSamplesPtr, 0, &nout);
if (nout > 0 && outputSamples.get() != nullptr)
{
codec2_fifo_write(cbData->outfifo1, outputSamples.get(), nout);
}
} while (nout > 0);
log_info("Injecting %d samples of EOO into TX stream", nout);
codec2_fifo_write(cbData->outfifo1, outputSamples.get(), nout);
}
}
break;
}
Expand Down

0 comments on commit e2a1e58

Please sign in to comment.