AC63_BT_SDK/apps/mesh/tone_table.c

194 lines
4.6 KiB
C
Raw Permalink Normal View History

2025-02-18 15:40:42 +08:00
#include "tone_player.h"
#include "system/includes.h"
#include "tone_player_api.h"
#include "app_config.h"
#if TCFG_AUDIO_ENABLE
static const char *const tone_index[] = {
TONE_NUM_0,
TONE_NUM_1,
TONE_NUM_2,
TONE_NUM_3,
TONE_NUM_4,
TONE_NUM_5,
TONE_NUM_6,
TONE_NUM_7,
TONE_NUM_8,
TONE_NUM_9,
TONE_BT_MODE,
TONE_BT_CONN,
TONE_BT_DISCONN,
TONE_TWS_CONN,
TONE_TWS_DISCONN,
TONE_LOW_POWER,
TONE_POWER_OFF,
TONE_POWER_ON,
TONE_RING,
TONE_MAX_VOL,
TONE_NORMAL,
};
/*
* :
* freq : * 512
* points :
* win :
* decay : (), *512
*
*/
static const struct sin_param sine_16k_normal[] __BANK_TONE = {
/*{0, 1000, 0, 100},*/
{1000 << 9, 4000, 0, 100},
};
static const struct sin_param sine_low_latency_in[] __BANK_TONE = {
/*{0, 1000, 0, 100},*/
{400 << 9, 4000, 0, 100},
};
static const struct sin_param sine_low_latency_out[] __BANK_TONE = {
/*{0, 1000, 0, 100},*/
{600 << 9, 8000, 0, 100},
};
static const struct sin_param sine_tws_disconnect_16k[] __BANK_TONE = {
/*
{390 << 9, 4026, SINE_TOTAL_VOLUME / 4026},
{262 << 9, 8000, SINE_TOTAL_VOLUME / 8000},
*/
{262 << 9, 4026, 0, 100},
{390 << 9, 8000, 0, 100},
};
static const struct sin_param sine_tws_connect_16k[] __BANK_TONE = {
/*
{262 << 9, 4026, SINE_TOTAL_VOLUME / 4026},
{390 << 9, 8000, SINE_TOTAL_VOLUME / 8000},
*/
{262.298 * 512, 8358, 0, 100},
};
static const struct sin_param sine_low_power[] __BANK_TONE = {
{424 << 9, 3613, 0, 100},
{319 << 9, 3623, 0, 100},
};
static const struct sin_param sine_ring[] __BANK_TONE = {
{450 << 9, 24960, 1, 16.667 * 512},
{0, 16000, 0, 100},
};
static const struct sin_param sine_tws_max_volume[] __BANK_TONE = {
{210 << 9, 2539, 0, 100},
{260 << 9, 7619, 0, 100},
{400 << 9, 2539, 0, 100},
};
__BANK_TONE_ENTRY
static const struct sin_param *get_sine_param_by_index(u8 index, u8 *num)
{
const struct sin_param *param_data;
switch (index) {
case SINE_WTONE_NORAML:
param_data = sine_16k_normal;
*num = ARRAY_SIZE(sine_16k_normal);
break;
case SINE_WTONE_TWS_CONNECT:
param_data = sine_tws_connect_16k;
*num = ARRAY_SIZE(sine_tws_connect_16k);
break;
case SINE_WTONE_TWS_DISCONNECT:
param_data = sine_tws_disconnect_16k;
*num = ARRAY_SIZE(sine_tws_disconnect_16k);
break;
case SINE_WTONE_LOW_POWER:
param_data = sine_low_power;
*num = ARRAY_SIZE(sine_low_power);
break;
case SINE_WTONE_RING:
param_data = sine_ring;
*num = ARRAY_SIZE(sine_ring);
break;
case SINE_WTONE_MAX_VOLUME:
param_data = sine_tws_max_volume;
*num = ARRAY_SIZE(sine_tws_max_volume);
break;
case SINE_WTONE_LOW_LATENRY_IN:
param_data = sine_low_latency_in;
*num = ARRAY_SIZE(sine_low_latency_in);
break;
case SINE_WTONE_LOW_LATENRY_OUT:
param_data = sine_low_latency_out;
*num = ARRAY_SIZE(sine_low_latency_out);
break;
default:
return NULL;
}
return param_data;
}
/*
*index:
*preemption:
*/
__BANK_TONE_ENTRY
int tone_play_index(u8 index, u8 preemption)
{
printf("tone_play_index:%d,preemption:%d", index, preemption);
if (index >= IDEX_TONE_NONE) {
return 0;
}
return tone_play(tone_index[index], preemption);
}
/*
*@brief:
*@return: 0
* 0
*@note:
*/
int tone_name_cmp_by_index(u8 index)
{
if (index >= IDEX_TONE_NONE) {
return 0;
}
return tone_name_compare(tone_index[index]);
}
__BANK_TONE_ENTRY
int tone_play_index_no_tws(u8 index, u8 preemption)
{
printf("tone_play_index no tws:%d,preemption:%d", index, preemption);
if (index >= IDEX_TONE_NONE) {
return 0;
}
return tone_play_no_tws(tone_index[index], preemption);
}
/* __BANK_TONE_ENTRY */
int tone_play_index_with_callback(u8 index, u8 preemption, void (*user_evt_handler)(void *priv), void *priv)
{
printf("tone_play_index:%d,preemption:%d", index, preemption);
if (index >= IDEX_TONE_NONE) {
return 0;
}
return tone_play_with_callback(tone_index[index], preemption, user_evt_handler, priv);
}
__BANK_INIT_ENTRY
int tone_table_init()
{
tone_play_set_sine_param_handler(get_sine_param_by_index);
return 0;
}
__initcall(tone_table_init);
#endif