freedv-gui/src/pipeline/RADEReceiveStep.h

103 lines
3.6 KiB
C++

//=========================================================================
// Name: RADEReceiveStep.h
// Purpose: Describes a demodulation step in the audio pipeline.
//
// Authors: Mooneer Salem
// License:
//
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.1,
// as published by the Free Software Foundation. This program is
// distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//
//=========================================================================
#ifndef AUDIO_PIPELINE__RADE_RECEIVE_STEP_H
#define AUDIO_PIPELINE__RADE_RECEIVE_STEP_H
#include <atomic>
#include <cstdio>
#include <thread>
#include <functional>
#include "IPipelineStep.h"
#include "rade_api.h"
#include "rade_text.h"
#include "../util/GenericFIFO.h"
#include "../util/Semaphore.h"
#include "../util/realtime_fp.h"
// Number of features to store. This is set to be close to the
// typical size for RX/TX features for the rade_loss ctest to
// avoid contention with normal RADE operation.
#define NUM_FEATURES_TO_STORE (256 * 1024)
// TBD - need to wrap in "extern C" to avoid linker errors
extern "C"
{
#if defined(FREEDV_INTEGRATION)
#include "fargan_config_integ.h"
#else
#include "fargan_config.h"
#endif // defined(FREEDV_INTEGRATION)
#include "fargan.h"
#include "lpcnet.h"
}
class RADEReceiveStep : public IPipelineStep
{
public:
RADEReceiveStep(struct rade* dv, FARGANState* fargan, rade_text_t textPtr, realtime_fp<void(RADEReceiveStep*)> const& syncFn);
virtual ~RADEReceiveStep();
virtual int getInputSampleRate() const FREEDV_NONBLOCKING override;
virtual int getOutputSampleRate() const FREEDV_NONBLOCKING override;
virtual short* execute(short* inputSamples, int numInputSamples, int* numOutputSamples) FREEDV_NONBLOCKING override;
virtual void reset() FREEDV_NONBLOCKING override;
int getSync() const { return syncState_.load(std::memory_order_acquire); }
int getSnr() const { return snr_.load(std::memory_order_acquire); }
realtime_fp<std::atomic<int>*()> getRxStateFn() { return rxStateFn_; }
void setRxStateFn(realtime_fp<std::atomic<int>*()> const& rxFn) { rxStateFn_ = rxFn; }
void* getStateObj() const { return stateObj_; }
void setStateObj(void* state) { stateObj_ = state; }
private:
std::atomic<int> syncState_;
std::atomic<int> snr_;
struct rade* dv_;
FARGANState* fargan_;
PreAllocatedFIFO<short, RADE_MODEM_SAMPLE_RATE> inputSampleFifo_;
PreAllocatedFIFO<short, RADE_SPEECH_SAMPLE_RATE> outputSampleFifo_;
float* pendingFeatures_;
int pendingFeaturesIdx_;
FILE* featuresFile_;
rade_text_t textPtr_;
realtime_fp<void(RADEReceiveStep*)> syncFn_;
RADE_COMP* inputBufCplx_;
short* inputBuf_;
float* featuresOut_;
float* eooOut_;
std::unique_ptr<short[]> outputSamples_;
PreAllocatedFIFO<float, NUM_FEATURES_TO_STORE>* utFeatures_;
std::thread utFeatureThread_;
std::atomic<bool> exitingFeatureThread_;
Semaphore featuresAvailableSem_;
realtime_fp<std::atomic<int>*()> rxStateFn_;
void* stateObj_;
void utFeatureThreadEntry_();
};
#endif // AUDIO_PIPELINE__RADE_RECEIVE_STEP_H