blob: 3494e74fdf376bb402974ff79d7b0dd038b98b7a [file] [log] [blame]
xf.libdd93d52023-05-12 07:10:14 -07001/**
2 * @file voice_api.c
3 * @brief Implementation of the public APIs of libvoice.
4 *
5 * Copyright (C) 2023 Sanechips Technology Co., Ltd.
6 * @author
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation. £¨±ØÑ¡£ºGPLv2 Licence£©
11 *
12 */
13
14
15
16#include <stdio.h>
17#include <unistd.h>
18#include <string.h>
19#include <stdlib.h>
20
21#include <stdint.h>
22//#include "volte_drv.h"
23#include <linux/volte_drv.h>
24
25#include <sys/ioctl.h>
26#include <fcntl.h>
27#include <tinyalsa/audio_mixer_ctrl.h>
28#include "voice_lib.h"
29
30#define VOCIE_SND_CARD_NUM 0
31
32
33extern int mix_set_voice_vol(struct mixer *mixer, int volume);
34extern int mix_get_voice_vol(struct mixer *mixer, int *volume);
35extern int mix_set_tx_voice_vol(struct mixer *mixer, int volume);
36extern int mix_get_tx_voice_vol(struct mixer *mixer, int *volume);
37extern int mix_set_voice_mute(struct mixer *mixer, bool enable);
38extern int mix_get_voice_mute(struct mixer *mixer, int *enable);
39extern int mix_set_rx_voice_mute(struct mixer *mixer, bool enable);
40extern int mix_get_rx_voice_mute(struct mixer *mixer, int *enable);
41extern int mix_set_voice_path(struct mixer *mixer, int path);
42extern int mix_set_vp_path(struct mixer *mixer, char path);
43extern int mix_get_vp_path(struct mixer *mixer, int *path);
44extern int mix_get_voice_path(struct mixer *mixer, int *path);
lh758261d2023-07-13 05:52:04 -070045extern int mix_set_vploop(struct mixer *mixer, int path);
46extern int mix_get_vploop(struct mixer *mixer, int *state);
47
xf.libdd93d52023-05-12 07:10:14 -070048
49
50
51#define VOCIE_SND_CARD_NUM 0
52
53
54
55//设置voice音频设备模式 dev_mode:handset,speaker,headset 0 表示成功ï¼?其它表示有错è¯?
56int set_voice_device_mode(int dev_mode)
57{
58
59 struct mixer *voice_mixer = NULL;
60 printf("%s: start dev_mode=%d!\n",__func__, dev_mode);
61
62 if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
63 printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
64 return -1;
65 }
66
67 //open mixer dev for control
68 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
69 if (!voice_mixer) {
70 printf("voice_mixer open failed!\n");
71 return -1;
72 }
73
74 //config mixer dev
75 mix_set_voice_path(voice_mixer, dev_mode);
76
77 //close mixer
78 mixer_close(voice_mixer);
79 voice_mixer = NULL;
80
81
82 return 0;
83
84
85}
86
87
88
89int sc_audio_set_voice_device_mode(int dev_mode)
90{
91
92 struct mixer *voice_mixer = NULL;
93 printf("%s: start dev_mode=%d!\n",__func__, dev_mode);
94
95 if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
96 printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
97 return -1;
98 }
99
100 //open mixer dev for control
101 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
102 if (!voice_mixer) {
103 printf("voice_mixer open failed!\n");
104 return -1;
105 }
106#ifdef _ALSA_CODEC_IN_CAP
107 mix_set_vp_path(voice_mixer,dev_mode);
108
109#else
110 //config mixer dev
111 mix_set_voice_path(voice_mixer, dev_mode);
112#endif
113
114
115 //close mixer
116 mixer_close(voice_mixer);
117 voice_mixer = NULL;
118
119
120 return 0;
121
122
123}
124
125
126int sc_audio_get_voice_device_mode(int *p_dev_mode)
127{
xf.li742dd022023-06-08 01:43:32 -0700128 int ret = 0;
xf.libdd93d52023-05-12 07:10:14 -0700129 struct mixer *voice_mixer = NULL;
130 printf("%s: start!\n",__func__);
131
132 //open mixer dev for control
133 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
134 if (!voice_mixer) {
135 printf("voice_mixer open failed!\n");
136 return -1;
137 }
138
139 //config mixer dev
140 mix_get_vp_path(voice_mixer, p_dev_mode);
141
142
143 if((*p_dev_mode < T_OUTPUT_HANDSET ) ||(*p_dev_mode >= T_OUTPUT_MAX)){
144 printf("%s: dev_mode not support, *p_dev_mode=%d!\n",__func__, *p_dev_mode);
xf.li742dd022023-06-08 01:43:32 -0700145 ret = -1;
xf.libdd93d52023-05-12 07:10:14 -0700146 }
147 printf("%s: start *p_dev_mode=%d!\n",__func__, *p_dev_mode);
148
149 //close mixer
150 mixer_close(voice_mixer);
151 voice_mixer = NULL;
152
xf.li742dd022023-06-08 01:43:32 -0700153 return ret;
xf.libdd93d52023-05-12 07:10:14 -0700154
155}
156
157
158int sc_audio_set_rx_voice_vol(int vol)
159{
160 struct mixer *voice_mixer = NULL;
161 printf("%s: start vol=%d!\n",__func__, vol);
162
163 if ((vol < 0 ) ||(vol > 11)){
164 printf("%s: vol not support, vol=%d!\n",__func__, vol);
165 return -1;
166 }
167
168 //open mixer dev for control
169 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
170 if (!voice_mixer) {
171 printf("voice_mixer open failed!\n");
172 return -1;
173 }
174
175 //config mixer dev
176 mix_set_voice_vol(voice_mixer, vol);
177
178 //close mixer
179 mixer_close(voice_mixer);
180 voice_mixer = NULL;
181
182
183 return 0;
184
185
186
187
188}
189
190
191
192int sc_audio_get_rx_voice_vol(int * p_vol)
193{
xf.li742dd022023-06-08 01:43:32 -0700194 int ret = 0;
xf.libdd93d52023-05-12 07:10:14 -0700195 struct mixer *voice_mixer = NULL;
196
197 printf("%s: start!\n",__func__);
198
199 //open mixer dev for control
200 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
201 if (!voice_mixer) {
202 printf("voice_mixer open failed!\n");
203 return -1;
204 }
205
206 //config mixer dev
207 mix_get_voice_vol(voice_mixer, p_vol);
208
209
210 if ((*p_vol < 0 ) ||(*p_vol > 11)){
211 printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
xf.li742dd022023-06-08 01:43:32 -0700212 ret = -1;
xf.libdd93d52023-05-12 07:10:14 -0700213 }
214 printf("%s: *p_vol=%d!\n",__func__, *p_vol);
215
216 //close mixer
217 mixer_close(voice_mixer);
218 voice_mixer = NULL;
219
220
xf.li742dd022023-06-08 01:43:32 -0700221 return ret;
xf.libdd93d52023-05-12 07:10:14 -0700222
223
224
225}
226
227
228
229int sc_audio_set_tx_voice_vol(int vol)
230{
231 struct mixer *voice_mixer = NULL;
232 printf("%s: start vol=%d!\n",__func__, vol);
233
234 if ((vol < 0 ) ||(vol > 11)){
235 printf("%s: vol not support, vol=%d!\n",__func__, vol);
236 return -1;
237 }
238
239 //open mixer dev for control
240 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
241 if (!voice_mixer) {
242 printf("voice_mixer open failed!\n");
243 return -1;
244 }
245
246 //config mixer dev
247 mix_set_tx_voice_vol(voice_mixer, vol);
248
249 //close mixer
250 mixer_close(voice_mixer);
251 voice_mixer = NULL;
252
253
254 return 0;
255
256
257}
258
259
260
261int sc_audio_get_tx_voice_vol(int *p_vol)
262{
xf.li742dd022023-06-08 01:43:32 -0700263 int ret = 0;
xf.libdd93d52023-05-12 07:10:14 -0700264 struct mixer *voice_mixer = NULL;
265 printf("%s: start!\n",__func__);
266
267
268 //open mixer dev for control
269 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
270 if (!voice_mixer) {
271 printf("voice_mixer open failed!\n");
272 return -1;
273 }
274
275 //config mixer dev
276 mix_get_tx_voice_vol(voice_mixer, p_vol);
277
278
279 if((*p_vol < 0 ) ||(*p_vol > 5)){
280 printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
xf.li742dd022023-06-08 01:43:32 -0700281 ret = -1;
xf.libdd93d52023-05-12 07:10:14 -0700282 }
283 printf("%s: *p_vol=%d!\n",__func__, *p_vol);
284
285 //close mixer
286 mixer_close(voice_mixer);
287 voice_mixer = NULL;
xf.li742dd022023-06-08 01:43:32 -0700288 return ret;
xf.libdd93d52023-05-12 07:10:14 -0700289}
290
291
292
293int sc_audio_set_tx_voice_mute_state(int mute )
294{
295 struct mixer *voice_mixer = NULL;
296 printf("%s: start mute=%d!\n",__func__, mute);
297
298 if((mute != 0 ) &&(mute != 1)) {
299 printf("%s: mute not support, mute=%d!\n",__func__, mute);
300 return -1;
301 }
302
303 //open mixer dev for control
304 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
305 if (!voice_mixer) {
306 printf("voice_mixer open failed!\n");
307 return -1;
308 }
309
310 //config mixer dev
311 mix_set_voice_mute(voice_mixer, mute);
312
313 //close mixer
314 mixer_close(voice_mixer);
315 voice_mixer = NULL;
316 return 0;
317
318}
319
320int sc_audio_get_tx_voice_mute_state(int *p_mute)
321{
xf.li742dd022023-06-08 01:43:32 -0700322 int ret = 0;
xf.libdd93d52023-05-12 07:10:14 -0700323 struct mixer *voice_mixer = NULL;
324
325 printf("%s: start!\n",__func__);
326
327 //open mixer dev for control
328 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
329 if (!voice_mixer) {
330 printf("voice_mixer open failed!\n");
331 return -1;
332 }
333
334 //config mixer dev
335 mix_get_voice_mute(voice_mixer, p_mute);
336
337
338 if((*p_mute != 0 ) &&(*p_mute != 1)) {
339 printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
xf.li742dd022023-06-08 01:43:32 -0700340
341 ret = -1;
xf.libdd93d52023-05-12 07:10:14 -0700342 }
343 printf("%s: *p_mute=%d!\n",__func__, *p_mute);
344
345 //close mixer
346 mixer_close(voice_mixer);
347 voice_mixer = NULL;
348
xf.li742dd022023-06-08 01:43:32 -0700349 return ret;
xf.libdd93d52023-05-12 07:10:14 -0700350}
351
352
353
354
355
356
357
358int sc_audio_set_rx_voice_mute_state(int mute)
359{
360 struct mixer *voice_mixer = NULL;
361 printf("%s: start mute=%d!\n",__func__, mute);
362
363 if((mute != 0 ) &&(mute != 1)) {
364 printf("%s: mute not support, mute=%d!\n",__func__, mute);
365 return -1;
366 }
367
368 //open mixer dev for control
369 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
370 if (!voice_mixer) {
371 printf("voice_mixer open failed!\n");
372 return -1;
373 }
374
375 //config mixer dev
376 mix_set_rx_voice_mute(voice_mixer, mute);
377
378 //close mixer
379 mixer_close(voice_mixer);
380 voice_mixer = NULL;
381 return 0;
382
383}
384
385
xf.li742dd022023-06-08 01:43:32 -0700386int sc_audio_get_rx_voice_mute_state(int *p_mute)
387{
388 int ret = 0;
xf.libdd93d52023-05-12 07:10:14 -0700389 struct mixer *voice_mixer = NULL;
390
391 printf("%s: start!\n",__func__);
392
393 //open mixer dev for control
394 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
395 if (!voice_mixer) {
396 printf("voice_mixer open failed!\n");
397 return -1;
398 }
399
400 //config mixer dev
401 mix_get_rx_voice_mute(voice_mixer, p_mute);
402
403 if((*p_mute != 0 ) &&(*p_mute != 1)) {
404
405 printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
xf.li742dd022023-06-08 01:43:32 -0700406 ret = -1;
xf.libdd93d52023-05-12 07:10:14 -0700407 }
408 printf("%s: *p_mute=%d!\n",__func__, *p_mute);
409
410 //close mixer
411 mixer_close(voice_mixer);
412 voice_mixer = NULL;
413
xf.li742dd022023-06-08 01:43:32 -0700414 return ret;
xf.libdd93d52023-05-12 07:10:14 -0700415
416}
417
418int sc_audio_set_loopback_enable_state(int enable)
419{
420 return 0;
421}
422
423int sc_audio_get_loopback_enable_state(int *p_enable)
424{
425 return 0;
426}
427
lh758261d2023-07-13 05:52:04 -0700428int ap_audio_set_loopback_enable(int dev_mode,int enable)
429{
430
431 struct mixer *voice_mixer = NULL;
432 int ret = 0;
433 struct pcm_config config_voice = {0};
434
435
436 printf("%s: start dev_mode=%d,enable=%d!\n",__func__, dev_mode,enable);
437
438 if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
439 printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
440 return -1;
441 }
442 if ((enable != 0 )&&(enable != 1)){
443 printf("%s: enable val not support, enable=%d!\n",__func__, enable);
444 return -1;
445 }
446 if(enable == 1){
447
448 //open mixer dev for control
449 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
450 if (!voice_mixer) {
451 printf("voice_mixer open failed!\n");
452 return -1;
453 }
454
455 //config mixer dev
456 ret = mix_set_voice_path(voice_mixer, dev_mode);
457 printf("mix_set_voice_path ret=%d!\n",ret);
458
459 ret = mix_set_vploop(voice_mixer, dev_mode);
460 printf("mix_set_vploop ret=%d!\n",ret);
461
462 //close mixer
463 mixer_close(voice_mixer);
464 voice_mixer = NULL;
465
466
467
468
469
470
471 }
472 else{
473
474 //open mixer dev for control
475 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
476 if (!voice_mixer) {
477 printf("voice_mixer open failed!\n");
478 return -1;
479 }
480
481
482 ret = mix_set_vploop(voice_mixer, VP_PATH_OFF);
483 //close mixer
484 mixer_close(voice_mixer);
485 voice_mixer = NULL;
486
487
488 printf("mix_set_vploop off end ret=%d!\n",ret);
489
490
491
492
493
494 }
495
496 //return 0;
497
498 printf("%s: end enable=%d!\n",__func__, enable);
499
500 return ret;
501
502
503}
504
505
506
507int ap_audio_get_loopback_enable(int *p_enable)
508{
509 struct mixer *voice_mixer = NULL;
510 int ret = 0;
511 printf("%s: start!\n",__func__);
512
513 //open mixer dev for control
514 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
515 if (!voice_mixer) {
516 printf("voice_mixer open failed!\n");
517 return -1;
518 }
519
520 //config mixer dev
521 ret = mix_get_vploop(voice_mixer, p_enable);
522 if((*p_enable != 0 ) &&(*p_enable != 1)){
523 printf("%s: p_enable not support, *p_enable=%d!\n",__func__, *p_enable);
524 ret = -1;
525 }
526 printf("%s: end *p_enable=%d!\n",__func__, *p_enable);
527
528 //close mixer
529 mixer_close(voice_mixer);
530 voice_mixer = NULL;
531
532 return ret;
533
534}
535
536