mirror of https://github.com/g4klx/MMDVM.git
Send usigned data and simplify downdamplign code
This commit is contained in:
parent
fa9f89700f
commit
81f6b6be53
|
@ -25,43 +25,38 @@ CFMDownsampler::CFMDownsampler(uint16_t length) :
|
||||||
m_ringBuffer(length),
|
m_ringBuffer(length),
|
||||||
m_samplePack(0U),
|
m_samplePack(0U),
|
||||||
m_samplePackPointer(NULL),
|
m_samplePackPointer(NULL),
|
||||||
m_packIndex(0U),
|
m_sampleIndex(0U)
|
||||||
m_downSampleIndex(0U)
|
|
||||||
{
|
{
|
||||||
m_samplePackPointer = (uint8_t*)&m_samplePack;
|
m_samplePackPointer = (uint8_t*)&m_samplePack;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFMDownsampler::addSample(q15_t sample)
|
void CFMDownsampler::addSample(q15_t sample)
|
||||||
{
|
{
|
||||||
//only take one of three samples
|
uint16_t usample = uint16_t(sample + 2048);
|
||||||
if(m_downSampleIndex == 0U) {
|
//only take one of three samples
|
||||||
switch(m_packIndex){
|
switch(m_sampleIndex){
|
||||||
case 0:
|
case 0:
|
||||||
m_samplePack = uint32_t(sample) << 12;
|
m_samplePack = uint32_t(usample) << 12;
|
||||||
break;
|
break;
|
||||||
case 1:{
|
case 3:{
|
||||||
m_samplePack |= uint32_t(sample);
|
m_samplePack |= uint32_t(usample);
|
||||||
|
|
||||||
//we did not use MSB; skip it
|
//we did not use MSB; skip it
|
||||||
TSamplePairPack pair{m_samplePackPointer[1U], m_samplePackPointer[2U], m_samplePackPointer[3U]};
|
TSamplePairPack pair{m_samplePackPointer[1U], m_samplePackPointer[2U], m_samplePackPointer[3U]};
|
||||||
|
|
||||||
m_ringBuffer.put(pair);
|
m_ringBuffer.put(pair);
|
||||||
|
|
||||||
m_samplePack = 0;//reset the sample pack
|
m_samplePack = 0U;//reset the sample pack
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//should never happen
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
m_packIndex++;
|
|
||||||
if(m_packIndex >= 2U)//did we pack two samples ?
|
|
||||||
m_packIndex = 0U;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//Just skip this sample
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
m_downSampleIndex++;
|
m_sampleIndex++;
|
||||||
if(m_downSampleIndex >= 3U)
|
if(m_sampleIndex >= 6U)//did we pack two samples ?
|
||||||
m_downSampleIndex = 0U;
|
m_sampleIndex = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFMDownsampler::getPackedData(TSamplePairPack& data)
|
bool CFMDownsampler::getPackedData(TSamplePairPack& data)
|
||||||
|
@ -76,6 +71,5 @@ uint16_t CFMDownsampler::getData()
|
||||||
|
|
||||||
void CFMDownsampler::reset()
|
void CFMDownsampler::reset()
|
||||||
{
|
{
|
||||||
m_downSampleIndex = 0;
|
m_sampleIndex = 0U;
|
||||||
m_packIndex = 0;
|
|
||||||
}
|
}
|
|
@ -38,8 +38,7 @@ private:
|
||||||
uint32_t m_samplePack;
|
uint32_t m_samplePack;
|
||||||
uint8_t *m_samplePackPointer;
|
uint8_t *m_samplePackPointer;
|
||||||
|
|
||||||
uint8_t m_packIndex;
|
uint8_t m_sampleIndex;
|
||||||
uint8_t m_downSampleIndex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue