Improve silence insertion.

This commit is contained in:
Jonathan Naylor 2016-07-11 20:08:14 +01:00
parent 58061be4c9
commit 495b3b6913
2 changed files with 19 additions and 9 deletions

View file

@ -515,7 +515,7 @@ void CDStarControl::writeNetwork()
unsigned char n = data[1U]; unsigned char n = data[1U];
insertSilence(data + 2U, n); insertSilence(data + 1U, n);
unsigned int errors = m_fec.regenerateDStar(data + 2U); unsigned int errors = m_fec.regenerateDStar(data + 2U);
@ -796,21 +796,20 @@ void CDStarControl::insertSilence(const unsigned char* data, unsigned char seqNo
assert(data != NULL); assert(data != NULL);
// Check to see if we have any spaces to fill? // Check to see if we have any spaces to fill?
unsigned char seq = (m_netN + 1U) % 21U; unsigned int oldSeqNo = (m_netN + 1U) % 21U;
if (seq == seqNo) { if (oldSeqNo == seqNo) {
// Just copy the data, nothing else to do here // Just copy the data, nothing else to do here
::memcpy(m_lastFrame, data, DSTAR_FRAME_LENGTH_BYTES + 1U); ::memcpy(m_lastFrame, data, DSTAR_FRAME_LENGTH_BYTES + 1U);
return; return;
} }
unsigned int oldSeqNo = (m_netN + 1U) % 21U; LogDebug("D-Star, current=%u last=%u", seqNo, m_netN);
unsigned int newSeqNo = seqNo;
unsigned int count; unsigned int count;
if (newSeqNo > oldSeqNo) if (seqNo > oldSeqNo)
count = newSeqNo - oldSeqNo; count = seqNo - oldSeqNo;
else else
count = (21U + newSeqNo) - oldSeqNo; count = (21U + seqNo) - oldSeqNo;
if (count < 10U) if (count < 10U)
insertSilence(count); insertSilence(count);
@ -820,11 +819,19 @@ void CDStarControl::insertSilence(const unsigned char* data, unsigned char seqNo
void CDStarControl::insertSilence(unsigned int count) void CDStarControl::insertSilence(unsigned int count)
{ {
LogDebug("D-Star, insert %u frames", count);
unsigned char n = (m_netN + 1U) % 21U; unsigned char n = (m_netN + 1U) % 21U;
for (unsigned int i = 0U; i < count; i++) { for (unsigned int i = 0U; i < count; i++) {
if (i < 3U) { if (i < 3U) {
writeQueueDataNet(m_lastFrame); if (n == 0U) {
::memcpy(m_lastFrame + DSTAR_VOICE_FRAME_LENGTH_BYTES + 1U, DSTAR_NULL_SLOW_SYNC_BYTES, DSTAR_DATA_FRAME_LENGTH_BYTES);
writeQueueDataNet(m_lastFrame);
} else {
::memcpy(m_lastFrame + DSTAR_VOICE_FRAME_LENGTH_BYTES + 1U, DSTAR_NULL_SLOW_DATA_BYTES, DSTAR_DATA_FRAME_LENGTH_BYTES);
writeQueueDataNet(m_lastFrame);
}
} else { } else {
if (n == 0U) if (n == 0U)
writeQueueDataNet(DSTAR_NULL_FRAME_SYNC_BYTES); writeQueueDataNet(DSTAR_NULL_FRAME_SYNC_BYTES);
@ -839,6 +846,8 @@ void CDStarControl::insertSilence(unsigned int count)
n = (n + 1U) % 21U; n = (n + 1U) % 21U;
} }
LogDebug("D-Star, last=%u", m_netN);
} }
void CDStarControl::blankDTMF(unsigned char* data) const void CDStarControl::blankDTMF(unsigned char* data) const

View file

@ -29,6 +29,7 @@ const unsigned int DSTAR_END_PATTERN_LENGTH_BYTES = 6U;
const unsigned char DSTAR_NULL_AMBE_DATA_BYTES[] = { 0x9E, 0x8D, 0x32, 0x88, 0x26, 0x1A, 0x3F, 0x61, 0xE8 }; const unsigned char DSTAR_NULL_AMBE_DATA_BYTES[] = { 0x9E, 0x8D, 0x32, 0x88, 0x26, 0x1A, 0x3F, 0x61, 0xE8 };
const unsigned char DSTAR_NULL_SLOW_SYNC_BYTES[] = { 0x55, 0x2D, 0x16 };
// Note that these are already scrambled, 0x66 0x66 0x66 otherwise // Note that these are already scrambled, 0x66 0x66 0x66 otherwise
const unsigned char DSTAR_NULL_SLOW_DATA_BYTES[] = { 0x16, 0x29, 0xF5 }; const unsigned char DSTAR_NULL_SLOW_DATA_BYTES[] = { 0x16, 0x29, 0xF5 };