From e6009989dbde058b5fef63e293483f08961066f1 Mon Sep 17 00:00:00 2001 From: Rob French Date: Tue, 30 Mar 2021 12:31:44 -0500 Subject: [PATCH] Reorganizing DSP and TR. Thoroughly broken ATM, just committing for backup. --- TeensyDSP/DSP.cpp | 121 ++++++++++++------------------------ TeensyDSP/DSP.h | 155 ++++++++++------------------------------------ TeensyDSP/TR.h | 45 ++++++++------ 3 files changed, 97 insertions(+), 224 deletions(-) diff --git a/TeensyDSP/DSP.cpp b/TeensyDSP/DSP.cpp index 3344123..1d1d190 100644 --- a/TeensyDSP/DSP.cpp +++ b/TeensyDSP/DSP.cpp @@ -11,40 +11,40 @@ //#include // GUItool: begin automatically generated code -AudioInputUSB usbIn; //xy=161,313 -AudioInputI2S lineIn; //xy=169,205 -AudioSynthWaveformSine tone1; //xy=234,386 -AudioSynthWaveformSine tone2; //xy=234,422 -AudioMixer4 rxAudio; //xy=426,119 -AudioMixer4 txAudio; //xy=430,307 -AudioAnalyzeRMS txVoxLevel; //xy=588,348 -AudioFilterFIR rxFilter; //xy=591,111 -AudioAmplifier usbOutAmp; //xy=756,107 -AudioAmplifier lineOutAmp; //xy=757,170 -AudioAmplifier usbBypassAmp; //xy=764,233 -AudioAmplifier txOutAmp; //xy=811,309 -AudioOutputI2S lineOut; //xy=974,302 -AudioOutputUSB usbOut; //xy=976,263 +AudioInputUSB usbIn; //xy=63,305 +AudioInputI2S lineIn; //xy=71,197 +AudioSynthWaveformSine tone1; //xy=111,369 +AudioSynthWaveformSine tone2; //xy=111,410 +AudioMixer4 rxAudio; //xy=328,111 +AudioMixer4 txAudio; //xy=332,299 +AudioAnalyzeRMS txVoxLevel; //xy=490,340 +AudioFilterFIR rxFilter; //xy=493,103 +AudioAmplifier usbOutAmp; //xy=658,99 +AudioAmplifier lineOutAmp; //xy=659,162 +AudioAmplifier usbBypassAmp; //xy=666,225 +AudioAmplifier txOutAmp; //xy=713,301 +AudioOutputI2S lineOut; //xy=876,294 +AudioOutputUSB usbOut; //xy=878,255 AudioConnection patchCord1(usbIn, 0, txAudio, 1); AudioConnection patchCord2(lineIn, 0, rxAudio, 0); AudioConnection patchCord3(lineIn, 1, txAudio, 0); AudioConnection patchCord4(tone1, 0, txAudio, 2); -AudioConnection patchCord5(tone2, 0, txAudio, 3); -AudioConnection patchCord6(rxAudio, rxFilter); -AudioConnection patchCord7(rxAudio, usbBypassAmp); -AudioConnection patchCord8(txAudio, txVoxLevel); -AudioConnection patchCord9(txAudio, txOutAmp); -AudioConnection patchCord10(rxFilter, usbOutAmp); -AudioConnection patchCord11(rxFilter, lineOutAmp); -AudioConnection patchCord12(usbOutAmp, 0, usbOut, 0); -AudioConnection patchCord13(lineOutAmp, 0, lineOut, 0); -AudioConnection patchCord14(usbBypassAmp, 0, usbOut, 1); -AudioConnection patchCord15(txOutAmp, 0, lineOut, 1); -AudioControlSGTL5000 audioCtrl; //xy=435,448 +AudioConnection patchCord5(tone1, 0, rxAudio, 2); +AudioConnection patchCord6(tone2, 0, txAudio, 3); +AudioConnection patchCord7(tone2, 0, rxAudio, 3); +AudioConnection patchCord8(rxAudio, rxFilter); +AudioConnection patchCord9(rxAudio, usbBypassAmp); +AudioConnection patchCord10(txAudio, txVoxLevel); +AudioConnection patchCord11(txAudio, txOutAmp); +AudioConnection patchCord12(rxFilter, usbOutAmp); +AudioConnection patchCord13(rxFilter, lineOutAmp); +AudioConnection patchCord14(usbOutAmp, 0, usbOut, 0); +AudioConnection patchCord15(lineOutAmp, 0, lineOut, 0); +AudioConnection patchCord16(usbBypassAmp, 0, usbOut, 1); +AudioConnection patchCord17(txOutAmp, 0, lineOut, 1); +AudioControlSGTL5000 audioCtrl; //xy=337,440 // GUItool: end automatically generated code -//} audio; - void UBitxDSP::begin() { // Basic audio setup @@ -65,7 +65,7 @@ void UBitxDSP::begin() { // Setup the VOX - TBD // Setup the RX Filter. - setRxFilter(300, 3000); + setRxFilter(300.0, 3000.0); sinceLastUpdate = 0; } @@ -80,19 +80,10 @@ void UBitxDSP::update() { } sinceLastUpdate = 0; } - - if (state.vox[txSrc].enable && txVoxLevel.available()) { - if (txVoxLevel.read() > state.vox[txSrc].threshold) { - isVoxActive = true; - sinceVoxActive = 0; - } - } - if (isVoxActive && (sinceVoxActive > state.voxDelay)) { - isVoxActive = false; - } } void UBitxDSP::end() { + bypassRxFilter(); } /********************************************************************** @@ -138,7 +129,7 @@ void UBitxDSP::tx(TxAudioIn src) { if (txSrcLatched == MIC_IN) { audioCtrl.inputSelect(AUDIO_INPUT_MIC); - audioCtrl.micGain(12); // TODO: Make this dynamic + audioCtrl.micGain(micGain); } unmuteTxOut(); @@ -241,16 +232,6 @@ void UBitxDSP::setUSBOutLevel(float level) { usbBypassAmp.gain(state.rxOut[USB_OUT].mute ? 0.0 : state.rxOut[USB_OUT].level); } -void UBitxDSP::setLineOut255(unsigned level) { setLineOutLevel<255>(level); } -void UBitxDSP::setLineOut9(unsigned level) { setLineOutLevel<9>(level); } -void UBitxDSP::setUSBOut255(unsigned level) { setUSBOutLevel<255>(level); } -void UBitxDSP::setUSBOut9(unsigned level) { setUSBOutLevel<9>(level); } - -unsigned UBitxDSP::getLineOut255() const { return getLineOutLevel<255>(); } -unsigned UBitxDSP::getLineOut9() const { return getLineOutLevel<9>(); } -unsigned UBitxDSP::getUSBOut255() const { return getUSBOutLevel<255>(); } -unsigned UBitxDSP::getUSBOut9() const { return getUSBOutLevel<9>(); } - /********************************************************************** * Transmit audio chain **********************************************************************/ @@ -316,16 +297,6 @@ void UBitxDSP::setUSBInLevel(float level) { txAudio.gain(TX_USB, state.txIn[TX_USB].mute ? 0.0 : state.txIn[TX_USB].level); } -void UBitxDSP::setLineIn255(unsigned level) { setLineInLevel<255>(level); } -void UBitxDSP::setLineIn9(unsigned level) { setLineInLevel<9>(level); } -void UBitxDSP::setUSBIn255(unsigned level) { setUSBInLevel<255>(level); } -void UBitxDSP::setUSBIn9(unsigned level) { setUSBInLevel<9>(level); } - -unsigned UBitxDSP::getLineIn255() const { return getLineInLevel<255>(); } -unsigned UBitxDSP::getLineIn9() const { return getLineInLevel<9>(); } -unsigned UBitxDSP::getUSBIn255() const { return getUSBInLevel<255>(); } -unsigned UBitxDSP::getUSBIn9() const { return getUSBInLevel<9>(); } - void UBitxDSP::setTxAudioIn(TxAudioIn src, bool isTemp) { if (!isTemp) { txSrc = src; @@ -470,34 +441,20 @@ void UBitxDSP::setRxFilterCenter(int center) { * Transmit Voice-Operated-Switch (VOX) **********************************************************************/ -void UBitxDSP::setLineVOXThresh9(unsigned level) { - state.vox[TX_LINE].threshold = static_cast(level) / 9.0; -} - -unsigned UBitxDSP::getLineVOXThresh9() const { - return static_cast(state.vox[TX_LINE].threshold * 9.0); -} - -void UBitxDSP::setUSBVOXThresh9(unsigned level) { - state.vox[TX_USB].threshold = static_cast(level) / 9.0; -} - -unsigned UBitxDSP::getUSBVOXThresh9() const { - return static_cast(state.vox[TX_USB].threshold * 9.0); -} - -void UBitxDSP::setDataVoxDelay(unsigned msec) { - state.voxDelay = msec; -} - -unsigned UBitxDSP::getDataVoxDelay() const { - return state.voxDelay; +float UBitxDSP::getVoxLevel() const { + if (return txVoxLevel.available()) { + prevVox = txVoxLevel.read(); + } + return prevVox; } /********************************************************************** * Singleton - the DSP instance **********************************************************************/ +// TODO: Fix this. This won't work... this compilation unit won't be +// able to instantiate a class it doesn't know about. + #ifndef UBITXDSP_CLASS #define UBITXDSP_CLASS UBitxDSP #endif diff --git a/TeensyDSP/DSP.h b/TeensyDSP/DSP.h index e9cea44..c9b1a8d 100644 --- a/TeensyDSP/DSP.h +++ b/TeensyDSP/DSP.h @@ -13,12 +13,12 @@ * Macros **********************************************************************/ -#define MIN_RX_FILTER_LO (0) //! Min allowable value of the RX filter low-cut frequency -#define MAX_RX_FILTER_HI (5000) //! Max allowable value of the RX filter hi-cut frequency -#define MIN_RX_FILTER_WIDTH (0) //! Min allowable value of the RX filter bandwidth -#define MAX_RX_FILTER_WIDTH (5000) //! Max allowable value of the RX filter bandwidth -#define MIN_RX_FILTER_CENTER (0) //! Min allowable value of the RX filter center frequency -#define MAX_RX_FILTER_CENTER (5000) //! Max allowable value of the RX filter center frequency +#define MIN_RX_FILTER_LO (0.0) //! Min allowable value of the RX filter low-cut frequency +#define MAX_RX_FILTER_HI (5000.0) //! Max allowable value of the RX filter hi-cut frequency +#define MIN_RX_FILTER_WIDTH (0.0) //! Min allowable value of the RX filter bandwidth +#define MAX_RX_FILTER_WIDTH (5000.0) //! Max allowable value of the RX filter bandwidth +#define MIN_RX_FILTER_CENTER (0.0) //! Min allowable value of the RX filter center frequency +#define MAX_RX_FILTER_CENTER (5000.0) //! Max allowable value of the RX filter center frequency #define DSP_MILLIS_PER_UPDATE (100) //! Number of milliseconds between update of the DSP object @@ -36,9 +36,9 @@ //! Defines the four separate RX audio input channels available. enum RxAudioCh { RX_AUDIO = 0, // Normal receiver audio input channel - RX_SPARE1, // Not used - RX_SPARE2, // Not used - RX_SPARE3, // Not used + RX_SPARE, // Not used + RX_TONE1 , // Optional tone #1 input channel (currently not used) + RX_TONE2, // Optional tone #2 input channel (currently not used) NUM_RX_AUDIO_CH // Total number of channels }; @@ -100,7 +100,8 @@ struct DSPState { {true, 0.0} // spare 3 }; - //! Receiver audio output; defaults to muted. + //! Receiver audio output; defaults to un + muted. AudioChannel rxOut[NUM_RX_AUDIO_OUT] = { {false, 1.0}, // line {false, 1.0} // USB @@ -117,24 +118,9 @@ struct DSPState { //! Tranmitter audio output; defaults to muted. AudioChannel txOut = {true, 1.0}; - //! Transmitter VOX settings, per audio input (not channel). - struct { - bool enable = false; - float threshold = 1.0; - } vox[NUM_TX_AUDIO_IN] = { - {false, TX_VOX_MIC_THRESH}, - {true, TX_VOX_LINE_THRESH}, - {true, TX_VOX_USB_THRESH}, - {false, TX_VOX_TUNE_THRESH}, - {false, TX_VOX_TT_THRESH} - }; - - //! VOX delay (regardless of input). - unsigned voxDelay = TX_VOX_DELAY; - //! Current RX filter settings - int rxFilterLo = 300; - int rxFilterHi = 3000; + float rxFilterLo = 300.0; + float rxFilterHi = 3000.0; }; /*! @@ -195,41 +181,6 @@ class UBitxDSP { void setLineOutLevel(float level); // Set the line output level (0.0 - 1.0). void setUSBOutLevel(float level); // Set the USB output level (0.0 - 1.0). - // Discrete control intended for use with TS-590 CAT. - void setLineOut255(unsigned level); // Set the line output level (0 - 255). - void setLineOut9(unsigned level); // Set the line output level (0 - 9). - void setUSBOut255(unsigned level); // Set the USB output level (0 - 255). - void setUSBOut9(unsigned level); // Set the USB output level (0 - 9). - - unsigned getLineOut255() const; // Get the line output level (0 - 255). - unsigned getLineOut9() const; // Get the line output level (0 - 9). - unsigned getUSBOut255() const; // Get the USB output level (0 - 255). - unsigned getUSBOut9() const; // Get the USB output level (0 - 9). - - //! Set the line output level based on an integer value. - template - void setLineOutLevel(unsigned level) { - setLineOutLevel(static_cast(level) / static_cast(MAX)); - } - - //! Set the USB output level based on an integer value. - template - void setUSBOutLevel(unsigned level) { - setUSBOutLevel(static_cast(level) / static_cast(MAX)); - } - - //! Get the line output level as an integer value. - template - unsigned getLineOutLevel() const { - return static_cast(state.rxOut[LINE_OUT].level * static_cast(MAX)); - } - - //! Get the USB output level as an integer value. - template - unsigned getUSBOutLevel() const { - return static_cast(state.rxOut[USB_OUT].level * static_cast(MAX)); - } - /******************************************************************** * Transmit audio chain ********************************************************************/ @@ -248,46 +199,15 @@ class UBitxDSP { void setLineInLevel(float level); // Set the line input level (0.0 - 1.0). void setUSBInLevel(float level); // Set the USB input level (0.0 - 1.0). - // Discrete control intended for use with TS-590 CAT. - void setLineIn255(unsigned level); // Set the line input level (0 - 255). - void setLineIn9(unsigned level); // Set the line input level (0 - 9). - void setUSBIn255(unsigned level); // Set the USB input level (0 - 255). - void setUSBIn9(unsigned level); // Set the USB input level (0 - 9). - - unsigned getLineIn255() const; // Get the line input level (0 - 255). - unsigned getLineIn9() const; // Get the line input level (0 - 9). - unsigned getUSBIn255() const; // Get the USB input level (0 - 255). - unsigned getUSBIn9() const; // Get the USB input level (0 - 9). - - //! Set the line input level based on an integer value. - template - void setLineInLevel(unsigned level) { - setLineInLevel(static_cast(level) / static_cast(MAX)); - } - - //! Set the USB input level based on an integer value. - template - void setUSBInLevel(unsigned level) { - setUSBInLevel(static_cast(level) / static_cast(MAX)); - } - - //! Get the line input level as an integer value. - template - unsigned getLineInLevel() const { - return static_cast(state.txIn[LINE_OUT].level * static_cast(MAX)); - } - - //! Get the USB input level as an integer value. - template - unsigned getUSBInLevel() const { - return static_cast(state.txIn[USB_OUT].level * static_cast(MAX)); - } - // Transmit audio selection (may be overriden at actual transmit time). public: void setTxAudioIn(TxAudioIn src, bool isTemp = false); // Select a specific TX audio input path, and identify it as permanent or temporary. inline TxAudioIn getTxAudioIn() const { return txSrc; } // Return the current TX audio input. + // Mic input controls. + public: + inline void setMicGain(float level) { micGain = static_cast(level * 63.0); } // Set the mic gain. + /******************************************************************** * Receive audio filter (band pass) ********************************************************************/ @@ -296,56 +216,42 @@ class UBitxDSP { void bypassRxFilter(); void updateRxFilter(); - void setRxFilter(int lo, int hi); - void setRxFilterLo(int lo); - void setRxFilterHi(int hi); - void setRxFilterWidth(int width); - void setRxFilterCenter(int center); + void setRxFilter(float lo, float hi); + void setRxFilterLo(float lo); + void setRxFilterHi(float hi); + void setRxFilterWidth(float width); + void setRxFilterCenter(float center); /*! * Get the current low frequency bound of the RX band pass filter. * @return The low frequency bound. */ - inline int getRxFilterLo() { return state.rxFilterLo; } + inline float getRxFilterLo() const { return state.rxFilterLo; } /*! * Get the current high frequency bound of the RX band pass filter. * @return The high frequency bound. */ - inline int getRxFilterHi() { return state.rxFilterHi; } + inline float getRxFilterHi() const { return state.rxFilterHi; } /*! * Get the current width of the RX band pass filter. * @return The filter width. */ - inline int getRxFilterWidth() { return state.rxFilterHi - state.rxFilterLo; } + inline float getRxFilterWidth() const { return state.rxFilterHi - state.rxFilterLo; } /*! * Get the current center frequency of the RX band pass filter. * @return The center frequency. */ - inline int getRxFilterCenter() { return (state.rxFilterHi + state.rxFilterLo) / 2; } + inline float getRxFilterCenter() const { return (state.rxFilterHi + state.rxFilterLo) / 2.0; } /******************************************************************** * Transmit Voice-Operated-Switch (VOX) ********************************************************************/ - inline void enableVOX() { state.vox[txSrc].enable = true; } - inline void disableVOX() { state.vox[txSrc].enable = false; } - inline bool voxEnabled() { return state.vox[txSrc].enable; } - inline bool voxDisabled() { return !state.vox[txSrc].enable; } - - inline bool voxActive() { return isVoxActive; } - inline bool voxInactive() { return !isVoxActive; } - - void setLineVOXThresh9(unsigned level); - unsigned getLineVOXThresh9() const; - - void setUSBVOXThresh9(unsigned level); - unsigned getUSBVOXThresh9() const; - - void setDataVoxDelay(unsigned msec); - unsigned getDataVoxDelay() const; + public: + float getVoxLevel() const; /******************************************************************** * Private state @@ -363,8 +269,9 @@ class UBitxDSP { elapsedMillis sinceLastUpdate = 0; float usbVol = 0.0; - bool isVoxActive = false; - elapsedMillis sinceVoxActive = 0; + unsigned micGain = 0; + + float prevVox = 0.0; }; extern UBitxDSP& DSP; diff --git a/TeensyDSP/TR.h b/TeensyDSP/TR.h index 382903c..105ae2c 100644 --- a/TeensyDSP/TR.h +++ b/TeensyDSP/TR.h @@ -41,29 +41,29 @@ class UBitxTR { } inline void enableMicPTT() { pttEnable = true; } - inline void enableMicVOX() { voxEnable = true; } inline void enableLinePTT() { keyEnable = true; } - inline void enableDataVOX() { dsp.enableVOX(); } + inline void enableMicVOX() { voxEnable = true; } + inline void enableDataVOX() { dvoxEnable = true; } inline void enableCAT() { catEnable = true; } inline void disableMicPTT() { pttEnable = false; } - inline void disableMicVOX() { voxEnable = false; } inline void disableLinePTT() { keyEnable = false; } - inline void disableDataVOX() { dsp.disableVOX(); } + inline void disableMicVOX() { voxEnable = false; } + inline void disableDataVOX() { dvoxEnable = false; } inline void disableCAT() { catEnable = false; } - inline bool micPTTEnabled() { return pttEnable; } - inline bool micVOXEnabled() { return voxEnable; } - inline bool linePTTEnabled() { return keyEnable; } - inline bool dataVOXEnabled() { return dsp.voxEnabled(); } - inline bool catEnabled() { return catEnable; } + inline bool micPTTEnabled() const { return pttEnable; } + inline bool linePTTEnabled() const { return keyEnable; } + inline bool micVOXEnabled() const { return voxEnable; } + inline bool dataVOXEnabled() const { return dvoxEnable; } + inline bool catEnabled() const { return catEnable; } inline bool micPTTPressed() { return ptt.fell(); } inline bool micPTTReleased() { return ptt.rose(); } - inline bool micVOXActivated() { return (L_voxActive != voxActive) && L_voxActive; } - inline bool micVOXDeactivated() { return (L_voxActive != voxActive) && voxActive; } inline bool linePTTPressed() { return (L_keyDown != keyDown) && L_keyDown; } inline bool linePTTReleased() { return (L_keyDown != keyDown) && keyDown; } + inline bool micVOXActivated() { return (L_voxActive != voxActive) && L_voxActive; } + inline bool micVOXDeactivated() { return (L_voxActive != voxActive) && voxActive; } inline bool dataVOXActivated() { return (L_dvoxActive != dvoxActive) && L_dvoxActive; } inline bool dataVOXDeactivated() { return (L_dvoxActive != dvoxActive) && dvoxActive; } inline bool catActivated() { return (L_catActive != catActive) && L_catActive; } @@ -119,34 +119,40 @@ class UBitxTR { ptt.update(); } - inline void updateMicVOX() { - L_voxActive = voxActive; - voxActive = (digitalRead(voxPin) == LOW); - } - inline void updateLinePTT() { L_keyDown = keyDown; keyDown = (digitalRead(keyPin) == LOW); } + inline void updateMicVOX() { + L_voxActive = voxActive; + voxActive = (digitalRead(voxPin) == LOW); + } + inline void updateDataVOX() { L_dvoxActive = dvoxActive; - dvoxActive = dsp.voxActive(); + if (dsp.getVoxLevel() > dvoxThreshold) { + dvoxActive = true; + dvoxElapsed = 0; + } else if (dvoxActive && (dvoxElapsed > dvoxDelay)) { + dvoxActive = false; + } } UBitxDSP& dsp; Bounce ptt; - int outPin; int pttPin; int voxPin; int keyPin; + int outPin; bool isTX = false; bool pttEnable = false; bool voxEnable = false; + bool dvoxEnable = false; bool keyEnable = false; bool catEnable = false; @@ -158,6 +164,9 @@ class UBitxTR { bool L_keyDown = false; bool catActive = false; bool L_catActive = false; + + elapsedMillis dvoxElapsed = 0; + unsigned dvoxDelay = 250; // TODO: make dynamic }; extern UBitxTR TR;