CubicSDR/src/demod/DemodulatorThread.h

76 lines
1.9 KiB
C
Raw Normal View History

// Copyright (c) Charles J. Cliffe
// SPDX-License-Identifier: GPL-2.0+
2014-12-16 18:27:32 -05:00
#pragma once
#include <queue>
#include <vector>
#include <memory>
2014-12-16 18:27:32 -05:00
#include "DemodDefs.h"
#include "AudioThread.h"
2015-11-17 19:32:47 -05:00
#include "Modem.h"
#include "SpinMutex.h"
2014-12-16 18:27:32 -05:00
#define DEMOD_VIS_SIZE 2048
2015-11-21 15:12:20 -05:00
#define DEMOD_SIGNAL_MIN -30
#define DEMOD_SIGNAL_MAX 30
class DemodulatorInstance;
2015-07-29 20:57:02 -04:00
class DemodulatorThread : public IOThread {
2014-12-16 18:27:32 -05:00
public:
explicit DemodulatorThread(DemodulatorInstance* parent);
~DemodulatorThread() override;
2014-12-16 18:27:32 -05:00
void onBindOutput(std::string name, ThreadQueueBasePtr threadQueue) override;
void run() override;
void terminate() override;
2015-11-17 21:22:51 -05:00
void setMuted(bool muted_in);
bool isMuted();
2014-12-31 19:45:01 -05:00
float getSignalLevel();
2016-08-10 14:02:25 -04:00
float getSignalCeil();
2021-04-22 00:34:45 -04:00
void setSquelchEnabled(bool squelchEnabled_in);
bool isSquelchEnabled();
2016-08-10 14:02:25 -04:00
float getSignalFloor();
2014-12-31 19:45:01 -05:00
void setSquelchLevel(float signal_level_in);
float getSquelchLevel();
2016-02-11 01:32:39 -05:00
bool getSquelchBreak();
2017-08-27 05:11:30 -04:00
static void releaseSquelchLock(DemodulatorInstance* inst);
2014-12-16 18:27:32 -05:00
protected:
2015-11-21 15:12:20 -05:00
double abMagnitude(float inphase, float quadrature);
double linearToDb(double linear);
2015-11-21 15:12:20 -05:00
2017-08-27 05:11:30 -04:00
DemodulatorInstance* demodInstance;
2016-06-02 01:20:42 -04:00
ReBuffer<AudioThreadInput> outputBuffers;
2015-01-01 03:48:32 -05:00
std::atomic_bool muted;
2014-12-16 18:27:32 -05:00
std::atomic<float> squelchLevel;
2016-08-10 14:02:25 -04:00
std::atomic<float> signalLevel, signalFloor, signalCeil;
2021-04-22 00:34:45 -04:00
std::atomic<bool> squelchEnabled, squelchBreak;
2015-06-05 03:51:46 -04:00
2017-08-27 05:11:30 -04:00
static DemodulatorInstance* squelchLock;
2016-08-12 22:58:33 -04:00
static std::mutex squelchLockMutex;
2016-06-01 13:32:22 -04:00
Modem *cModem = nullptr;
ModemKit *cModemKit = nullptr;
2015-11-17 19:32:47 -05:00
DemodulatorThreadPostInputQueuePtr iqInputQueue;
AudioThreadInputQueuePtr audioOutputQueue;
DemodulatorThreadOutputQueuePtr audioVisOutputQueue;
DemodulatorThreadOutputQueuePtr audioSinkOutputQueue = nullptr;
2016-06-01 13:32:22 -04:00
//protects the audioVisOutputQueue dynamic binding change at runtime (in DemodulatorMgr)
SpinMutex m_mutexAudioVisOutputQueue;
2014-12-16 18:27:32 -05:00
};