mirror of
https://github.com/g4klx/DMRGateway
synced 2025-12-21 13:35:40 +08:00
Use the same logic as the D-Star voice unit.
This commit is contained in:
@@ -38,7 +38,7 @@ W 1888 38
|
|||||||
X 1945 35
|
X 1945 35
|
||||||
Y 1999 28
|
Y 1999 28
|
||||||
Z 2052 37
|
Z 2052 37
|
||||||
linkedto 2116 19
|
linked 2116 19
|
||||||
notlinked 2186 44
|
notlinked 2186 44
|
||||||
linking 2250 31
|
linking 2250 31
|
||||||
isbusy 2342 33
|
isbusy 2342 33
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ W 2336 33
|
|||||||
X 2413 24
|
X 2413 24
|
||||||
Y 2481 26
|
Y 2481 26
|
||||||
Z 2553 32
|
Z 2553 32
|
||||||
linkedto 2629 20
|
linked 2629 20
|
||||||
notlinked 2702 49
|
notlinked 2702 49
|
||||||
linking 2771 25
|
linking 2771 25
|
||||||
isbusy 2864 34
|
isbusy 2864 34
|
||||||
|
|||||||
43
Voice.cpp
43
Voice.cpp
@@ -32,6 +32,9 @@ const unsigned char SILENCE[] = {0xACU, 0xAAU, 0x40U, 0x20U, 0x00U, 0x44U, 0x40U
|
|||||||
|
|
||||||
const unsigned char COLOR_CODE = 3U;
|
const unsigned char COLOR_CODE = 3U;
|
||||||
|
|
||||||
|
const unsigned int SILENCE_LENGTH = 9U;
|
||||||
|
const unsigned int AMBE_LENGTH = 9U;
|
||||||
|
|
||||||
CVoice::CVoice(const std::string& directory, const std::string& language, unsigned int id, unsigned int slot, unsigned int tg) :
|
CVoice::CVoice(const std::string& directory, const std::string& language, unsigned int id, unsigned int slot, unsigned int tg) :
|
||||||
m_indxFile(),
|
m_indxFile(),
|
||||||
m_ambeFile(),
|
m_ambeFile(),
|
||||||
@@ -108,9 +111,9 @@ bool CVoice::open()
|
|||||||
char* p3 = ::strtok(NULL, "\t\r\n");
|
char* p3 = ::strtok(NULL, "\t\r\n");
|
||||||
|
|
||||||
if (p1 != NULL && p2 != NULL && p3 != NULL) {
|
if (p1 != NULL && p2 != NULL && p3 != NULL) {
|
||||||
std::string symbol = std::string(p1);
|
std::string symbol = std::string(p1);
|
||||||
unsigned int start = ::atoi(p2) * 9U;
|
unsigned int start = ::atoi(p2) * AMBE_LENGTH;
|
||||||
unsigned int length = ::atoi(p3) * 9U;
|
unsigned int length = ::atoi(p3) * AMBE_LENGTH;
|
||||||
|
|
||||||
CPositions* pos = new CPositions;
|
CPositions* pos = new CPositions;
|
||||||
pos->m_start = start;
|
pos->m_start = start;
|
||||||
@@ -133,7 +136,12 @@ void CVoice::linkedTo(unsigned int number, unsigned int room)
|
|||||||
::sprintf(letters, "%03u", number);
|
::sprintf(letters, "%03u", number);
|
||||||
|
|
||||||
std::vector<std::string> words;
|
std::vector<std::string> words;
|
||||||
words.push_back("linkedto");
|
if (m_positions.count("linkedto") == 0U) {
|
||||||
|
words.push_back("linked");
|
||||||
|
words.push_back("2");
|
||||||
|
} else {
|
||||||
|
words.push_back("linkedto");
|
||||||
|
}
|
||||||
words.push_back("X");
|
words.push_back("X");
|
||||||
words.push_back("L");
|
words.push_back("L");
|
||||||
words.push_back("X");
|
words.push_back("X");
|
||||||
@@ -171,19 +179,24 @@ void CVoice::createVoice(const std::vector<std::string>& words)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the AMBE is an integer number of DMR frames
|
// Ensure that the AMBE is an integer number of DMR frames
|
||||||
if ((ambeLength % 27U) != 0U) {
|
if ((ambeLength % (3U * AMBE_LENGTH)) != 0U) {
|
||||||
unsigned int frames = ambeLength / 27U;
|
unsigned int frames = ambeLength / (3U * AMBE_LENGTH);
|
||||||
frames++;
|
frames++;
|
||||||
ambeLength = frames * 27U;
|
ambeLength = frames * (3U * AMBE_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add space for silence before and after the voice
|
||||||
|
ambeLength += SILENCE_LENGTH * AMBE_LENGTH;
|
||||||
|
ambeLength += SILENCE_LENGTH * AMBE_LENGTH;
|
||||||
|
|
||||||
unsigned char* ambeData = new unsigned char[ambeLength];
|
unsigned char* ambeData = new unsigned char[ambeLength];
|
||||||
|
|
||||||
// Fill the AMBE data with silence
|
// Fill the AMBE data with silence
|
||||||
for (unsigned int i = 0U; i < ambeLength; i += 9U)
|
for (unsigned int i = 0U; i < ambeLength; i += AMBE_LENGTH)
|
||||||
::memcpy(ambeData + i, SILENCE, 9U);
|
::memcpy(ambeData + i, SILENCE, AMBE_LENGTH);
|
||||||
|
|
||||||
unsigned int pos = 0U;
|
// Put offset in for silence at the beginning
|
||||||
|
unsigned int pos = SILENCE_LENGTH * AMBE_LENGTH;
|
||||||
for (std::vector<std::string>::const_iterator it = words.begin(); it != words.end(); ++it) {
|
for (std::vector<std::string>::const_iterator it = words.begin(); it != words.end(); ++it) {
|
||||||
if (m_positions.count(*it) > 0U) {
|
if (m_positions.count(*it) > 0U) {
|
||||||
CPositions* position = m_positions.at(*it);
|
CPositions* position = m_positions.at(*it);
|
||||||
@@ -209,7 +222,7 @@ void CVoice::createVoice(const std::vector<std::string>& words)
|
|||||||
unsigned char buffer[DMR_FRAME_LENGTH_BYTES];
|
unsigned char buffer[DMR_FRAME_LENGTH_BYTES];
|
||||||
|
|
||||||
unsigned int n = 0U;
|
unsigned int n = 0U;
|
||||||
for (unsigned int i = 0U; i < ambeLength; i += 27U) {
|
for (unsigned int i = 0U; i < ambeLength; i += (3U * AMBE_LENGTH)) {
|
||||||
unsigned char* p = ambeData + i;
|
unsigned char* p = ambeData + i;
|
||||||
|
|
||||||
CDMRData* data = new CDMRData;
|
CDMRData* data = new CDMRData;
|
||||||
@@ -222,10 +235,10 @@ void CVoice::createVoice(const std::vector<std::string>& words)
|
|||||||
data->setSeqNo(m_seqNo++);
|
data->setSeqNo(m_seqNo++);
|
||||||
data->setStreamId(m_streamId);
|
data->setStreamId(m_streamId);
|
||||||
|
|
||||||
::memcpy(buffer + 0U, p + 0U, 9U);
|
::memcpy(buffer + 0U, p + 0U, AMBE_LENGTH);
|
||||||
::memcpy(buffer + 9U, p + 9U, 9U);
|
::memcpy(buffer + 9U, p + 9U, AMBE_LENGTH);
|
||||||
::memcpy(buffer + 15U, p + 9U, 9U);
|
::memcpy(buffer + 15U, p + 9U, AMBE_LENGTH);
|
||||||
::memcpy(buffer + 24U, p + 18U, 9U);
|
::memcpy(buffer + 24U, p + 18U, AMBE_LENGTH);
|
||||||
|
|
||||||
if (n == 0U) {
|
if (n == 0U) {
|
||||||
CSync::addDMRAudioSync(buffer, true);
|
CSync::addDMRAudioSync(buffer, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user