Updated DSP. Compiles, no warnings/errors. Going to do some work on CAT.

This commit is contained in:
Rob French
2021-03-16 18:37:14 -05:00
parent 869e47d430
commit f724142fca
4 changed files with 244 additions and 208 deletions
+92 -89
View File
@@ -10,17 +10,6 @@
//#include <SD.h>
//#include <SerialFlash.h>
const int rxRigInChannel = RX_RIG_IN_CH;
const int txMicInChannel = TX_MIC_IN_CH;
const int txLineInChannel = TX_LINE_IN_CH;
const int txUSBInChannel = TX_USB_IN_CH;
const int txNumChannels = TX_NUM_CHANNELS;
UBitxDSP DSP;
//static struct {
// GUItool: begin automatically generated code
AudioInputUSB usbIn; //xy=161,313
AudioInputI2S lineIn; //xy=169,205
@@ -56,10 +45,6 @@ AudioControlSGTL5000 audioCtrl; //xy=435,448
//} audio;
UBitxDSP::UBitxDSP()
: txSrc(MIC_IN), txSrcLatched(MIC_IN) {
}
void UBitxDSP::begin() {
// Basic audio setup
@@ -98,33 +83,32 @@ void UBitxDSP::update() {
if (state.vox[txSrc].enable && txVoxLevel.available()) {
if (txVoxLevel.read() > state.vox[txSrc].threshold) {
voxTimeout = millis() + state.voxDelay;
state.voxActive = true;
isVoxActive = true;
sinceVoxActive = 0;
}
}
if (millis() > voxTimeout) {
state.voxActive = false;
if (isVoxActive && (sinceVoxActive > state.voxDelay)) {
isVoxActive = false;
}
}
void UBitxDSP::end() {
}
//======================================================================
// Transmit/Receive (T/R) Switching
//======================================================================
/**********************************************************************
* Transmit/Receive switching
**********************************************************************/
/*!
* @brief Revert to receive (RX) mode from transmit (TX) mode. First
* the transmit audio output is muted, to ensure that no more
* audio goes to the rig. Then we check to see if the latched
* TX audio source was different than the selected TX audio
* source; this happens if the radio is currently set for a
* particular input (which determines what is monitored by the
* VOX), but then is commanded to transmit a different source
* (e.g. based on a CAT command). The actual transmit audio
* source is latched during transmit, but upon returning to
* receive, we restore the selected transmit audio.
* Return to receive (RX) mode from transmit (TX) mode.
* First the transmit audio output is muted, to ensure that no more
* audio goes to the rig. Then we check to see if the latched TX audio
* source was different than the selected TX audio source; this happens
* if the radio is currently set for a particular input (which
* determines what is monitored by the VOX), but then is commanded to
* transmit a different source (e.g. based on a CAT command). The
* actual transmit audio source is latched during transmit, but upon
* returning to receive, we restore the selected transmit audio.
*/
void UBitxDSP::rx() {
if (isTx) {
@@ -140,6 +124,9 @@ void UBitxDSP::rx() {
}
}
/*!
* Enter transmit (TX) mode from receive (RX) mode.
*/
void UBitxDSP::tx(TxAudioIn src) {
if (!isTx) {
muteRxIn(RX_AUDIO);
@@ -159,9 +146,9 @@ void UBitxDSP::tx(TxAudioIn src) {
}
}
//======================================================================
// Receive (RX) Audio Chain
//======================================================================
/**********************************************************************
* General audio setup -- called via begin()
**********************************************************************/
void UBitxDSP::setupRxAudio() {
for (int i = 0; i < NUM_RX_AUDIO_CH; i++) {
@@ -185,42 +172,6 @@ void UBitxDSP::setupRxAudio() {
usbBypassAmp.gain(1.0);
}
void UBitxDSP::setRxInLevel(RxAudioCh ch, float level) {
if (ch < NUM_RX_AUDIO_CH) {
state.rxin[ch].level = level;
rxAudio.gain(ch, state.rxin[ch].mute ? 0.0 : state.rxin[ch].level);
}
}
void UBitxDSP::muteRxIn() {
for (int i = 0; i < NUM_RX_AUDIO_CH; i++) {
state.rxin[RxAudioCh(i)].mute = true;
rxAudio.gain(i, 0.0);
}
}
void UBitxDSP::muteRxIn(RxAudioCh ch) {
if (ch < NUM_RX_AUDIO_CH) {
if (!state.rxin[ch].mute) {
state.rxin[ch].mute = true;
rxAudio.gain(ch, 0.0);
}
}
}
void UBitxDSP::unmuteRxIn(RxAudioCh ch) {
if (ch < NUM_RX_AUDIO_CH) {
if (state.rxin[ch].mute) {
state.rxin[ch].mute = false;
rxAudio.gain(ch, state.rxin[ch].level);
}
}
}
//======================================================================
// Transmit (TX) Audio Chain
//======================================================================
void UBitxDSP::setupTxAudio() {
for (int i = 0; i < NUM_TX_AUDIO_CH; i++) {
txAudio.gain(i, 0.0);
@@ -244,24 +195,64 @@ void UBitxDSP::setupTxAudio() {
tone2.frequency(1900);
}
/**********************************************************************
* Receive audio chain
**********************************************************************/
void UBitxDSP::setRxInLevel(RxAudioCh ch, float level) {
if (ch < NUM_RX_AUDIO_CH) {
state.rxIn[ch].level = level;
rxAudio.gain(ch, state.rxIn[ch].mute ? 0.0 : state.rxIn[ch].level);
}
}
void UBitxDSP::muteRxIn() {
for (int i = 0; i < NUM_RX_AUDIO_CH; i++) {
state.rxIn[RxAudioCh(i)].mute = true;
rxAudio.gain(i, 0.0);
}
}
void UBitxDSP::muteRxIn(RxAudioCh ch) {
if (ch < NUM_RX_AUDIO_CH) {
if (!state.rxIn[ch].mute) {
state.rxIn[ch].mute = true;
rxAudio.gain(ch, 0.0);
}
}
}
void UBitxDSP::unmuteRxIn(RxAudioCh ch) {
if (ch < NUM_RX_AUDIO_CH) {
if (state.rxIn[ch].mute) {
state.rxIn[ch].mute = false;
rxAudio.gain(ch, state.rxIn[ch].level);
}
}
}
/**********************************************************************
* Transmit audio chain
**********************************************************************/
void UBitxDSP::setTxInLevel(TxAudioCh ch, float level) {
if (ch < NUM_TX_AUDIO_CH) {
state.txin[ch].level = level;
txAudio.gain(ch, state.txin[ch].mute ? 0.0 : state.txin[ch].level);
state.txIn[ch].level = level;
txAudio.gain(ch, state.txIn[ch].mute ? 0.0 : state.txIn[ch].level);
}
}
void UBitxDSP::muteTxIn() {
for (int i = 0; i < NUM_TX_AUDIO_CH; i++) {
state.txin[TxAudioCh(i)].mute = true;
state.txIn[TxAudioCh(i)].mute = true;
txAudio.gain(i, 0.0);
}
}
void UBitxDSP::muteTxIn(TxAudioCh ch) {
if (ch < NUM_TX_AUDIO_CH) {
if (!state.txin[ch].mute) {
state.txin[ch].mute = true;
if (!state.txIn[ch].mute) {
state.txIn[ch].mute = true;
txAudio.gain(ch, 0.0);
}
}
@@ -269,29 +260,29 @@ void UBitxDSP::muteTxIn(TxAudioCh ch) {
void UBitxDSP::unmuteTxIn(TxAudioCh ch) {
if (ch < NUM_TX_AUDIO_CH) {
if (state.txin[ch].mute) {
state.txin[ch].mute = false;
rxAudio.gain(ch, state.txin[ch].level);
if (state.txIn[ch].mute) {
state.txIn[ch].mute = false;
rxAudio.gain(ch, state.txIn[ch].level);
}
}
}
void UBitxDSP::setTxOutLevel(float level) {
state.txout.level = level;
txOutAmp.gain(state.txout.mute ? 0.0 : state.txout.level);
state.txOut.level = level;
txOutAmp.gain(state.txOut.mute ? 0.0 : state.txOut.level);
}
void UBitxDSP::muteTxOut() {
if (!state.txout.mute) {
state.txout.mute = true;
if (!state.txOut.mute) {
state.txOut.mute = true;
txOutAmp.gain(0.0);
}
}
void UBitxDSP::unmuteTxOut() {
if (state.txout.mute) {
state.txout.mute = false;
txOutAmp.gain(state.txout.level);
if (state.txOut.mute) {
state.txOut.mute = false;
txOutAmp.gain(state.txOut.level);
}
}
@@ -338,13 +329,14 @@ void UBitxDSP::setTxAudioIn(TxAudioIn src, bool isTemp) {
default:
// should never happen
break;
}
}
}
//======================================================================
// RX Audio Filter Settings
//======================================================================
/**********************************************************************
* Receive audio filter (band pass)
**********************************************************************/
const int minRxFilterLo = MIN_RX_FILTER_LO;
const int maxRxFilterHi = MAX_RX_FILTER_HI;
@@ -434,6 +426,17 @@ void UBitxDSP::setRxFilterCenter(int center) {
setRxFilter(lo, hi);
}
/**********************************************************************
* Singleton - the DSP instance
**********************************************************************/
#ifndef UBITXDSP_CLASS
#define UBITXDSP_CLASS UBitxDSP
#endif
UBITXDSP_CLASS theDSP;
UBitxDSP& DSP = theDSP;
/*
NOTES