2021-01-30 06:02:57 +00:00
|
|
|
//======================================================================
|
|
|
|
// DSP.h
|
|
|
|
//======================================================================
|
|
|
|
|
|
|
|
#ifndef __DSP_h__
|
|
|
|
#define __DSP_h__
|
|
|
|
|
2021-02-13 04:19:14 +00:00
|
|
|
#include <Audio.h>
|
|
|
|
#include <dynamicFilters.h>
|
2021-01-30 06:02:57 +00:00
|
|
|
#include "Debug.h"
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Macros
|
|
|
|
**********************************************************************/
|
|
|
|
|
2021-03-30 17:31:44 +00:00
|
|
|
#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
|
2021-03-16 23:37:14 +00:00
|
|
|
|
|
|
|
#define DSP_MILLIS_PER_UPDATE (100) //! Number of milliseconds between update of the DSP object
|
|
|
|
|
|
|
|
#define TX_VOX_MIC_THRESH (0.0) //! Threshold for mic VOX (not implemented, since mic requires special handling)
|
|
|
|
#define TX_VOX_LINE_THRESH (0.25) //! Threshold for line in VOX
|
|
|
|
#define TX_VOX_USB_THRESH (0.25) //! Threshold for USB VOX
|
|
|
|
#define TX_VOX_TUNE_THRESH (0.0) //! Threshold for tune (single tone) VOX (not expected to be used)
|
|
|
|
#define TX_VOX_TT_THRESH (0.0) //! Threshold for two-tone VOX (not expected to be used)
|
|
|
|
#define TX_VOX_DELAY (500) //! VOX delay in milliseconds
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Enumerations
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
//! Defines the four separate RX audio input channels available.
|
2021-03-15 04:18:24 +00:00
|
|
|
enum RxAudioCh {
|
2021-03-16 23:37:14 +00:00
|
|
|
RX_AUDIO = 0, // Normal receiver audio input channel
|
2021-03-30 17:31:44 +00:00
|
|
|
RX_SPARE, // Not used
|
|
|
|
RX_TONE1 , // Optional tone #1 input channel (currently not used)
|
|
|
|
RX_TONE2, // Optional tone #2 input channel (currently not used)
|
2021-03-16 23:37:14 +00:00
|
|
|
NUM_RX_AUDIO_CH // Total number of channels
|
2021-01-30 06:02:57 +00:00
|
|
|
};
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
//! Defines the different RX audio inputs (not channels).
|
2021-01-30 06:02:57 +00:00
|
|
|
enum RxAudioIn {
|
2021-03-16 23:37:14 +00:00
|
|
|
RIG_IN = 0, // Normal rig input (receiver audio)
|
|
|
|
NUM_RX_AUDIO_IN // Total number of inputs
|
2021-03-05 05:12:41 +00:00
|
|
|
};
|
|
|
|
|
2021-03-17 04:11:17 +00:00
|
|
|
//! Defines the different RX audio outputs.
|
|
|
|
enum RxAudioOut {
|
|
|
|
LINE_OUT = 0, // Line audio out (and speaker)
|
|
|
|
USB_OUT, // USB audio out
|
|
|
|
NUM_RX_AUDIO_OUT
|
|
|
|
};
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
//! Defines the four separate TX audio input channels available.
|
2021-03-15 04:18:24 +00:00
|
|
|
enum TxAudioCh {
|
2021-03-16 23:37:14 +00:00
|
|
|
TX_LINE = 0, // Line and/or mic audio input channel
|
|
|
|
TX_USB, // USB audio input channel
|
|
|
|
TX_TONE1, // Audio tone #1 input channel
|
|
|
|
TX_TONE2, // Audio tone #2 input channel
|
|
|
|
NUM_TX_AUDIO_CH // Toal number of channels
|
2021-01-30 06:02:57 +00:00
|
|
|
};
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
//! Defines the different TX audio input sources (not channels!).
|
2021-01-30 06:02:57 +00:00
|
|
|
enum TxAudioIn {
|
2021-03-16 23:37:14 +00:00
|
|
|
MIC_IN = 0, // Microphone transmit audio input
|
|
|
|
LINE_IN, // Line ("AUX") transmit audio input
|
|
|
|
USB_IN, // USB transmit audio input
|
|
|
|
TUNE_IN, // Tune input (transmits a single tone)
|
|
|
|
TWO_TONE_IN, // Two tone audio input (transmits two tones)
|
|
|
|
NUM_TX_AUDIO_IN // Total number of inputs
|
2021-03-05 05:12:41 +00:00
|
|
|
};
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Classes
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
//! Defines parameters for a simple audio channel that can be muted.
|
2021-03-15 04:18:24 +00:00
|
|
|
struct AudioChannel {
|
|
|
|
bool mute = false;
|
|
|
|
float level = 0.0;
|
|
|
|
};
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
/*!
|
|
|
|
* Contains the current 'persistent' state of the DSP.
|
|
|
|
* This includes all audio-specific state that can be saved to, or
|
|
|
|
* restored from, EEPROM. It does not include 'transient' state (such
|
|
|
|
* as whether we're currently transmitting or receiving).
|
|
|
|
*/
|
2021-03-15 04:18:24 +00:00
|
|
|
struct DSPState {
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
//! Receiver audio inputs; all default to muted.
|
|
|
|
AudioChannel rxIn[NUM_RX_AUDIO_CH] = {
|
2021-03-15 04:18:24 +00:00
|
|
|
{true, 1.0}, // audio
|
|
|
|
{true, 0.0}, // spare 1
|
|
|
|
{true, 0.0}, // spare 2
|
|
|
|
{true, 0.0} // spare 3
|
|
|
|
};
|
|
|
|
|
2021-03-30 17:31:44 +00:00
|
|
|
//! Receiver audio output; defaults to un
|
|
|
|
muted.
|
2021-03-17 04:11:17 +00:00
|
|
|
AudioChannel rxOut[NUM_RX_AUDIO_OUT] = {
|
|
|
|
{false, 1.0}, // line
|
|
|
|
{false, 1.0} // USB
|
|
|
|
};
|
2021-03-16 23:37:14 +00:00
|
|
|
|
|
|
|
//! Transmitter audio inputs; all default to muted.
|
|
|
|
AudioChannel txIn[NUM_TX_AUDIO_CH] = {
|
2021-03-15 04:18:24 +00:00
|
|
|
{true, 0.1}, // line
|
|
|
|
{true, 0.1}, // USB
|
|
|
|
{true, 0.1}, // tone 1
|
|
|
|
{true, 0.1} // tone 2
|
|
|
|
};
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
//! Tranmitter audio output; defaults to muted.
|
|
|
|
AudioChannel txOut = {true, 1.0};
|
|
|
|
|
|
|
|
//! Current RX filter settings
|
2021-03-30 17:31:44 +00:00
|
|
|
float rxFilterLo = 300.0;
|
|
|
|
float rxFilterHi = 3000.0;
|
2021-01-30 06:02:57 +00:00
|
|
|
};
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
/*!
|
|
|
|
* Defines the DSP subsystem of the UBitx V5X.
|
|
|
|
* The DSP subsystem, which relies on the Teensy Audio Library, is
|
|
|
|
* responsible for setting up the audio inputs and outputs for both
|
|
|
|
* receive (RX) and transmit (TX) audio, maintaining the correct path
|
|
|
|
* between inputs and outputs based on current TX/RX state, and setting
|
|
|
|
* up audio filters and other audio-based modules for the RX and TX
|
|
|
|
* audio paths.
|
|
|
|
*/
|
2021-01-30 06:02:57 +00:00
|
|
|
class UBitxDSP {
|
2021-03-15 04:18:24 +00:00
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
/********************************************************************
|
|
|
|
* Object creation/deletion
|
|
|
|
********************************************************************/
|
|
|
|
|
2021-03-15 04:18:24 +00:00
|
|
|
public:
|
2021-03-16 23:37:14 +00:00
|
|
|
UBitxDSP() {}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Basic administration
|
|
|
|
********************************************************************/
|
2021-03-15 04:18:24 +00:00
|
|
|
|
|
|
|
public:
|
2021-01-30 06:02:57 +00:00
|
|
|
void begin();
|
2021-02-10 04:58:07 +00:00
|
|
|
void update();
|
2021-03-15 04:18:24 +00:00
|
|
|
void end();
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
/********************************************************************
|
|
|
|
* Transmit/Receive switching
|
|
|
|
********************************************************************/
|
2021-03-15 04:18:24 +00:00
|
|
|
|
|
|
|
public:
|
2021-01-30 06:02:57 +00:00
|
|
|
void rx();
|
2021-03-05 05:12:41 +00:00
|
|
|
inline void tx() { tx(txSrc); }
|
|
|
|
void tx(TxAudioIn src);
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
/********************************************************************
|
|
|
|
* General audio setup -- called via begin()
|
|
|
|
********************************************************************/
|
2021-02-13 04:19:14 +00:00
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
protected:
|
|
|
|
virtual void setupRxAudio();
|
|
|
|
virtual void setupTxAudio();
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Receive audio chain
|
|
|
|
********************************************************************/
|
2021-02-13 04:19:14 +00:00
|
|
|
|
2021-03-15 04:18:24 +00:00
|
|
|
// Basic control of RX audio inputs and outputs.
|
|
|
|
public:
|
2021-03-17 04:11:17 +00:00
|
|
|
void setRxInLevel(RxAudioCh ch, float level); // Set the audio input level for a given channel.
|
|
|
|
void muteRxIn(); // Mute all RX audio input channels.
|
|
|
|
void muteRxIn(RxAudioCh ch); // Mute a specific RX audio input channel.
|
|
|
|
void unmuteRxIn(RxAudioCh ch); // Un-mute a specific RX audio input channel.
|
|
|
|
|
|
|
|
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).
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
/********************************************************************
|
|
|
|
* Transmit audio chain
|
|
|
|
********************************************************************/
|
2021-03-15 04:18:24 +00:00
|
|
|
|
|
|
|
// Basic control of TX audio inputs and outputs.
|
|
|
|
public:
|
|
|
|
void setTxInLevel(TxAudioCh ch, float level); // Set the audio input level for a given channel.
|
|
|
|
void muteTxIn(); // Mute all TX audio input channels.
|
|
|
|
void muteTxIn(TxAudioCh ch); // Mute a specific TX audio input channel.
|
|
|
|
void unmuteTxIn(TxAudioCh ch); // Un-mute a specific TX audio input channel.
|
2021-03-17 04:11:17 +00:00
|
|
|
|
2021-03-15 04:18:24 +00:00
|
|
|
void setTxOutLevel(float level); // Set the TX audio output level.
|
|
|
|
void muteTxOut(); // Mute the TX audio output.
|
|
|
|
void unmuteTxOut(); // Un-mute the TX audio output.
|
2021-03-17 04:11:17 +00:00
|
|
|
|
|
|
|
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).
|
|
|
|
|
2021-03-15 04:18:24 +00:00
|
|
|
// 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.
|
|
|
|
|
2021-03-30 17:31:44 +00:00
|
|
|
// Mic input controls.
|
|
|
|
public:
|
|
|
|
inline void setMicGain(float level) { micGain = static_cast<unsigned>(level * 63.0); } // Set the mic gain.
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
/********************************************************************
|
|
|
|
* Receive audio filter (band pass)
|
|
|
|
********************************************************************/
|
2021-03-15 04:18:24 +00:00
|
|
|
|
|
|
|
public:
|
2021-02-13 04:19:14 +00:00
|
|
|
void bypassRxFilter();
|
2021-03-16 23:37:14 +00:00
|
|
|
void updateRxFilter();
|
|
|
|
|
2021-03-30 17:31:44 +00:00
|
|
|
void setRxFilter(float lo, float hi);
|
|
|
|
void setRxFilterLo(float lo);
|
|
|
|
void setRxFilterHi(float hi);
|
|
|
|
void setRxFilterWidth(float width);
|
|
|
|
void setRxFilterCenter(float center);
|
2021-02-13 04:19:14 +00:00
|
|
|
|
|
|
|
/*!
|
2021-03-16 23:37:14 +00:00
|
|
|
* Get the current low frequency bound of the RX band pass filter.
|
2021-02-13 04:19:14 +00:00
|
|
|
* @return The low frequency bound.
|
|
|
|
*/
|
2021-03-30 17:31:44 +00:00
|
|
|
inline float getRxFilterLo() const { return state.rxFilterLo; }
|
2021-02-13 04:19:14 +00:00
|
|
|
|
|
|
|
/*!
|
2021-03-16 23:37:14 +00:00
|
|
|
* Get the current high frequency bound of the RX band pass filter.
|
2021-02-13 04:19:14 +00:00
|
|
|
* @return The high frequency bound.
|
|
|
|
*/
|
2021-03-30 17:31:44 +00:00
|
|
|
inline float getRxFilterHi() const { return state.rxFilterHi; }
|
2021-02-13 04:19:14 +00:00
|
|
|
|
|
|
|
/*!
|
2021-03-16 23:37:14 +00:00
|
|
|
* Get the current width of the RX band pass filter.
|
2021-02-13 04:19:14 +00:00
|
|
|
* @return The filter width.
|
|
|
|
*/
|
2021-03-30 17:31:44 +00:00
|
|
|
inline float getRxFilterWidth() const { return state.rxFilterHi - state.rxFilterLo; }
|
2021-02-13 04:19:14 +00:00
|
|
|
|
|
|
|
/*!
|
2021-03-16 23:37:14 +00:00
|
|
|
* Get the current center frequency of the RX band pass filter.
|
2021-02-13 04:19:14 +00:00
|
|
|
* @return The center frequency.
|
|
|
|
*/
|
2021-03-30 17:31:44 +00:00
|
|
|
inline float getRxFilterCenter() const { return (state.rxFilterHi + state.rxFilterLo) / 2.0; }
|
2021-02-13 04:19:14 +00:00
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
/********************************************************************
|
|
|
|
* Transmit Voice-Operated-Switch (VOX)
|
|
|
|
********************************************************************/
|
2021-02-13 04:19:14 +00:00
|
|
|
|
2021-03-30 17:31:44 +00:00
|
|
|
public:
|
|
|
|
float getVoxLevel() const;
|
2021-03-17 04:11:17 +00:00
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
/********************************************************************
|
|
|
|
* Private state
|
|
|
|
********************************************************************/
|
|
|
|
|
2021-02-13 04:19:14 +00:00
|
|
|
private:
|
2021-03-16 23:37:14 +00:00
|
|
|
DSPState state;
|
2021-03-05 05:12:41 +00:00
|
|
|
|
|
|
|
bool isTx = false;
|
2021-03-16 23:37:14 +00:00
|
|
|
TxAudioIn txSrc = MIC_IN;
|
|
|
|
TxAudioIn txSrcLatched = MIC_IN;
|
2021-02-13 04:19:14 +00:00
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
short coefficients[NUM_COEFFICIENTS] = {0};
|
|
|
|
|
|
|
|
elapsedMillis sinceLastUpdate = 0;
|
2021-03-15 04:18:24 +00:00
|
|
|
float usbVol = 0.0;
|
2021-03-05 05:12:41 +00:00
|
|
|
|
2021-03-30 17:31:44 +00:00
|
|
|
unsigned micGain = 0;
|
|
|
|
|
|
|
|
float prevVox = 0.0;
|
2021-01-30 06:02:57 +00:00
|
|
|
};
|
|
|
|
|
2021-03-16 23:37:14 +00:00
|
|
|
extern UBitxDSP& DSP;
|
2021-01-30 06:02:57 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//======================================================================
|
|
|
|
// EOF
|
|
|
|
//======================================================================
|