From 96f1a1674420a9fd600cf5665a8caadcb4cd55b6 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 9 Aug 2017 11:59:13 +0200 Subject: [PATCH] =?UTF-8?q?Avoid=20repeat=20i.e.=20Telemetry=20Lost=20/=20?= =?UTF-8?q?Trainer=20Lost=20until=20prompts=20fifo=20is=E2=80=A6=20(#5121)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Avoid repeat i.e. Telemetry Lost / Trainer Lost until prompts fifo is full ... * Rename functions * Belt and braces --- radio/src/audio_arm.cpp | 20 ++++++++++++-------- radio/src/audio_arm.h | 25 +++++++++++++++++++------ radio/src/functions.cpp | 2 +- radio/src/opentx.cpp | 2 +- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 0b6c9bfd3..50a283e26 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -825,9 +825,9 @@ void AudioQueue::pause(uint16_t len) bool AudioQueue::isPlaying(uint8_t id) { - return normalContext.hasId(id) || - (isFunctionActive(FUNCTION_BACKGND_MUSIC) && backgroundContext.hasId(id)) || - fragmentsFifo.hasId(id); + return normalContext.hasPromptId(id) || + (isFunctionActive(FUNCTION_BACKGND_MUSIC) && backgroundContext.hasPromptId(id)) || + fragmentsFifo.hasPromptId(id); } void AudioQueue::playTone(uint16_t freq, uint16_t len, uint16_t pause, uint8_t flags, int8_t freqIncr) @@ -863,7 +863,7 @@ void AudioQueue::playTone(uint16_t freq, uint16_t len, uint16_t pause, uint8_t f } #if defined(SDCARD) -void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id) +void AudioQueue::playFile(const char * filename, uint8_t flags, uint8_t id) { #if defined(SIMU) TRACE("playFile(\"%s\", flags=%x, id=%d)", filename, flags, id); @@ -876,7 +876,6 @@ void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id) #endif #endif - if (!sdMounted()) return; @@ -911,8 +910,12 @@ void AudioQueue::stopPlay(uint8_t id) return; #endif - // For the moment it's only needed to stop the background music + CoEnterMutexSection(audioMutex); + + fragmentsFifo.removePromptById(id); backgroundContext.stop(id); + + CoLeaveMutexSection(audioMutex); } void AudioQueue::stopSD() @@ -1052,7 +1055,8 @@ void audioEvent(unsigned int index) #if defined(SDCARD) char filename[AUDIO_FILENAME_MAXLEN + 1]; if (index < AU_SPECIAL_SOUND_FIRST && isAudioFileReferenced(index, filename)) { - audioQueue.playFile(filename); + audioQueue.stopPlay(ID_PLAY_PROMPT_BASE + index); + audioQueue.playFile(filename, 0, ID_PLAY_PROMPT_BASE + index); return; } #endif @@ -1206,7 +1210,7 @@ void pushUnit(uint8_t unit, uint8_t idx, uint8_t id) { if (unit < DIM(unitsFilenames)) { char path[AUDIO_FILENAME_MAXLEN+1]; - char *tmp = strAppendSystemAudioPath(path); + char * tmp = strAppendSystemAudioPath(path); tmp = strAppendStringWithIndex(tmp, unitsFilenames[unit], idx); strcpy(tmp, SOUNDS_EXT); audioQueue.playFile(path, 0, id); diff --git a/radio/src/audio_arm.h b/radio/src/audio_arm.h index 1e244dac3..7c2cb4302 100644 --- a/radio/src/audio_arm.h +++ b/radio/src/audio_arm.h @@ -209,7 +209,7 @@ class WavContext { inline void clear() { fragment.clear(); }; int mixBuffer(AudioBuffer *buffer, int volume, unsigned int fade); - bool hasId(uint8_t id) const { return fragment.id == id; }; + bool hasPromptId(uint8_t id) const { return fragment.id == id; }; void setFragment(const char * filename, uint8_t repeat, uint8_t id) { @@ -262,7 +262,7 @@ class MixedContext { bool isEmpty() const { return fragment.type == FRAGMENT_EMPTY; }; bool isTone() const { return fragment.type == FRAGMENT_TONE; }; bool isFile() const { return fragment.type == FRAGMENT_FILE; }; - bool hasId(uint8_t id) const { return fragment.id == id; }; + bool hasPromptId(uint8_t id) const { return fragment.id == id; }; int mixBuffer(AudioBuffer *buffer, int toneVolume, int wavVolume, unsigned int fade) { @@ -414,7 +414,7 @@ class AudioFragmentFifo public: AudioFragmentFifo() : ridx(0), widx(0), fragments() {}; - bool hasId(uint8_t id) + bool hasPromptId(uint8_t id) { uint8_t i = ridx; while (i != widx) { @@ -425,6 +425,17 @@ class AudioFragmentFifo return false; } + bool removePromptById(uint8_t id) + { + uint8_t i = ridx; + while (i != widx) { + AudioFragment & fragment = fragments[i]; + if (fragment.id == id) fragment.clear(); + i = nextIdx(i); + } + return false; + } + bool empty() const { return ridx == widx; @@ -502,8 +513,10 @@ extern uint8_t currentSpeakerVolume; extern AudioQueue audioQueue; enum { - ID_PLAY_FROM_SD_MANAGER = 254, - ID_PLAY_BYE = 255 + // IDs for special functions [0:64] + // IDs for global functions [64:128] + ID_PLAY_PROMPT_BASE = 128, + ID_PLAY_FROM_SD_MANAGER = 255, }; void codecsInit(); @@ -536,7 +549,7 @@ void audioTimerCountdown(uint8_t timer, int value); #define AUDIO_KEY_ERROR() audioKeyError() #define AUDIO_HELLO() audioPlay(AUDIO_HELLO) -#define AUDIO_BYE() audioPlay(AU_BYE, ID_PLAY_BYE) +#define AUDIO_BYE() audioPlay(AU_BYE, ID_PLAY_PROMPT_BASE + AU_BYE) #define AUDIO_WARNING1() AUDIO_BUZZER(audioEvent(AU_WARNING1), beep(3)) #define AUDIO_WARNING2() AUDIO_BUZZER(audioEvent(AU_WARNING2), beep(2)) #define AUDIO_TX_BATTERY_LOW() AUDIO_BUZZER(audioEvent(AU_TX_BATTERY_LOW), beep(4)) diff --git a/radio/src/functions.cpp b/radio/src/functions.cpp index 8cdebf2ec..3606d0f6e 100644 --- a/radio/src/functions.cpp +++ b/radio/src/functions.cpp @@ -211,7 +211,7 @@ PLAY_FUNCTION(playValue, source_t idx) #endif #if defined(CPUARM) -void playCustomFunctionFile(const CustomFunctionData *sd, uint8_t id) +void playCustomFunctionFile(const CustomFunctionData * sd, uint8_t id) { if (sd->play.name[0] != '\0') { char filename[sizeof(SOUNDS_PATH)+sizeof(sd->play.name)+sizeof(SOUNDS_EXT)] = SOUNDS_PATH "/"; diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index dc7bbff98..f2de31a4e 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1945,7 +1945,7 @@ void opentxClose(uint8_t shutdown) storageCheck(true); #if defined(CPUARM) - while (IS_PLAYING(ID_PLAY_BYE)) { + while (IS_PLAYING(ID_PLAY_PROMPT_BASE + AU_BYE)) { CoTickDelay(10); } CoTickDelay(50);