Moved voiceprompts audio management to audio path system

This commit is contained in:
Silvano Seva 2022-09-28 09:13:06 +02:00
parent 4411e0f3e8
commit 2c1401de86
1 changed files with 17 additions and 10 deletions

View File

@ -19,11 +19,11 @@
***************************************************************************/ ***************************************************************************/
#include <interfaces/platform.h> #include <interfaces/platform.h>
#include <interfaces/keyboard.h> #include <interfaces/keyboard.h>
#include <interfaces/audio.h> #include <voicePromptUtils.h>
#include "voicePromptUtils.h"
#include <ui/ui_strings.h> #include <ui/ui_strings.h>
#include <voicePrompts.h> #include <voicePrompts.h>
#include <audio_codec.h> #include <audio_codec.h>
#include <audio_path.h>
#include <ctype.h> #include <ctype.h>
#include <state.h> #include <state.h>
#include <stdio.h> #include <stdio.h>
@ -106,6 +106,8 @@ static uint16_t currentBeepDuration = 0;
static uint8_t beepSeriesIndex = 0; static uint8_t beepSeriesIndex = 0;
static bool delayBeepUntilTick = false; static bool delayBeepUntilTick = false;
static pathId vpAudioPath;
#ifdef VP_USE_FILESYSTEM #ifdef VP_USE_FILESYSTEM
static FILE *vpFile = NULL; static FILE *vpFile = NULL;
#else #else
@ -270,6 +272,7 @@ static void beep_flush()
memset(beepSeriesBuffer, 0, sizeof(beepSeriesBuffer)); memset(beepSeriesBuffer, 0, sizeof(beepSeriesBuffer));
currentBeepDuration = 0; currentBeepDuration = 0;
beepSeriesIndex = 0; beepSeriesIndex = 0;
audioPath_release(vpAudioPath);
} }
/** /**
@ -283,7 +286,7 @@ static bool beep_tick()
if (delayBeepUntilTick) if (delayBeepUntilTick)
{ {
platform_beepStart(beepSeriesBuffer[beepSeriesIndex].freq); platform_beepStart(beepSeriesBuffer[beepSeriesIndex].freq);
delayBeepUntilTick=false; delayBeepUntilTick = false;
} }
currentBeepDuration--; currentBeepDuration--;
@ -366,10 +369,7 @@ void vp_init()
void vp_terminate() void vp_terminate()
{ {
if (voicePromptActive) if (voicePromptActive)
{
audio_disableAmp();
vp_flush(); vp_flush();
}
codec_terminate(); codec_terminate();
@ -388,6 +388,8 @@ void vp_stop()
// If any beep is playing, immediately stop it. // If any beep is playing, immediately stop it.
beep_flush(); beep_flush();
audioPath_release(vpAudioPath);
} }
void vp_flush() void vp_flush()
@ -530,8 +532,8 @@ void vp_play()
voicePromptActive = true; voicePromptActive = true;
vpAudioPath = audioPath_request(SOURCE_MCU, SINK_SPK, PRIO_PROMPT);
codec_startDecode(SINK_SPK); codec_startDecode(SINK_SPK);
audio_enableAmp();
} }
void vp_tick() void vp_tick()
@ -564,7 +566,11 @@ void vp_tick()
fetchCodec2Data(c2Frame, vpCurrentSequence.c2DataStart + fetchCodec2Data(c2Frame, vpCurrentSequence.c2DataStart +
vpCurrentSequence.c2DataIndex); vpCurrentSequence.c2DataIndex);
if (!codec_pushFrame(c2Frame, false)) // Do not push codec2 data if audio path is closed or suspended
if(audioPath_getStatus(vpAudioPath) != PATH_OPEN)
return;
if (codec_pushFrame(c2Frame, false) == false)
return; return;
vpCurrentSequence.c2DataIndex += 8; vpCurrentSequence.c2DataIndex += 8;
@ -582,6 +588,7 @@ void vp_tick()
vpCurrentSequence.pos = 0; vpCurrentSequence.pos = 0;
vpCurrentSequence.c2DataIndex = 0; vpCurrentSequence.c2DataIndex = 0;
vpCurrentSequence.c2DataLength = 0; vpCurrentSequence.c2DataLength = 0;
audioPath_release(vpAudioPath);
codec_stop(); codec_stop();
} }
} }
@ -615,7 +622,7 @@ void vp_beep(uint16_t freq, uint16_t duration)
beepSeriesBuffer[1].duration = 0; beepSeriesBuffer[1].duration = 0;
currentBeepDuration = duration; currentBeepDuration = duration;
beepSeriesIndex = 0; beepSeriesIndex = 0;
audio_enableAmp(); vpAudioPath = audioPath_request(SOURCE_MCU, SINK_SPK, PRIO_PROMPT);
platform_beepStart(freq); platform_beepStart(freq);
} }
@ -627,7 +634,7 @@ void vp_beepSeries(const uint16_t* beepSeries)
if (currentBeepDuration != 0) if (currentBeepDuration != 0)
return; return;
audio_enableAmp(); vpAudioPath = audioPath_request(SOURCE_MCU, SINK_SPK, PRIO_PROMPT);
if (beepSeries == NULL) if (beepSeries == NULL)
return; return;