ubitx-v5x/TeensyDSP/DSP.h

146 lines
3.1 KiB
C
Raw Normal View History

//======================================================================
// DSP.h
//======================================================================
#ifndef __DSP_h__
#define __DSP_h__
#include <Audio.h>
#include <dynamicFilters.h>
#include "Debug.h"
#define MIN_RX_FILTER_LO 0
#define MAX_RX_FILTER_HI 5000
#define MIN_RX_FILTER_WIDTH 0
#define MAX_RX_FILTER_WIDTH 5000
#define MIN_RX_FILTER_CENTER 0
#define MAX_RX_FILTER_CENTER 5000
#define DSP_MILLIS_PER_UPDATE 100
#define TX_MIC_IN_CH 0
#define TX_LINE_IN_CH 0
#define TX_USB_IN_CH 1
#define TX_NUM_CHANNELS 2
#define TX_LINE_IN_VOX 0
#define TX_USB_IN_L_VOX 1
#define TX_USB_IN_R_VOX 2
#define TX_NUM_VOX 3
#define TX_LINE_IN_VOX_THRESH 0.25
#define TX_USB_IN_L_VOX_THRESH 0.25
#define TX_USB_IN_R_VOX_THRESH 0.25
#define TX_LINE_IN_VOX_DELAY 500
#define TX_USB_IN_L_VOX_DELAY 500
#define TX_USB_IN_R_VOX_DELAY 500
struct DSPState {
// RX audio output settings
// RX filter settings
int rxFilterLo = 300;
int rxFilterHi = 3000;
// TX audio input settings
float txInLvl[4] = {0.5, 0.5, 0.0, 0.0};
int txInEnable[4] = {1, 1, 0, 0};
int txInTx[4] = {0, 0, 0, 0};
// VOX settings
bool voxActive[3];
float voxThresh[3];
unsigned voxDelay[3];
unsigned voxTimeout[3];
};
enum TRState {
TRANSMIT,
RECEIVE
};
enum RxAudioIn {
RIG_AUDIO
};
enum TxAudioIn {
MIC_IN,
LINE_IN,
USB_IN
};
class UBitxDSP {
public:
UBitxDSP();
void begin();
void update();
void end();
void rx();
void txMicIn();
void txLineIn();
void txUSBIn();
// RX audio output settings
// RX filter settings
void bypassRxFilter();
void setRxFilter(int lo, int hi);
void setRxFilterLo(int lo);
void setRxFilterHi(int hi);
void setRxFilterWidth(int width);
void setRxFilterCenter(int center);
/*!
* @brief Get the current low frequency bound of the RX band pass filter.
* @return The low frequency bound.
*/
inline int getRxFilterLo() { return state.rxFilterLo; }
/*!
* @brief Get the current high frequency bound of the RX band pass filter.
* @return The high frequency bound.
*/
inline int getRxFilterHi() { return state.rxFilterHi; }
/*!
* @brief Get the current width of the RX band pass filter.
* @return The filter width.
*/
inline int getRxFilterWidth() { return state.rxFilterHi - state.rxFilterLo; }
/*!
* @brief Get the current center frequency of the RX band pass filter.
* @return The center frequency.
*/
inline int getRxFilterCenter() { return (state.rxFilterHi + state.rxFilterLo) / 2; }
// TX audio input settings
void setTxInputLevel(int ch, float lvl);
void enableTxInput(int ch);
void disableTxInput(int ch);
void startTxInput(int ch);
void stopTxInput(int ch);
// VOX settings
bool isVoxActive(int vox);
private:
void updateRxFilter();
DSPState state;
short coefficients[NUM_COEFFICIENTS];
elapsedMillis sinceLastUpdate;
AudioAnalyzeRMS* voxRMS[3];
};
extern UBitxDSP DSP;
#endif
//======================================================================
// EOF
//======================================================================