-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathtone_table.c
193 lines (170 loc) · 4.63 KB
/
tone_table.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#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