Buffer incoming modem audio

This commit is contained in:
Geoffrey Merck
2020-05-10 21:49:11 +02:00
parent 33fedb781d
commit 0178ba0aba
2 changed files with 51 additions and 36 deletions

View File

@@ -21,12 +21,14 @@
#include <string> #include <string>
#define EMPHASIS_GAIN_DB 0 //Gain needs to be the same for pre an deeemphasis #define EMPHASIS_GAIN_DB 0 //Gain needs to be the same for pre an deeemphasis
#define RF_AUDIO_SAMP_RATE 8000
CFMControl::CFMControl(CFMNetwork* network) : CFMControl::CFMControl(CFMNetwork* network) :
m_network(network), m_network(network),
m_enabled(false), m_enabled(false),
m_preemphasis(0.3889703087993727F, -0.3290005228984741F, 0.0F, 1.0F, 0.282029168302153F, 0.0F, EMPHASIS_GAIN_DB), // m_preemphasis(0.3889703087993727F, -0.3290005228984741F, 0.0F, 1.0F, 0.282029168302153F, 0.0F, EMPHASIS_GAIN_DB),
m_deemphasis(1.0F, 0.282029168302153F, 0.0F, 0.3889703087993727F, -0.3290005228984741F, 0.0F, EMPHASIS_GAIN_DB) // m_deemphasis(1.0F, 0.282029168302153F, 0.0F, 0.3889703087993727F, -0.3290005228984741F, 0.0F, EMPHASIS_GAIN_DB),
m_incomingRFAudio(1000U, "Incoming RF FM Audio")
{ {
} }
@@ -45,6 +47,15 @@ bool CFMControl::writeModem(const unsigned char* data, unsigned int length)
float samples[170U]; float samples[170U];
unsigned int nSamples = 0U; unsigned int nSamples = 0U;
m_incomingRFAudio.addData(data, length);
unsigned int bufferLength = m_incomingRFAudio.dataSize();
if(bufferLength >= 3) {
bufferLength = bufferLength - bufferLength % 3; //round down to nearest multiple of 3
unsigned char bufferData[bufferLength];
m_incomingRFAudio.getData(bufferData, bufferLength);
// Unpack the serial data into float values. // Unpack the serial data into float values.
for (unsigned int i = 0U; i < length; i += 3U) { for (unsigned int i = 0U; i < length; i += 3U) {
unsigned short sample1 = 0U; unsigned short sample1 = 0U;
@@ -54,9 +65,9 @@ bool CFMControl::writeModem(const unsigned char* data, unsigned int length)
unsigned int pack = 0U; unsigned int pack = 0U;
unsigned char* packPointer = (unsigned char*)&pack; unsigned char* packPointer = (unsigned char*)&pack;
packPointer[1U] = data[i]; packPointer[1U] = bufferData[i];
packPointer[2U] = data[i + 1U]; packPointer[2U] = bufferData[i + 1U];
packPointer[3U] = data[i + 2U]; packPointer[3U] = bufferData[i + 2U];
sample2 = (short)(pack & MASK); sample2 = (short)(pack & MASK);
sample1 = (short)(pack >> 12); sample1 = (short)(pack >> 12);
@@ -67,8 +78,8 @@ bool CFMControl::writeModem(const unsigned char* data, unsigned int length)
} }
// De-emphasise the data and any other processing needed (maybe a low-pass filter to remove the CTCSS) // De-emphasise the data and any other processing needed (maybe a low-pass filter to remove the CTCSS)
for (unsigned int i = 0U; i < nSamples; i++) // for (unsigned int i = 0U; i < nSamples; i++)
samples[i] = m_deemphasis.filter(samples[i]); // samples[i] = m_deemphasis.filter(samples[i]);
unsigned char out[350U]; unsigned char out[350U];
unsigned int nOut = 0U; unsigned int nOut = 0U;
@@ -83,6 +94,9 @@ bool CFMControl::writeModem(const unsigned char* data, unsigned int length)
return m_network->write(out, nOut); return m_network->write(out, nOut);
} }
return 0U;
}
unsigned int CFMControl::readModem(unsigned char* data, unsigned int space) unsigned int CFMControl::readModem(unsigned char* data, unsigned int space)
{ {
assert(data != NULL); assert(data != NULL);
@@ -105,8 +119,8 @@ unsigned int CFMControl::readModem(unsigned char* data, unsigned int space)
} }
// Pre-emphasise the data and other stuff. // Pre-emphasise the data and other stuff.
for (unsigned int i = 0U; i < nSamples; i++) // for (unsigned int i = 0U; i < nSamples; i++)
samples[i] = m_preemphasis.filter(samples[i]); // samples[i] = m_preemphasis.filter(samples[i]);
// Pack the floating point data (+1.0 to -1.0) to packed 12-bit samples (+2047 - -2048) // Pack the floating point data (+1.0 to -1.0) to packed 12-bit samples (+2047 - -2048)
unsigned int pack = 0U; unsigned int pack = 0U;

View File

@@ -39,8 +39,9 @@ public:
private: private:
CFMNetwork* m_network; CFMNetwork* m_network;
bool m_enabled; bool m_enabled;
CIIRDirectForm1Filter m_preemphasis; // CIIRDirectForm1Filter m_preemphasis;
CIIRDirectForm1Filter m_deemphasis; // CIIRDirectForm1Filter m_deemphasis;
CRingBuffer<unsigned char> m_incomingRFAudio;
}; };
#endif #endif