mirror of
https://github.com/g4klx/MMDVM.git
synced 2026-05-07 13:37:48 +00:00
Add FM Cal modes
This commit is contained in:
parent
d66c6d7f9c
commit
5156ca13b7
7 changed files with 236 additions and 6 deletions
144
CalFM.cpp
Normal file
144
CalFM.cpp
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2015 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2016 by Colin Durbridge G4EML
|
||||
* Copyright (C) 2020 by Phil Taylor M0VSE
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "Config.h"
|
||||
#include "Globals.h"
|
||||
#include "CalFM.h"
|
||||
|
||||
|
||||
/*
|
||||
const struct TONE_TABLE {
|
||||
uint16_t frequency;
|
||||
uint16_t length;
|
||||
q31_t increment;
|
||||
} TONE_TABLE_DATA[] = {
|
||||
{2495U, 10U, 140271371},
|
||||
{2079U, 12U, 116883439},
|
||||
{1633U, 15U, 91808877},
|
||||
{1247U, 20U, 70107575},
|
||||
{1039U, 24U, 58441775},
|
||||
{956U, 26U, 53747266}};
|
||||
*/
|
||||
|
||||
|
||||
const struct TONE_TABLE {
|
||||
uint16_t frequency;
|
||||
uint16_t length;
|
||||
q31_t increment;
|
||||
} TONE_TABLE_DATA[] = {
|
||||
{2495U, 10U, 223248821},
|
||||
{2079U, 12U, 186025771},
|
||||
{1633U, 15U, 148802721},
|
||||
{1247U, 20U, 111579672},
|
||||
{1039U, 24U, 93012886},
|
||||
{956U, 26U, 85541432}};
|
||||
|
||||
|
||||
const uint8_t TONE_TABLE_DATA_LEN = 6U;
|
||||
|
||||
CCalFM::CCalFM() :
|
||||
m_tone(NULL),
|
||||
m_frequency(0),
|
||||
m_length(0),
|
||||
m_level(128*128),
|
||||
m_transmit(false),
|
||||
m_lastState(STATE_IDLE),
|
||||
m_audioSeq(0)
|
||||
{
|
||||
}
|
||||
|
||||
void CCalFM::process()
|
||||
{
|
||||
const TONE_TABLE* entry = NULL;
|
||||
|
||||
if (m_modemState!=m_lastState)
|
||||
{
|
||||
switch (m_modemState) {
|
||||
case STATE_FMCAL10K:
|
||||
m_frequency=956U;
|
||||
break;
|
||||
case STATE_FMCAL12K:
|
||||
m_frequency=1039U;
|
||||
break;
|
||||
case STATE_FMCAL15K:
|
||||
m_frequency=1247U;
|
||||
break;
|
||||
case STATE_FMCAL20K:
|
||||
m_frequency=1633U;
|
||||
break;
|
||||
case STATE_FMCAL25K:
|
||||
m_frequency=2079U;
|
||||
break;
|
||||
case STATE_FMCAL30K:
|
||||
m_frequency=2495U;
|
||||
break;
|
||||
default:
|
||||
m_frequency=0;
|
||||
break;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0U; i < TONE_TABLE_DATA_LEN; i++) {
|
||||
if (TONE_TABLE_DATA[i].frequency == m_frequency) {
|
||||
entry = TONE_TABLE_DATA + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry == NULL)
|
||||
return;
|
||||
|
||||
m_length = entry->length;
|
||||
|
||||
delete[] m_tone;
|
||||
m_tone = new q15_t[m_length];
|
||||
|
||||
q31_t arg = 0;
|
||||
for (uint16_t i = 0U; i < m_length; i++) {
|
||||
q63_t value = ::arm_sin_q31(arg) * q63_t(m_level * 13);
|
||||
m_tone[i] = q15_t(__SSAT((value >> 31), 16));
|
||||
|
||||
arg += entry->increment;
|
||||
}
|
||||
|
||||
m_lastState=m_modemState;
|
||||
}
|
||||
|
||||
if (m_transmit)
|
||||
{
|
||||
uint16_t space = io.getSpace();
|
||||
while (space > m_length)
|
||||
{
|
||||
io.write(m_modemState,m_tone,m_length);
|
||||
space -= m_length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t CCalFM::write(const uint8_t* data, uint8_t length)
|
||||
{
|
||||
if (length != 1U)
|
||||
return 4U;
|
||||
|
||||
m_transmit = data[0U] == 1U;
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue