2023-09-09 08:03:56 +01:00
|
|
|
/* Copyright 2023 Dual Tachyon
|
|
|
|
* https://github.com/DualTachyon
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-10-15 17:56:55 +01:00
|
|
|
#ifdef ENABLE_AIRCOPY
|
|
|
|
#include "app/aircopy.h"
|
|
|
|
#endif
|
2023-10-24 11:47:49 +01:00
|
|
|
#ifdef ENABLE_FMRADIO
|
2023-09-14 09:56:30 +01:00
|
|
|
#include "app/fm.h"
|
|
|
|
#endif
|
2023-09-09 08:03:56 +01:00
|
|
|
#include "audio.h"
|
|
|
|
#include "bsp/dp32g030/gpio.h"
|
2023-10-24 11:47:49 +01:00
|
|
|
#ifdef ENABLE_FMRADIO
|
2023-09-14 09:56:30 +01:00
|
|
|
#include "driver/bk1080.h"
|
|
|
|
#endif
|
2023-09-09 08:03:56 +01:00
|
|
|
#include "driver/bk4819.h"
|
|
|
|
#include "driver/gpio.h"
|
|
|
|
#include "driver/system.h"
|
|
|
|
#include "driver/systick.h"
|
2023-10-27 10:52:32 +01:00
|
|
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
|
|
|
#include "driver/uart.h"
|
|
|
|
#endif
|
2023-09-09 08:03:56 +01:00
|
|
|
#include "functions.h"
|
|
|
|
#include "misc.h"
|
2023-11-04 14:56:09 +00:00
|
|
|
#include "radio.h"
|
2023-09-09 08:03:56 +01:00
|
|
|
#include "settings.h"
|
|
|
|
#include "ui/ui.h"
|
|
|
|
|
2023-09-14 09:56:30 +01:00
|
|
|
#ifdef ENABLE_VOICE
|
2023-09-09 08:03:56 +01:00
|
|
|
|
|
|
|
static const uint8_t VoiceClipLengthChinese[58] =
|
|
|
|
{
|
|
|
|
0x32, 0x32, 0x32, 0x37, 0x37, 0x32, 0x32, 0x32,
|
|
|
|
0x32, 0x37, 0x37, 0x32, 0x64, 0x64, 0x64, 0x64,
|
|
|
|
0x64, 0x69, 0x64, 0x69, 0x5A, 0x5F, 0x5F, 0x64,
|
|
|
|
0x64, 0x69, 0x64, 0x64, 0x69, 0x69, 0x69, 0x64,
|
|
|
|
0x64, 0x6E, 0x69, 0x5F, 0x64, 0x64, 0x64, 0x69,
|
|
|
|
0x69, 0x69, 0x64, 0x69, 0x64, 0x64, 0x55, 0x5F,
|
|
|
|
0x5A, 0x4B, 0x4B, 0x46, 0x46, 0x69, 0x64, 0x6E,
|
|
|
|
0x5A, 0x64,
|
|
|
|
};
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
static const uint8_t VoiceClipLengthEnglish[76] =
|
|
|
|
{
|
|
|
|
0x50, 0x32, 0x2D, 0x2D, 0x2D, 0x37, 0x37, 0x37,
|
|
|
|
0x32, 0x32, 0x3C, 0x37, 0x46, 0x46, 0x4B, 0x82,
|
|
|
|
0x82, 0x6E, 0x82, 0x46, 0x96, 0x64, 0x46, 0x6E,
|
|
|
|
0x78, 0x6E, 0x87, 0x64, 0x96, 0x96, 0x46, 0x9B,
|
|
|
|
0x91, 0x82, 0x82, 0x73, 0x78, 0x64, 0x82, 0x6E,
|
|
|
|
0x78, 0x82, 0x87, 0x6E, 0x55, 0x78, 0x64, 0x69,
|
|
|
|
0x9B, 0x5A, 0x50, 0x3C, 0x32, 0x55, 0x64, 0x64,
|
|
|
|
0x50, 0x46, 0x46, 0x46, 0x4B, 0x4B, 0x50, 0x50,
|
|
|
|
0x55, 0x4B, 0x4B, 0x32, 0x32, 0x32, 0x32, 0x37,
|
|
|
|
0x41, 0x32, 0x3C, 0x37,
|
|
|
|
};
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-10-08 17:14:13 +01:00
|
|
|
voice_id_t g_voice_id[8];
|
|
|
|
uint8_t g_voice_read_index;
|
|
|
|
uint8_t g_voice_write_index;
|
2023-10-29 22:33:38 +00:00
|
|
|
volatile uint16_t g_play_next_voice_tick_10ms;
|
2023-10-08 17:14:13 +01:00
|
|
|
volatile bool g_flag_play_queued_voice;
|
|
|
|
voice_id_t g_another_voice_id = VOICE_ID_INVALID;
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
#endif
|
|
|
|
|
2023-10-08 20:23:37 +01:00
|
|
|
beep_type_t g_beep_to_play = BEEP_NONE;
|
2023-09-09 08:03:56 +01:00
|
|
|
|
2023-11-06 14:46:39 +00:00
|
|
|
void AUDIO_set_mod_mode(const mod_mode_t mode)
|
2023-10-30 01:51:41 +00:00
|
|
|
{
|
|
|
|
BK4819_af_type_t af_mode;
|
|
|
|
switch (mode)
|
2023-11-11 13:09:24 +00:00
|
|
|
{
|
2023-10-30 01:51:41 +00:00
|
|
|
default:
|
2023-11-08 12:17:35 +00:00
|
|
|
case MOD_MODE_FM: af_mode = BK4819_AF_FM; break;
|
|
|
|
case MOD_MODE_AM: af_mode = BK4819_AF_AM; break;
|
2023-11-06 14:46:39 +00:00
|
|
|
case MOD_MODE_DSB: af_mode = BK4819_AF_BASEBAND1; break;
|
2023-10-30 01:51:41 +00:00
|
|
|
}
|
|
|
|
BK4819_SetAF(af_mode);
|
|
|
|
}
|
|
|
|
|
2023-10-08 20:23:37 +01:00
|
|
|
void AUDIO_PlayBeep(beep_type_t Beep)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
2023-11-05 23:16:19 +00:00
|
|
|
const uint16_t tone_val = BK4819_read_reg(0x71);
|
|
|
|
// const uint16_t af_val = BK4819_read_reg(0x47);
|
2023-10-18 18:50:37 +01:00
|
|
|
uint16_t ToneFrequency;
|
|
|
|
uint16_t Duration;
|
|
|
|
|
2023-11-02 10:00:51 +00:00
|
|
|
if (g_eeprom.config.setting.beep_control == 0)
|
2023-10-18 18:50:37 +01:00
|
|
|
{ // beep not enabled
|
|
|
|
if (Beep != BEEP_880HZ_60MS_TRIPLE_BEEP &&
|
|
|
|
Beep != BEEP_500HZ_60MS_DOUBLE_BEEP &&
|
|
|
|
Beep != BEEP_440HZ_500MS &&
|
|
|
|
Beep != BEEP_880HZ_200MS &&
|
|
|
|
Beep != BEEP_880HZ_500MS)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2023-09-09 08:03:56 +01:00
|
|
|
|
2023-10-29 22:33:38 +00:00
|
|
|
if (g_flash_light_state == FLASHLIGHT_SOS ||
|
|
|
|
g_current_function == FUNCTION_RECEIVE ||
|
|
|
|
g_monitor_enabled ||
|
2023-10-30 21:48:29 +00:00
|
|
|
g_squelch_open ||
|
2023-10-29 22:33:38 +00:00
|
|
|
GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-14 09:56:30 +01:00
|
|
|
#ifdef ENABLE_AIRCOPY
|
2023-10-28 14:07:41 +01:00
|
|
|
// if (g_current_display_screen == DISPLAY_AIRCOPY || g_aircopy_state != AIRCOPY_READY)
|
2023-10-30 21:48:29 +00:00
|
|
|
// return;
|
2023-09-09 08:03:56 +01:00
|
|
|
#endif
|
2023-10-29 22:33:38 +00:00
|
|
|
|
|
|
|
// GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
|
2023-09-09 08:03:56 +01:00
|
|
|
|
2023-10-08 20:23:37 +01:00
|
|
|
if (g_current_function == FUNCTION_POWER_SAVE && g_rx_idle_mode)
|
2023-09-09 08:03:56 +01:00
|
|
|
BK4819_RX_TurnOn();
|
|
|
|
|
2023-10-24 11:47:49 +01:00
|
|
|
#ifdef ENABLE_FMRADIO
|
2023-10-11 16:02:45 +01:00
|
|
|
#ifdef MUTE_AUDIO_FOR_VOICE
|
|
|
|
if (g_fm_radio_mode)
|
|
|
|
BK1080_Mute(true);
|
|
|
|
#endif
|
2023-09-14 09:56:30 +01:00
|
|
|
#endif
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-10-18 20:44:33 +01:00
|
|
|
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
|
|
|
|
// UART_printf("beep %u\r\n", (unsigned int)Beep);
|
|
|
|
#endif
|
|
|
|
|
2023-10-18 18:50:37 +01:00
|
|
|
// whats this for ?
|
2023-10-18 20:44:33 +01:00
|
|
|
SYSTEM_DelayMs(20);
|
|
|
|
// SYSTEM_DelayMs(2);
|
2023-09-09 08:03:56 +01:00
|
|
|
|
|
|
|
switch (Beep)
|
|
|
|
{
|
2023-09-15 06:28:45 +01:00
|
|
|
default:
|
|
|
|
case BEEP_NONE:
|
|
|
|
ToneFrequency = 220;
|
|
|
|
break;
|
2023-10-18 18:50:37 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
case BEEP_1KHZ_60MS_OPTIONAL:
|
|
|
|
ToneFrequency = 1000;
|
|
|
|
break;
|
2023-10-18 18:50:37 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
case BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL:
|
|
|
|
case BEEP_500HZ_60MS_DOUBLE_BEEP:
|
|
|
|
ToneFrequency = 500;
|
|
|
|
break;
|
2023-10-18 18:50:37 +01:00
|
|
|
|
2023-09-15 06:28:45 +01:00
|
|
|
case BEEP_440HZ_40MS_OPTIONAL:
|
|
|
|
case BEEP_440HZ_500MS:
|
2023-09-09 08:03:56 +01:00
|
|
|
ToneFrequency = 440;
|
|
|
|
break;
|
2023-10-18 18:50:37 +01:00
|
|
|
|
2023-09-15 22:48:06 +01:00
|
|
|
case BEEP_880HZ_40MS_OPTIONAL:
|
2023-09-28 17:39:45 +01:00
|
|
|
case BEEP_880HZ_60MS_TRIPLE_BEEP:
|
2023-09-30 11:22:19 +01:00
|
|
|
case BEEP_880HZ_200MS:
|
|
|
|
case BEEP_880HZ_500MS:
|
2023-09-15 22:48:06 +01:00
|
|
|
ToneFrequency = 880;
|
|
|
|
break;
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-11-06 09:08:09 +00:00
|
|
|
BK4819_start_tone(ToneFrequency, 10, false, true);
|
2023-10-29 22:33:38 +00:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
SYSTEM_DelayMs(2);
|
2023-10-18 11:31:30 +01:00
|
|
|
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
|
2023-09-09 08:03:56 +01:00
|
|
|
|
|
|
|
SYSTEM_DelayMs(60);
|
|
|
|
|
|
|
|
switch (Beep)
|
|
|
|
{
|
2023-09-28 17:39:45 +01:00
|
|
|
case BEEP_880HZ_60MS_TRIPLE_BEEP:
|
|
|
|
BK4819_ExitTxMute();
|
|
|
|
SYSTEM_DelayMs(60);
|
|
|
|
BK4819_EnterTxMute();
|
|
|
|
SYSTEM_DelayMs(20);
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-10-28 23:11:57 +01:00
|
|
|
// Fallthrough
|
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
case BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL:
|
|
|
|
case BEEP_500HZ_60MS_DOUBLE_BEEP:
|
|
|
|
BK4819_ExitTxMute();
|
|
|
|
SYSTEM_DelayMs(60);
|
|
|
|
BK4819_EnterTxMute();
|
|
|
|
SYSTEM_DelayMs(20);
|
2023-09-15 06:28:45 +01:00
|
|
|
|
2023-10-28 23:11:57 +01:00
|
|
|
// Fallthrough
|
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
case BEEP_1KHZ_60MS_OPTIONAL:
|
|
|
|
BK4819_ExitTxMute();
|
|
|
|
Duration = 60;
|
|
|
|
break;
|
2023-09-15 06:28:45 +01:00
|
|
|
|
2023-09-15 22:48:06 +01:00
|
|
|
case BEEP_880HZ_40MS_OPTIONAL:
|
2023-09-15 06:28:45 +01:00
|
|
|
case BEEP_440HZ_40MS_OPTIONAL:
|
|
|
|
BK4819_ExitTxMute();
|
|
|
|
Duration = 40;
|
|
|
|
break;
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-30 11:22:19 +01:00
|
|
|
case BEEP_880HZ_200MS:
|
|
|
|
BK4819_ExitTxMute();
|
|
|
|
Duration = 200;
|
|
|
|
break;
|
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
case BEEP_440HZ_500MS:
|
2023-09-30 11:22:19 +01:00
|
|
|
case BEEP_880HZ_500MS:
|
2023-09-09 08:03:56 +01:00
|
|
|
default:
|
|
|
|
BK4819_ExitTxMute();
|
|
|
|
Duration = 500;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSTEM_DelayMs(Duration);
|
|
|
|
BK4819_EnterTxMute();
|
2023-10-18 18:50:37 +01:00
|
|
|
SYSTEM_DelayMs(2);
|
2023-09-09 08:03:56 +01:00
|
|
|
|
2023-10-29 22:33:38 +00:00
|
|
|
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
|
|
|
|
|
2023-10-04 11:57:34 +01:00
|
|
|
#ifdef ENABLE_VOX
|
2023-10-29 22:33:38 +00:00
|
|
|
g_vox_resume_tick_10ms = 80; // 800ms
|
2023-10-04 11:57:34 +01:00
|
|
|
#endif
|
2023-09-09 08:03:56 +01:00
|
|
|
|
2023-10-18 18:50:37 +01:00
|
|
|
SYSTEM_DelayMs(2);
|
2023-09-09 08:03:56 +01:00
|
|
|
BK4819_TurnsOffTones_TurnsOnRX();
|
2023-10-18 18:50:37 +01:00
|
|
|
SYSTEM_DelayMs(2);
|
|
|
|
|
2023-11-05 23:16:19 +00:00
|
|
|
BK4819_write_reg(0x71, tone_val);
|
2023-09-09 08:03:56 +01:00
|
|
|
|
2023-10-24 11:47:49 +01:00
|
|
|
#ifdef ENABLE_FMRADIO
|
2023-10-08 20:23:37 +01:00
|
|
|
if (g_fm_radio_mode)
|
2023-09-14 09:56:30 +01:00
|
|
|
BK1080_Mute(false);
|
|
|
|
#endif
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-10-08 20:23:37 +01:00
|
|
|
if (g_current_function == FUNCTION_POWER_SAVE && g_rx_idle_mode)
|
2023-10-29 22:33:38 +00:00
|
|
|
{
|
2023-09-09 08:03:56 +01:00
|
|
|
BK4819_Sleep();
|
2023-10-29 22:33:38 +00:00
|
|
|
}
|
|
|
|
else
|
2023-10-30 21:48:29 +00:00
|
|
|
if (g_squelch_open || g_monitor_enabled)
|
2023-10-29 22:33:38 +00:00
|
|
|
{
|
|
|
|
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
|
|
|
|
}
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
|
|
|
|
2023-09-14 09:56:30 +01:00
|
|
|
#ifdef ENABLE_VOICE
|
2023-09-09 08:03:56 +01:00
|
|
|
|
|
|
|
void AUDIO_PlayVoice(uint8_t VoiceID)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-11-02 10:00:51 +00:00
|
|
|
if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF)
|
2023-10-11 16:02:45 +01:00
|
|
|
return;
|
2023-10-18 18:50:37 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_VOICE_0);
|
2023-09-13 02:01:35 +01:00
|
|
|
SYSTEM_DelayMs(20);
|
2023-09-09 08:03:56 +01:00
|
|
|
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_VOICE_0);
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if ((VoiceID & 0x80U) == 0)
|
|
|
|
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_VOICE_1);
|
|
|
|
else
|
|
|
|
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_VOICE_1);
|
2023-11-05 20:26:42 +00:00
|
|
|
SYSTICK_Delay250us(4000);
|
2023-09-09 08:03:56 +01:00
|
|
|
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_VOICE_0);
|
2023-11-05 20:26:42 +00:00
|
|
|
SYSTICK_Delay250us(4800);
|
2023-09-09 08:03:56 +01:00
|
|
|
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_VOICE_0);
|
|
|
|
VoiceID <<= 1;
|
2023-11-05 20:26:42 +00:00
|
|
|
SYSTICK_Delay250us(800);
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
|
|
|
}
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-10-08 20:23:37 +01:00
|
|
|
void AUDIO_PlaySingleVoice(bool flag)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
|
|
|
uint8_t Delay;
|
2023-10-11 16:02:45 +01:00
|
|
|
uint8_t VoiceID = g_voice_id[0];
|
|
|
|
|
2023-11-02 10:00:51 +00:00
|
|
|
if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF || g_voice_write_index == 0)
|
2023-10-11 16:02:45 +01:00
|
|
|
goto Bailout;
|
|
|
|
|
2023-11-02 10:00:51 +00:00
|
|
|
if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_CHINESE)
|
2023-10-11 16:02:45 +01:00
|
|
|
{ // Chinese
|
|
|
|
if (VoiceID >= ARRAY_SIZE(VoiceClipLengthChinese))
|
|
|
|
goto Bailout;
|
|
|
|
|
|
|
|
Delay = VoiceClipLengthChinese[VoiceID];
|
|
|
|
VoiceID += VOICE_ID_CHI_BASE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // English
|
|
|
|
if (VoiceID >= ARRAY_SIZE(VoiceClipLengthEnglish))
|
|
|
|
goto Bailout;
|
|
|
|
|
|
|
|
Delay = VoiceClipLengthEnglish[VoiceID];
|
|
|
|
VoiceID += VOICE_ID_ENG_BASE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MUTE_AUDIO_FOR_VOICE
|
2023-10-29 22:33:38 +00:00
|
|
|
if (g_current_function == FUNCTION_RECEIVE)
|
2023-09-09 08:03:56 +01:00
|
|
|
BK4819_SetAF(BK4819_AF_MUTE);
|
2023-10-11 16:02:45 +01:00
|
|
|
#endif
|
2023-10-18 18:50:37 +01:00
|
|
|
|
2023-10-24 11:47:49 +01:00
|
|
|
#ifdef ENABLE_FMRADIO
|
2023-10-11 16:02:45 +01:00
|
|
|
#ifdef MUTE_AUDIO_FOR_VOICE
|
2023-10-08 20:23:37 +01:00
|
|
|
if (g_fm_radio_mode)
|
2023-09-14 09:56:30 +01:00
|
|
|
BK1080_Mute(true);
|
|
|
|
#endif
|
2023-10-11 16:02:45 +01:00
|
|
|
#endif
|
|
|
|
|
2023-10-18 11:31:30 +01:00
|
|
|
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
|
2023-10-11 16:02:45 +01:00
|
|
|
|
|
|
|
#ifdef ENABLE_VOX
|
2023-10-29 22:33:38 +00:00
|
|
|
g_vox_resume_tick_10ms = 2000;
|
2023-10-11 16:02:45 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
SYSTEM_DelayMs(5);
|
2023-10-18 18:50:37 +01:00
|
|
|
|
2023-10-11 16:02:45 +01:00
|
|
|
AUDIO_PlayVoice(VoiceID);
|
|
|
|
|
|
|
|
if (g_voice_write_index == 1)
|
|
|
|
Delay += 3;
|
|
|
|
|
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
SYSTEM_DelayMs(Delay * 10);
|
|
|
|
|
2023-10-29 22:33:38 +00:00
|
|
|
if (g_current_function == FUNCTION_RECEIVE)
|
2023-11-06 14:46:39 +00:00
|
|
|
AUDIO_set_mod_mode(g_rx_vfo->channel.mod_mode);
|
2023-10-30 01:51:41 +00:00
|
|
|
|
2023-10-24 11:47:49 +01:00
|
|
|
#ifdef ENABLE_FMRADIO
|
2023-10-11 16:02:45 +01:00
|
|
|
if (g_fm_radio_mode)
|
|
|
|
BK1080_Mute(false);
|
|
|
|
#endif
|
|
|
|
|
2023-10-30 21:48:29 +00:00
|
|
|
if (!g_squelch_open && !g_monitor_enabled)
|
2023-10-18 11:31:30 +01:00
|
|
|
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
|
2023-10-11 16:02:45 +01:00
|
|
|
|
|
|
|
g_voice_write_index = 0;
|
|
|
|
g_voice_read_index = 0;
|
2023-10-04 11:57:34 +01:00
|
|
|
|
|
|
|
#ifdef ENABLE_VOX
|
2023-10-29 22:33:38 +00:00
|
|
|
g_vox_resume_tick_10ms = 80;
|
2023-10-04 11:57:34 +01:00
|
|
|
#endif
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
return;
|
|
|
|
}
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-10-30 01:51:41 +00:00
|
|
|
g_voice_read_index = 1;
|
2023-10-29 22:33:38 +00:00
|
|
|
g_play_next_voice_tick_10ms = Delay;
|
2023-10-30 01:51:41 +00:00
|
|
|
g_flag_play_queued_voice = false;
|
2023-10-11 16:02:45 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
Bailout:
|
2023-10-08 17:14:13 +01:00
|
|
|
g_voice_read_index = 0;
|
|
|
|
g_voice_write_index = 0;
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-10-08 17:14:13 +01:00
|
|
|
void AUDIO_SetVoiceID(uint8_t Index, voice_id_t VoiceID)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
2023-11-02 10:00:51 +00:00
|
|
|
if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF || Index == 0)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
2023-10-08 17:14:13 +01:00
|
|
|
g_voice_write_index = 0;
|
|
|
|
g_voice_read_index = 0;
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-11-02 10:00:51 +00:00
|
|
|
if (g_eeprom.config.setting.voice_prompt != VOICE_PROMPT_OFF && Index < ARRAY_SIZE(g_voice_id))
|
2023-10-11 16:02:45 +01:00
|
|
|
{
|
|
|
|
g_voice_id[Index] = VoiceID;
|
|
|
|
g_voice_write_index++;
|
|
|
|
}
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
uint8_t AUDIO_SetDigitVoice(uint8_t Index, uint16_t Value)
|
|
|
|
{
|
|
|
|
uint16_t Remainder;
|
|
|
|
uint8_t Result;
|
|
|
|
uint8_t Count;
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-11-02 10:00:51 +00:00
|
|
|
if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF || Index == 0)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
2023-10-08 17:14:13 +01:00
|
|
|
g_voice_write_index = 0;
|
|
|
|
g_voice_read_index = 0;
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-11-02 10:00:51 +00:00
|
|
|
if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF)
|
2023-10-11 16:02:45 +01:00
|
|
|
return 0;
|
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
Count = 0;
|
|
|
|
Result = Value / 1000U;
|
|
|
|
Remainder = Value % 1000U;
|
|
|
|
if (Remainder < 100U)
|
|
|
|
{
|
|
|
|
if (Remainder < 10U)
|
|
|
|
goto Skip;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Result = Remainder / 100U;
|
2023-10-08 17:14:13 +01:00
|
|
|
g_voice_id[g_voice_write_index++] = (voice_id_t)Result;
|
2023-09-09 08:03:56 +01:00
|
|
|
Count++;
|
|
|
|
Remainder -= Result * 100U;
|
|
|
|
}
|
|
|
|
Result = Remainder / 10U;
|
2023-10-08 17:14:13 +01:00
|
|
|
g_voice_id[g_voice_write_index++] = (voice_id_t)Result;
|
2023-09-09 08:03:56 +01:00
|
|
|
Count++;
|
|
|
|
Remainder -= Result * 10U;
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
Skip:
|
2023-10-08 17:14:13 +01:00
|
|
|
g_voice_id[g_voice_write_index++] = (voice_id_t)Remainder;
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
return Count + 1U;
|
|
|
|
}
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
void AUDIO_PlayQueuedVoice(void)
|
|
|
|
{
|
|
|
|
uint8_t VoiceID;
|
|
|
|
uint8_t Delay;
|
2023-10-11 16:02:45 +01:00
|
|
|
bool Skip = false;
|
|
|
|
|
2023-11-02 10:00:51 +00:00
|
|
|
if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF)
|
2023-10-11 16:02:45 +01:00
|
|
|
{
|
|
|
|
g_voice_write_index = 0;
|
|
|
|
g_voice_read_index = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-02 10:00:51 +00:00
|
|
|
if (g_voice_read_index != g_voice_write_index && g_eeprom.config.setting.voice_prompt != VOICE_PROMPT_OFF)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
2023-10-08 17:14:13 +01:00
|
|
|
VoiceID = g_voice_id[g_voice_read_index];
|
2023-11-02 10:00:51 +00:00
|
|
|
if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_CHINESE)
|
2023-09-09 08:03:56 +01:00
|
|
|
{
|
|
|
|
if (VoiceID < ARRAY_SIZE(VoiceClipLengthChinese))
|
|
|
|
{
|
|
|
|
Delay = VoiceClipLengthChinese[VoiceID];
|
|
|
|
VoiceID += VOICE_ID_CHI_BASE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Skip = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (VoiceID < ARRAY_SIZE(VoiceClipLengthEnglish))
|
|
|
|
{
|
|
|
|
Delay = VoiceClipLengthEnglish[VoiceID];
|
|
|
|
VoiceID += VOICE_ID_ENG_BASE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Skip = true;
|
|
|
|
}
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-10-08 17:14:13 +01:00
|
|
|
g_voice_read_index++;
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
if (!Skip)
|
|
|
|
{
|
2023-10-08 17:14:13 +01:00
|
|
|
if (g_voice_read_index == g_voice_write_index)
|
2023-09-09 08:03:56 +01:00
|
|
|
Delay += 3;
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
AUDIO_PlayVoice(VoiceID);
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-10-29 22:33:38 +00:00
|
|
|
g_play_next_voice_tick_10ms = Delay;
|
2023-10-08 17:14:13 +01:00
|
|
|
g_flag_play_queued_voice = false;
|
2023-10-04 11:57:34 +01:00
|
|
|
|
|
|
|
#ifdef ENABLE_VOX
|
2023-10-29 22:33:38 +00:00
|
|
|
g_vox_resume_tick_10ms = 2000;
|
2023-10-04 11:57:34 +01:00
|
|
|
#endif
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-09-09 08:03:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2023-10-11 16:02:45 +01:00
|
|
|
|
|
|
|
// ***********************
|
|
|
|
// unmute the radios audio
|
2023-10-18 18:50:37 +01:00
|
|
|
|
2023-10-29 22:33:38 +00:00
|
|
|
if (g_current_function == FUNCTION_RECEIVE)
|
2023-11-06 14:46:39 +00:00
|
|
|
AUDIO_set_mod_mode(g_rx_vfo->channel.mod_mode);
|
2023-10-30 01:51:41 +00:00
|
|
|
|
2023-10-24 11:47:49 +01:00
|
|
|
#ifdef ENABLE_FMRADIO
|
2023-10-08 20:23:37 +01:00
|
|
|
if (g_fm_radio_mode)
|
2023-09-14 09:56:30 +01:00
|
|
|
BK1080_Mute(false);
|
|
|
|
#endif
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-10-30 21:48:29 +00:00
|
|
|
if (!g_squelch_open && !g_monitor_enabled)
|
2023-10-18 11:31:30 +01:00
|
|
|
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
|
2023-10-11 16:02:45 +01:00
|
|
|
|
|
|
|
// **********************
|
2023-10-18 18:50:37 +01:00
|
|
|
|
2023-10-04 11:57:34 +01:00
|
|
|
#ifdef ENABLE_VOX
|
2023-10-29 22:33:38 +00:00
|
|
|
g_vox_resume_tick_10ms = 80;
|
2023-10-04 11:57:34 +01:00
|
|
|
#endif
|
2023-10-11 16:02:45 +01:00
|
|
|
|
2023-10-08 17:14:13 +01:00
|
|
|
g_voice_write_index = 0;
|
|
|
|
g_voice_read_index = 0;
|
2023-09-09 08:03:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|