Tweaks to new audio path code:

1. Move lambda usage for RX to member functions (adds readability and possibly fixes #250).
2. Use sync as well as SNR/squelch setting to determine whether to let audio through (reduces extra noise in speakers).
pull/246/head
Mooneer Salem 2022-07-01 16:21:21 -07:00
parent 5c05513e0f
commit d803330458
2 changed files with 140 additions and 99 deletions

View File

@ -26,6 +26,33 @@
#include "pipeline/FreeDVTransmitStep.h"
#include "pipeline/FreeDVReceiveStep.h"
using namespace std::placeholders;
static const char* GetCurrentModeStrImpl_(int mode)
{
switch(mode)
{
case FREEDV_MODE_700C:
return "700C";
case FREEDV_MODE_700D:
return "700D";
case FREEDV_MODE_700E:
return "700E";
case FREEDV_MODE_1600:
return "1600";
case FREEDV_MODE_2020:
return "2020";
case FREEDV_MODE_2020B:
return "2020B";
case FREEDV_MODE_800XA:
return "800XA";
case FREEDV_MODE_2400B:
return "2400B";
default:
return "unk";
}
}
FreeDVInterface::FreeDVInterface() :
textRxFunc_(nullptr),
singleRxThread_(false),
@ -588,7 +615,24 @@ IPipelineStep* FreeDVInterface::createReceivePipeline(
parallelSteps.push_back(recvStep);
}
auto preProcessFn = [&](ParallelStep* stepObj) {
state->preProcessFn = std::bind(&FreeDVInterface::preProcessRxFn_, this, _1);
state->postProcessFn = std::bind(&FreeDVInterface::postProcessRxFn_, this, _1);
auto parallelStep = new ParallelStep(
inputSampleRate,
outputSampleRate,
!singleRxThread_,
state->preProcessFn,
state->postProcessFn,
parallelSteps,
state
);
return parallelStep;
}
int FreeDVInterface::preProcessRxFn_(ParallelStep* stepObj)
{
int rxIndex = 0;
std::shared_ptr<ReceivePipelineState> state = std::static_pointer_cast<ReceivePipelineState>(stepObj->getState());
@ -616,7 +660,8 @@ IPipelineStep* FreeDVInterface::createReceivePipeline(
return -1;
};
auto postProcessFn = [&](ParallelStep* stepObj) {
int FreeDVInterface::postProcessRxFn_(ParallelStep* stepObj)
{
std::shared_ptr<ReceivePipelineState> state = std::static_pointer_cast<ReceivePipelineState>(stepObj->getState());
// If the current RX mode is still sync'd, only let that one out.
@ -648,7 +693,10 @@ IPipelineStep* FreeDVInterface::createReceivePipeline(
}
int snr = (int)(snrVals_[rxIndex]+0.5);
if (snr > maxSyncFound && tmpStats->sync != 0)
bool canUnsquelch = !squelchEnabled_ ||
(squelchEnabled_ && snr >= squelchVals_[rxIndex]);
if (snr > maxSyncFound && tmpStats->sync != 0 && canUnsquelch)
{
maxSyncFound = snr;
indexWithSync = rxIndex;
@ -685,16 +733,3 @@ skipSyncCheck:
return indexWithSync;
};
auto parallelStep = new ParallelStep(
inputSampleRate,
outputSampleRate,
!singleRxThread_,
preProcessFn,
postProcessFn,
parallelSteps,
state
);
return parallelStep;
}

View File

@ -40,6 +40,7 @@
#include <samplerate.h>
class IPipelineStep;
class ParallelStep;
class FreeDVInterface
{
@ -120,6 +121,8 @@ private:
std::function<int()> getChannelNoiseSnrFn;
std::function<float()> getFreqOffsetFn;
std::function<float*()> getSigPwrAvgFn;
std::function<int(ParallelStep*)> preProcessFn;
std::function<int(ParallelStep*)> postProcessFn;
};
struct FreeDVTextFnState
@ -161,6 +164,9 @@ private:
std::deque<reliable_text_t> reliableText_;
std::string receivedReliableText_;
int preProcessRxFn_(ParallelStep* ps);
int postProcessRxFn_(ParallelStep* ps);
};
#endif // CODEC2_INTERFACE_H