mirror of https://github.com/g4klx/MMDVM.git
(almost) One loop to rule all the samples
Avoid looping over and over the samples. One
This commit is contained in:
parent
87c3b57ae4
commit
8d340cbfba
49
FM.cpp
49
FM.cpp
|
@ -31,7 +31,6 @@ q15_t FILTER_COEFFS[] = {
|
|||
|
||||
const uint16_t FILTER_COEFFS_LEN = 101U;
|
||||
|
||||
const uint16_t OUTPUT_BUFFER_SIZE = 1000U;
|
||||
|
||||
CFM::CFM() :
|
||||
m_filter(),
|
||||
|
@ -50,8 +49,7 @@ m_holdoffTimer(),
|
|||
m_kerchunkTimer(),
|
||||
m_ackMinTimer(),
|
||||
m_ackDelayTimer(),
|
||||
m_hangTimer(),
|
||||
m_ringBuffer(OUTPUT_BUFFER_SIZE)
|
||||
m_hangTimer()
|
||||
{
|
||||
::memset(m_filterState, 0x00U, 230U * sizeof(q15_t));
|
||||
|
||||
|
@ -69,50 +67,31 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length)
|
|||
if (m_modemState != STATE_FM)
|
||||
return;
|
||||
|
||||
q15_t currentSample;
|
||||
for(uint8_t i = 0U; i < length; i++) {
|
||||
// Only let audio through when relaying audio
|
||||
// if (m_state != FS_RELAYING && m_state != FS_KERCHUNK) {
|
||||
// for (uint8_t i = 0U; i < length; i++)
|
||||
// samples[i] = 0;
|
||||
// }
|
||||
currentSample = samples[i];//save to a local variable to avoid indirection on every access
|
||||
if (m_state != FS_RELAYING && m_state != FS_KERCHUNK) {
|
||||
currentSample = 0U;
|
||||
}
|
||||
|
||||
/*if (!m_callsign.isRunning())
|
||||
m_rfAck.getAudio(samples, length);
|
||||
if(!m_callsign.isRunning())
|
||||
currentSample = m_rfAck.getAudio(currentSample);
|
||||
|
||||
if (!m_rfAck.isRunning())
|
||||
m_callsign.getAudio(samples, length);
|
||||
if(!m_rfAck.isRunning())
|
||||
currentSample = m_rfAck.getAudio(currentSample);
|
||||
|
||||
if (!m_callsign.isRunning() && !m_rfAck.isRunning())
|
||||
m_timeoutTone.getAudio(samples, length);
|
||||
currentSample = m_timeoutTone.getAudio(currentSample);
|
||||
|
||||
q15_t output[RX_BLOCK_SIZE];
|
||||
::arm_fir_fast_q15(&m_filter, samples, output, length);
|
||||
|
||||
m_ctcssTX.getAudio(output, length);*/
|
||||
samples[i] = currentSample;
|
||||
}
|
||||
|
||||
io.write(STATE_FM, samples, length);
|
||||
|
||||
// for (uint8_t i = 0U; i < length; i++) {
|
||||
// bool ret = m_ringBuffer.put(output[i]);
|
||||
// if (!ret) {
|
||||
// DEBUG1("Overflow in the FM ring buffer");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void CFM::process()
|
||||
{
|
||||
// uint16_t space = io.getSpace();
|
||||
// uint16_t data = m_ringBuffer.getData();
|
||||
// if (data < space)
|
||||
// space = data;
|
||||
|
||||
// for (uint16_t i = 0U; i < space; i++) {
|
||||
// q15_t sample;
|
||||
// m_ringBuffer.get(sample);
|
||||
|
||||
// io.write(STATE_FM, &sample, 1U);
|
||||
// }
|
||||
}
|
||||
|
||||
void CFM::reset()
|
||||
|
|
1
FM.h
1
FM.h
|
@ -70,7 +70,6 @@ private:
|
|||
CFMTimer m_ackMinTimer;
|
||||
CFMTimer m_ackDelayTimer;
|
||||
CFMTimer m_hangTimer;
|
||||
CFMRB m_ringBuffer;
|
||||
|
||||
void stateMachine(bool validSignal, uint8_t length);
|
||||
void listeningState(bool validSignal);
|
||||
|
|
|
@ -109,9 +109,6 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold)
|
|||
|
||||
bool CFMCTCSSRX::process(q15_t* samples, uint8_t length)
|
||||
{
|
||||
//float32_t data[RX_BLOCK_SIZE];
|
||||
//::arm_q15_to_float(samples, data, length);
|
||||
|
||||
for (unsigned int i = 0U; i < length; i++) {
|
||||
float32_t q2 = m_q1;
|
||||
m_q1 = m_q0;
|
||||
|
@ -121,7 +118,7 @@ bool CFMCTCSSRX::process(q15_t* samples, uint8_t length)
|
|||
if (m_count == N) {
|
||||
float32_t value = m_q0 * m_q0 + m_q1 * m_q1 - m_q0 * m_q1 * m_coeff;
|
||||
m_result = value >= m_threshold;
|
||||
DEBUG4("CTCSS value / threshold / result", value, m_threshold, m_result);
|
||||
//DEBUG4("CTCSS value / threshold / result", value, m_threshold, m_result);
|
||||
m_count = 0U;
|
||||
m_q0 = 0.0F;
|
||||
m_q1 = 0.0F;
|
||||
|
|
|
@ -125,3 +125,12 @@ void CFMCTCSSTX::getAudio(q15_t* samples, uint8_t length)
|
|||
m_n = 0U;
|
||||
}
|
||||
}
|
||||
|
||||
q15_t CFMCTCSSTX::getAudio(q15_t sample)
|
||||
{
|
||||
sample += m_values[m_n++];
|
||||
if(m_n >= m_length)
|
||||
m_n = 0U;
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
uint8_t setParams(uint8_t frequency, uint8_t level);
|
||||
|
||||
void getAudio(q15_t* samples, uint8_t length);
|
||||
inline q15_t getAudio(q15_t sample);
|
||||
|
||||
private:
|
||||
q15_t* m_values;
|
||||
|
|
26
FMKeyer.cpp
26
FMKeyer.cpp
|
@ -152,6 +152,32 @@ void CFMKeyer::getAudio(q15_t* samples, uint8_t length)
|
|||
}
|
||||
}
|
||||
|
||||
q15_t CFMKeyer::getAudio(q15_t sample)
|
||||
{
|
||||
if (!m_wanted)
|
||||
return 0U; //TODO F4FXL, not sure what to do here
|
||||
|
||||
q15_t output;
|
||||
bool b = READ_BIT(m_poBuffer, m_poPos);
|
||||
if (b)
|
||||
output = sample + m_audio[m_audioPos];
|
||||
|
||||
m_audioPos++;
|
||||
if (m_audioPos >= m_audioLen)
|
||||
m_audioPos = 0U;
|
||||
m_dotPos++;
|
||||
if (m_dotPos >= m_dotLen) {
|
||||
m_dotPos = 0U;
|
||||
m_poPos++;
|
||||
if (m_poPos >= m_poLen) {
|
||||
stop();
|
||||
return sample;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void CFMKeyer::start()
|
||||
{
|
||||
if (isRunning())
|
||||
|
|
|
@ -29,6 +29,8 @@ public:
|
|||
|
||||
void getAudio(q15_t* samples, uint8_t length);
|
||||
|
||||
q15_t getAudio(q15_t sample);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
|
|
|
@ -62,6 +62,26 @@ void CFMTimeout::getAudio(q15_t* samples, uint8_t length)
|
|||
}
|
||||
}
|
||||
|
||||
q15_t CFMTimeout::getAudio(q15_t sample)
|
||||
{
|
||||
if (m_pos > 12000U) {
|
||||
q31_t sample = BUSY_AUDIO[m_n] * m_level;
|
||||
sample = q15_t(__SSAT((sample >> 15), 16));
|
||||
|
||||
m_n++;
|
||||
if (m_n >= BUSY_AUDIO_LEN)
|
||||
m_n = 0U;
|
||||
} else {
|
||||
sample = 0U;
|
||||
}
|
||||
|
||||
m_pos++;
|
||||
if (m_pos >= 24000U)
|
||||
m_pos = 0U;
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
void CFMTimeout::start()
|
||||
{
|
||||
m_running = true;
|
||||
|
|
|
@ -32,6 +32,8 @@ public:
|
|||
|
||||
void getAudio(q15_t* samples, uint8_t length);
|
||||
|
||||
q15_t getAudio(q15_t sample);
|
||||
|
||||
private:
|
||||
q15_t m_level;
|
||||
bool m_running;
|
||||
|
|
Loading…
Reference in New Issue