Avoid repeat i.e. Telemetry Lost / Trainer Lost until prompts fifo is… (#5121)
* Avoid repeat i.e. Telemetry Lost / Trainer Lost until prompts fifo is full ... * Rename functions * Belt and braces
This commit is contained in:
committed by
Andre Bernet
parent
7d386e7821
commit
96f1a16744
+12
-8
@@ -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);
|
||||
|
||||
+19
-6
@@ -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))
|
||||
|
||||
@@ -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 "/";
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user