150 lines
3.7 KiB
C++
150 lines
3.7 KiB
C++
//======================================================================
|
|
// DSP.cpp
|
|
//======================================================================
|
|
|
|
#include "DSP.h"
|
|
|
|
#include <Audio.h>
|
|
#include <i2c_t3.h>
|
|
//#include <Wire.h>
|
|
//#include <SPI.h>
|
|
//#include <SD.h>
|
|
//#include <SerialFlash.h>
|
|
|
|
#define RX_AUDIO_CH 0
|
|
|
|
#define TX_MIC_IN_CH 0
|
|
#define TX_LINE_IN_CH 0
|
|
#define TX_USB_IN_CH1 1
|
|
#define TX_USB_IN_CH2 2
|
|
|
|
UBitxDSP DSP;
|
|
|
|
//static struct {
|
|
|
|
// GUItool: begin automatically generated code
|
|
AudioInputI2S lineIn; //xy=137,220
|
|
AudioInputUSB usbIn; //xy=142,326
|
|
AudioMixer4 rxAudio; //xy=394,134
|
|
AudioMixer4 txAudio; //xy=398,322
|
|
AudioOutputAnalog spkrOut; //xy=774,104
|
|
AudioOutputUSB usbOut; //xy=774,138
|
|
AudioOutputI2S lineOut; //xy=776,236
|
|
AudioConnection patchCord1(lineIn, 0, rxAudio, 0);
|
|
AudioConnection patchCord2(lineIn, 1, txAudio, 0);
|
|
AudioConnection patchCord3(usbIn, 0, txAudio, 1);
|
|
AudioConnection patchCord4(usbIn, 1, txAudio, 2);
|
|
AudioConnection patchCord5(rxAudio, spkrOut);
|
|
AudioConnection patchCord6(rxAudio, 0, lineOut, 0);
|
|
AudioConnection patchCord7(rxAudio, 0, usbOut, 0);
|
|
AudioConnection patchCord8(rxAudio, 0, usbOut, 1);
|
|
AudioConnection patchCord9(txAudio, 0, lineOut, 1);
|
|
AudioControlSGTL5000 audioCtrl; //xy=403,463
|
|
// GUItool: end automatically generated code
|
|
|
|
//} audio;
|
|
|
|
void UBitxDSP::begin() {
|
|
AudioMemory(20);
|
|
audioCtrl.enable();
|
|
audioCtrl.volume(0.0); // headphone volume...
|
|
audioCtrl.muteHeadphone(); // ...not used by UBitxDSP
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
if (i == RX_AUDIO_CH)
|
|
rxAudio.gain(i, 1.0);
|
|
else
|
|
rxAudio.gain(i, 0.0);
|
|
}
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
txAudio.gain(i, 0.0);
|
|
}
|
|
|
|
// SETUP THE AUDIO INPUTS
|
|
|
|
// Rig (Line) Input (RX)
|
|
audioCtrl.inputSelect(AUDIO_INPUT_LINEIN);
|
|
audioCtrl.unmuteLineout();
|
|
audioCtrl.lineInLevel(5, 5); // RX, TX
|
|
audioCtrl.lineOutLevel(29, 29); //RX, TX
|
|
|
|
// Mic Input (TX)
|
|
audioCtrl.micGain(0); // TODO: set value
|
|
|
|
// Line Input (TX)
|
|
|
|
// USB Input (TX)
|
|
|
|
// SETUP THE AUDIO OUTPUTS
|
|
|
|
// Speaker Output (RX)
|
|
spkrOut.analogReference(INTERNAL);
|
|
|
|
// Line Output (RX)
|
|
|
|
// USB Output (RX)
|
|
|
|
// Rig (Line) Output (TX)
|
|
|
|
// Default to RX.
|
|
rx();
|
|
}
|
|
|
|
void UBitxDSP::end() {
|
|
}
|
|
|
|
void UBitxDSP::rx() {
|
|
// mute all tx audio
|
|
for (int i = 0; i < 4; i++) {
|
|
txAudio.gain(i, 0.0);
|
|
}
|
|
// select line in for rx
|
|
audioCtrl.inputSelect(AUDIO_INPUT_LINEIN);
|
|
// restore rx audio
|
|
rxAudio.gain(RX_AUDIO_CH, 1.0); // restore the RX audio
|
|
}
|
|
|
|
void UBitxDSP::txMicIn() {
|
|
// mute the rx audio
|
|
rxAudio.gain(RX_AUDIO_CH, 0.0);
|
|
// restore the tx mic audio
|
|
audioCtrl.inputSelect(AUDIO_INPUT_MIC);
|
|
for (int i = 0; i < 4; i++) {
|
|
if (i == TX_MIC_IN_CH)
|
|
txAudio.gain(i, 1.0);
|
|
else
|
|
txAudio.gain(i, 0.0);
|
|
}
|
|
}
|
|
|
|
void UBitxDSP::txLineIn() {
|
|
// mute the rx audio
|
|
rxAudio.gain(RX_AUDIO_CH, 0.0);
|
|
// restore the tx line in audio
|
|
audioCtrl.inputSelect(AUDIO_INPUT_LINEIN);
|
|
for (int i = 0; i < 4; i++) {
|
|
if (i == TX_LINE_IN_CH)
|
|
txAudio.gain(i, 1.0);
|
|
else
|
|
txAudio.gain(i, 0.0);
|
|
}
|
|
}
|
|
|
|
void UBitxDSP::txUSBIn() {
|
|
// mute the rx audio
|
|
rxAudio.gain(RX_AUDIO_CH, 0.0);
|
|
// restore the tx usb in audio
|
|
audioCtrl.inputSelect(AUDIO_INPUT_LINEIN);
|
|
for (int i = 0; i < 4; i++) {
|
|
if (i == TX_USB_IN_CH1 || i == TX_USB_IN_CH2)
|
|
txAudio.gain(i, 1.0);
|
|
else
|
|
txAudio.gain(i, 0.0);
|
|
}
|
|
}
|
|
|
|
//======================================================================
|
|
// EOF
|
|
//======================================================================
|