From fa9c757c6a1bacf7edc1d61d52ac539cf6ba1c73 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sat, 30 Sep 2017 19:07:40 +0100 Subject: [PATCH] Add safety and logging code to the Voice unit. --- Voice.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Voice.cpp b/Voice.cpp index 745bc88..c16ddd4 100644 --- a/Voice.cpp +++ b/Voice.cpp @@ -159,8 +159,12 @@ void CVoice::createVoice(const std::vector& words) { unsigned int ambeLength = 0U; for (std::vector::const_iterator it = words.begin(); it != words.end(); ++it) { - CPositions* position = m_positions.at(*it); - ambeLength += position->m_length; + if (m_positions.count(*it) > 0U) { + CPositions* position = m_positions.at(*it); + ambeLength += position->m_length; + } else { + LogWarning("Unable to find character/phrase \"%s\" in the index", (*it).c_str()); + } } // Ensure that the AMBE is an integer number of DMR frames @@ -178,11 +182,13 @@ void CVoice::createVoice(const std::vector& words) unsigned int pos = 0U; for (std::vector::const_iterator it = words.begin(); it != words.end(); ++it) { - CPositions* position = m_positions.at(*it); - unsigned int start = position->m_start; - unsigned int length = position->m_length; - ::memcpy(ambeData + pos, m_ambe + start, length); - pos += length; + if (m_positions.count(*it) > 0U) { + CPositions* position = m_positions.at(*it); + unsigned int start = position->m_start; + unsigned int length = position->m_length; + ::memcpy(ambeData + pos, m_ambe + start, length); + pos += length; + } } for (std::vector::iterator it = m_data.begin(); it != m_data.end(); ++it)