From 8eca684a7dc4e1a7b5688b4e17b751e771a5d7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Izzo?= Date: Sat, 23 Jul 2022 23:35:29 +0200 Subject: [PATCH] Voice prompts bugfixes: - added missing initialization of codec2 in voice prompts code - discarding the voice prompt header as we only support 3200 bit rate - fixed wrong offset in pick vpQueueStringTableEntry - fixed bug in vpInit causing voiceprompts to hang --- meson.build | 7 ++++- openrtx/include/core/voicePrompts.h | 5 +++- openrtx/src/core/voicePrompts.c | 17 +++++------ tests/unit/voice_prompts.c | 45 +++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 tests/unit/voice_prompts.c diff --git a/meson.build b/meson.build index 75ead507..c862a33d 100644 --- a/meson.build +++ b/meson.build @@ -697,10 +697,15 @@ sine_test = executable('sine_test', sources : unit_test_src + ['tests/unit/play_sine.c'], kwargs : unit_test_opts) +vp_test = executable('vp_test', + sources : unit_test_src + ['tests/unit/voice_prompts.c'], + kwargs : unit_test_opts) + test('M17 Golay Unit Test', m17_golay_test) test('M17 Viterbi Unit Test', m17_viterbi_test) test('M17 Demodulator Test', m17_demodulator_test) test('M17 RRC Test', m17_rrc_test) test('Codeplug Test', cps_test) test('Linux InputStream Test', linux_inputStream_test) -test('Sine Test', sine_test) +test('Sine Test', sine_test) +test('Voice Prompts Test', vp_test) diff --git a/openrtx/include/core/voicePrompts.h b/openrtx/include/core/voicePrompts.h index d2e97cd4..ebd9a5ca 100644 --- a/openrtx/include/core/voicePrompts.h +++ b/openrtx/include/core/voicePrompts.h @@ -22,6 +22,9 @@ #include #include +// Voice prompts are encoded using the codec2 file format used by ffmpeg +#define CODEC2_HEADER_SIZE 7 + /* Please note, these prompts represent spoken words or phrases which are not in the UI string table, for example letters of the alphabet, digits, and @@ -270,4 +273,4 @@ bool vpCheckHeader(uint32_t* bufferAddress); int vp_open(char *vp_name); void vp_close(); -#endif \ No newline at end of file +#endif diff --git a/openrtx/src/core/voicePrompts.c b/openrtx/src/core/voicePrompts.c index 335aae67..213ac4df 100644 --- a/openrtx/src/core/voicePrompts.c +++ b/openrtx/src/core/voicePrompts.c @@ -137,6 +137,8 @@ void vpCacheInit(void) // loaded. if (state.settings.vpLevel > vpBeep) state.settings.vpLevel = vpBeep; } + // TODO: Move this somewhere else for compatibility with M17 + codec_init(); } bool vpCheckHeader(uint32_t* bufferAddress) @@ -154,8 +156,9 @@ static void GetCodec2Data(int offset, int length) if ((offset < 0) || (length > Codec2DataBufferSize)) return; - - fseek(voice_prompt_file, vpDataOffset+offset, SEEK_SET); + + // Skip codec2 header + fseek(voice_prompt_file, vpDataOffset+offset+CODEC2_HEADER_SIZE, SEEK_SET); fread((void*)&Codec2Data, length, 1, voice_prompt_file); // zero buffer from length to the next multiple of 8 to avoid garbage // being played back, since codec2 frames are pushed in lots of 8 bytes. @@ -181,11 +184,6 @@ void vpTerminate(void) void vpInit(void) { - if (voicePromptIsActive) - { - vpTerminate(); - } - vpCurrentSequence.length = 0; vpCurrentSequence.pos = 0; vpCurrentSequence.codec2DataIndex = 0; @@ -343,8 +341,9 @@ void vpQueueStringTableEntry(const char* const* stringTableStringPtr) { return; } - vpQueuePrompt(NUM_VOICE_PROMPTS + - (stringTableStringPtr - ¤tLanguage->languageName)); + vpQueuePrompt(NUM_VOICE_PROMPTS + 1 + + (stringTableStringPtr - ¤tLanguage->languageName) + / sizeof(const char *)); } void vpPlay(void) diff --git a/tests/unit/voice_prompts.c b/tests/unit/voice_prompts.c new file mode 100644 index 00000000..b6972043 --- /dev/null +++ b/tests/unit/voice_prompts.c @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN * + * Frederik Saraci IU2NRO * + * Silvano Seva IU2KWO * + * * + * * + * 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 3 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, see * + ***************************************************************************/ + +// Test private methods +#define private public + +#include +#include + +/** + * Test voice prompts playback + */ + +int main() +{ + state.settings.vpLevel = 3; + VoicePromptQueueFlags_T flags = GetQueueFlagsForVoiceLevel(); + + vpCacheInit(); + vpInit(); + vpQueueStringTableEntry(¤tLanguage->allChannels); + vpPlay(); + while(true) + { + vpTick(); + } +}