mirror of https://github.com/g4klx/MMDVM.git
Tighten incoming data, Add FM UpSampler
This commit is contained in:
parent
2cc6c1f68f
commit
994226e4b1
32
FM.cpp
32
FM.cpp
|
@ -87,7 +87,7 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length)
|
||||||
}
|
}
|
||||||
|
|
||||||
q15_t currentExtSample;
|
q15_t currentExtSample;
|
||||||
bool inputExt = m_inputExtRB.get(currentExtSample);//always consume the external input data so it does not overflow
|
bool inputExt = m_inputExtRB.getSample(currentExtSample);//always consume the external input data so it does not overflow
|
||||||
inputExt = inputExt && m_extEnabled;
|
inputExt = inputExt && m_extEnabled;
|
||||||
|
|
||||||
if (!inputExt && (CTCSS_NOT_READY(ctcssState)) && m_modemState != STATE_FM) {
|
if (!inputExt && (CTCSS_NOT_READY(ctcssState)) && m_modemState != STATE_FM) {
|
||||||
|
@ -691,35 +691,7 @@ uint8_t CFM::getSpace() const
|
||||||
|
|
||||||
uint8_t CFM::writeData(const uint8_t* data, uint8_t length)
|
uint8_t CFM::writeData(const uint8_t* data, uint8_t length)
|
||||||
{
|
{
|
||||||
for (uint8_t i = 0U; i < length; i += 3U) {
|
m_inputExtRB.addData(data, length);
|
||||||
uint16_t sample1 = 0U;
|
|
||||||
uint16_t sample2 = 0U;
|
|
||||||
uint32_t MASK = 0x00000FFFU;
|
|
||||||
|
|
||||||
uint32_t pack = 0U;
|
|
||||||
uint8_t* packPointer = (uint8_t*)&pack;
|
|
||||||
|
|
||||||
packPointer[1U] = data[i];
|
|
||||||
packPointer[2U] = data[i + 1U];
|
|
||||||
packPointer[3U] = data[i + 2U];
|
|
||||||
|
|
||||||
sample2 = uint16_t(pack & MASK);
|
|
||||||
sample1 = uint16_t(pack >> 12);
|
|
||||||
|
|
||||||
// Convert from uint16_t (0 - +4095) to Q15 (-2048 - +2047).
|
|
||||||
// Incoming data has sample rate 8kHz, just add 2 empty samples after
|
|
||||||
// every incoming sample to upsample to 24kHz
|
|
||||||
m_inputExtRB.put(q15_t(sample1) - 2048);
|
|
||||||
m_inputExtRB.put(0);
|
|
||||||
m_inputExtRB.put(0);
|
|
||||||
m_inputExtRB.put(q15_t(sample2) - 2048);
|
|
||||||
m_inputExtRB.put(0);
|
|
||||||
m_inputExtRB.put(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Received audio is now in Q15 format in samples, with length nSamples.
|
|
||||||
|
|
||||||
return 0U;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFM::insertDelay(uint16_t ms)
|
void CFM::insertDelay(uint16_t ms)
|
||||||
|
|
3
FM.h
3
FM.h
|
@ -30,6 +30,7 @@
|
||||||
#include "RingBuffer.h"
|
#include "RingBuffer.h"
|
||||||
#include "FMDirectForm1.h"
|
#include "FMDirectForm1.h"
|
||||||
#include "FMDownsampler.h"
|
#include "FMDownsampler.h"
|
||||||
|
#include "FMUpSampler.h"
|
||||||
|
|
||||||
enum FM_STATE {
|
enum FM_STATE {
|
||||||
FS_LISTENING,
|
FS_LISTENING,
|
||||||
|
@ -98,7 +99,7 @@ private:
|
||||||
q15_t m_rxLevel;
|
q15_t m_rxLevel;
|
||||||
CRingBuffer<q15_t> m_inputRFRB;
|
CRingBuffer<q15_t> m_inputRFRB;
|
||||||
CRingBuffer<q15_t> m_outputRFRB;
|
CRingBuffer<q15_t> m_outputRFRB;
|
||||||
CRingBuffer<q15_t> m_inputExtRB;
|
CFMUpSampler m_inputExtRB;
|
||||||
|
|
||||||
void stateMachine(bool validRFSignal, bool validExtSignal);
|
void stateMachine(bool validRFSignal, bool validExtSignal);
|
||||||
void listeningState(bool validRFSignal, bool validExtSignal);
|
void listeningState(bool validRFSignal, bool validExtSignal);
|
||||||
|
|
|
@ -22,12 +22,7 @@
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "RingBuffer.h"
|
#include "RingBuffer.h"
|
||||||
|
#include "FMSamplePairPack.h"
|
||||||
struct TSamplePairPack {
|
|
||||||
uint8_t byte0;
|
|
||||||
uint8_t byte1;
|
|
||||||
uint8_t byte2;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CFMDownsampler {
|
class CFMDownsampler {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
||||||
|
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(TSAMPLEPACK_H)
|
||||||
|
#define TSAMPLEPACK_H
|
||||||
|
|
||||||
|
struct TSamplePairPack {
|
||||||
|
uint8_t byte0;
|
||||||
|
uint8_t byte1;
|
||||||
|
uint8_t byte2;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,89 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
||||||
|
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
||||||
|
*
|
||||||
|
* 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 "FMUpSampler.h"
|
||||||
|
|
||||||
|
const uint32_t FM_UPSAMPLE_MASK = 0x00000FFFU;
|
||||||
|
|
||||||
|
CFMUpSampler::CFMUpSampler(uint16_t length) :
|
||||||
|
m_upSampleIndex(0),
|
||||||
|
m_pack({0U, 0U, 0U}),
|
||||||
|
m_samples(length)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFMUpSampler::reset()
|
||||||
|
{
|
||||||
|
m_upSampleIndex = 0U;
|
||||||
|
m_pack = {0U, 0U, 0U};
|
||||||
|
m_samples.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFMUpSampler::addData(const uint8_t* data, uint16_t length)
|
||||||
|
{
|
||||||
|
for(uint16_t i = 0U; i < length; i++) {
|
||||||
|
switch (m_upSampleIndex)
|
||||||
|
{
|
||||||
|
case 0U:
|
||||||
|
m_pack.byte0 = data[i];
|
||||||
|
break;
|
||||||
|
case 1U:
|
||||||
|
m_pack.byte1 = data[i];
|
||||||
|
break;
|
||||||
|
case 2U: {
|
||||||
|
m_pack.byte2 = data[i];
|
||||||
|
|
||||||
|
uint32_t pack = 0U;
|
||||||
|
uint8_t* packPtr = (uint8_t*)&pack;
|
||||||
|
|
||||||
|
packPtr[1] = m_pack.byte0;
|
||||||
|
packPtr[2] = m_pack.byte1;
|
||||||
|
packPtr[3] = m_pack.byte2;
|
||||||
|
|
||||||
|
q15_t sample2 = q15_t(uint16_t(pack & FM_UPSAMPLE_MASK) - 2048);
|
||||||
|
q15_t sample1 = q15_t(uint16_t(pack >> 12) - 2048);
|
||||||
|
|
||||||
|
m_samples.put(sample1);
|
||||||
|
m_samples.put(0);
|
||||||
|
m_samples.put(0);
|
||||||
|
m_samples.put(sample2);
|
||||||
|
m_samples.put(0);
|
||||||
|
m_samples.put(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//shoudl never happen
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_upSampleIndex ++;
|
||||||
|
if (m_upSampleIndex > 2U)
|
||||||
|
m_upSampleIndex = 0U;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CFMUpSampler::getSample(q15_t& sample)
|
||||||
|
{
|
||||||
|
return m_samples.get(sample);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t CFMUpSampler::getSpace() const
|
||||||
|
{
|
||||||
|
return m_samples.getSpace();
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
||||||
|
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(FMUPSAMPLER_H)
|
||||||
|
#define FMUPSAMPLER_H
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
#include "RingBuffer.h"
|
||||||
|
#include "FMSamplePairPack.h"
|
||||||
|
|
||||||
|
class CFMUpSampler {
|
||||||
|
public:
|
||||||
|
CFMUpSampler(uint16_t length);
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
void addData(const uint8_t* data, uint16_t length);
|
||||||
|
|
||||||
|
bool getSample(q15_t& sample);
|
||||||
|
|
||||||
|
uint16_t getSpace() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t m_upSampleIndex;
|
||||||
|
TSamplePairPack m_pack;
|
||||||
|
CRingBuffer<q15_t> m_samples;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue