Skip to content

Commit

Permalink
Fix segfaults when transmitting through external vocoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Aug 17, 2024
1 parent c9e33a8 commit fd5928e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/freedv_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,16 @@ int FreeDVInterface::getTxSpeechSampleRate() const

int FreeDVInterface::getTxNumSpeechSamples() const
{
if (txMode_ == -1) return 1024;

assert(currentTxMode_ != nullptr);
return freedv_get_n_speech_samples(currentTxMode_);
}

int FreeDVInterface::getTxNNomModemSamples() const
{
if (txMode_ == -1) return 1024;

assert(currentTxMode_ != nullptr);
return freedv_get_n_nom_modem_samples(currentTxMode_);
}
Expand Down Expand Up @@ -603,6 +607,9 @@ IPipelineStep* FreeDVInterface::createTransmitPipeline(int inputSampleRate, int

std::function<int(ParallelStep*)> modeFn =
[&](ParallelStep*) {
// Special handling for external vocoder.
if (txMode_ == -1) return 0;

int index = 0;
for (auto& dv : dvObjects_)
{
Expand Down
5 changes: 4 additions & 1 deletion src/pipeline/ExternVocoderStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ std::shared_ptr<short> ExternVocoderStep::execute(std::shared_ptr<short> inputSa
short output_buf[samplesToRead];
short* inputPtr = inputSamples.get();

write(receiveStdinFd_, inputPtr, numInputSamples * sizeof(short));
if (numInputSamples > 0)
{
write(receiveStdinFd_, inputPtr, numInputSamples * sizeof(short));
}
*numOutputSamples = read(receiveStdoutFd_, output_buf, samplesToRead * sizeof(short));
if (*numOutputSamples == -1)
{
Expand Down

0 comments on commit fd5928e

Please sign in to comment.