From 104f18d9e92ed2f02a08323ea64dc5dc527f52ff Mon Sep 17 00:00:00 2001 From: vk7js <58905135+vk7js@users.noreply.github.com> Date: Mon, 12 Sep 2022 19:45:26 +1000 Subject: [PATCH] Added vp_beepSeries to play a melody. Now play melody on power up if vp level set to Beep. --- openrtx/include/core/beeps.h | 1 + openrtx/include/core/voicePrompts.h | 13 +++++ openrtx/src/core/voicePrompts.c | 80 ++++++++++++++++++++++++++--- 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/openrtx/include/core/beeps.h b/openrtx/include/core/beeps.h index 7099f08d..0bd72968 100644 --- a/openrtx/include/core/beeps.h +++ b/openrtx/include/core/beeps.h @@ -30,5 +30,6 @@ #define BEEP_FUNCTION_LATCH_ON 800 #define BEEP_FUNCTION_LATCH_OFF 400 #define BEEP_KEY_GENERIC 750 +extern const uint16_t BOOT_MELODY[]; #endif // BEEPS_H_INCLUDED \ No newline at end of file diff --git a/openrtx/include/core/voicePrompts.h b/openrtx/include/core/voicePrompts.h index 828461dd..dc9fb483 100644 --- a/openrtx/include/core/voicePrompts.h +++ b/openrtx/include/core/voicePrompts.h @@ -242,6 +242,14 @@ typedef enum } vpSummaryInfoFlags_t; +typedef struct +{ + uint16_t freq; + uint16_t duration; +} +beep_data_t; + + /** * Initialise the voice prompt system and load vp table of contents. */ @@ -318,4 +326,9 @@ bool vp_sequenceNotEmpty(); * play a beep at a given frequency for a given duration. */ void vp_beep(uint16_t freq, uint16_t duration); +/** + * play a series of beeps at a given frequency for a given duration. + * Array is freq, duration, ... 0, 0 to terminate series. + */ +void vp_beepSeries(const uint16_t* beepSeries); #endif diff --git a/openrtx/src/core/voicePrompts.c b/openrtx/src/core/voicePrompts.c index 7c675c37..b6fed5cf 100644 --- a/openrtx/src/core/voicePrompts.c +++ b/openrtx/src/core/voicePrompts.c @@ -29,11 +29,19 @@ #include #include #include +#include static const uint32_t VOICE_PROMPTS_DATA_MAGIC = 0x5056; //'VP' static const uint32_t VOICE_PROMPTS_DATA_VERSION = 0x1000; // v1000 OpenRTX static uint16_t currentBeepDuration=0; +// max buff size for beep series (melody). +#define beepSeriesMax 256 +static beep_data_t beepSeriesBuffer[beepSeriesMax]; +static uint8_t beepSeriesIndex = 0; + static bool delayBeepUntilTick=false; + const uint16_t BOOT_MELODY[]={400, 3, 600, 3, 800, 3, 0, 0}; + #define VOICE_PROMPTS_TOC_SIZE 350 #define CODEC2_HEADER_SIZE 7 #define VP_SEQUENCE_BUF_SIZE 128 @@ -281,8 +289,11 @@ void vp_init() // Initialize codec2 module codec_init(); - - if (state.settings.vpLevel > vpBeep) + if (state.settings.vpLevel == vpBeep) + { + vp_beepSeries(BOOT_MELODY); + } + else if (state.settings.vpLevel > vpBeep) {// announce the splash msg and VFO. vpSummaryInfoFlags_t infoFlags = vpChannelNameOrVFO | vpFrequencies | vpRadioMode | vpSplashInfo; @@ -316,6 +327,9 @@ void vp_stop() // If any beep is playing, immediately stop it. if (currentBeepDuration > 0) platform_beepStop(); + + memset(beepSeriesBuffer, 0, sizeof(beepSeriesBuffer)); + beepSeriesIndex=0; } void vp_flush() @@ -461,19 +475,41 @@ void vp_play() audio_enableAmp(); } -static void beep_tick() +static bool beep_tick() { if (currentBeepDuration > 0) { + if (delayBeepUntilTick) + { + platform_beepStart(beepSeriesBuffer[beepSeriesIndex].freq); + delayBeepUntilTick=false; + } currentBeepDuration--; if (currentBeepDuration==0) - platform_beepStop(); + { + platform_beepStop(); + // see if there are any more in the series to play. + if (beepSeriesBuffer[beepSeriesIndex+1].freq && beepSeriesBuffer[beepSeriesIndex+1].duration) + { + beepSeriesIndex++; + currentBeepDuration=beepSeriesBuffer[beepSeriesIndex].duration; + platform_beepStart(beepSeriesBuffer[beepSeriesIndex].freq); + } + else + { + memset(beepSeriesBuffer, 0, sizeof(beepSeriesBuffer)); + beepSeriesIndex=0; + } + } + return true; } + return false; } void vp_tick() { - beep_tick(); + if (beep_tick()) + return; if (voicePromptActive == false) return; @@ -547,8 +583,40 @@ void vp_beep(uint16_t freq, uint16_t duration) currentBeepDuration=duration; audio_enableAmp(); - + beepSeriesBuffer[0].freq=freq; + beepSeriesBuffer[0].duration=duration; + beepSeriesBuffer[1].freq =0; + beepSeriesBuffer[1].duration =0; + beepSeriesIndex=0; platform_beepStart(freq); // See BeepTick for termination. } +/* +We delay the playing of the melody until the first time vp_tick is called +because there is a sleep on the splash screen which would make the first note +play extra long. +*/ +void vp_beepSeries(const uint16_t* beepSeries) +{ + if (state.settings.vpLevel < vpBeep) + return; + + if (currentBeepDuration) + return ; + + audio_enableAmp(); + + if (!beepSeries) return; + + memcpy(beepSeriesBuffer, beepSeries, beepSeriesMax*sizeof(beep_data_t)); + // Always ensure that the array is terminated! + beepSeriesBuffer[beepSeriesMax-1].freq = 0; + beepSeriesBuffer[beepSeriesMax-1].duration = 0; + + beepSeriesIndex=0; + currentBeepDuration=beepSeriesBuffer[0].duration; + delayBeepUntilTick = true; +} + +