blob: e9f5145485b52ecd4519225a26b48f81484a2ca2 [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);
xf.lif2330622024-05-15 18:17:18 -070047extern int mix_set_voice_vol_gain(struct mixer *mixer, int vol_gain);
48extern int mix_get_voice_vol_gain(struct mixer *mixer, int *vol_gain);
49extern int mix_set_tx_voice_vol_gain(struct mixer *mixer, int vol_gain);
50extern int mix_get_tx_voice_vol_gain(struct mixer *mixer, int *vol_gain);
xf.libdd93d52023-05-12 07:10:14 -070051
52
53#define VOCIE_SND_CARD_NUM 0
54
55
56
57//设置voice音频设备模式 dev_mode:handset,speaker,headset 0 表示成功ï¼?其它表示有错è¯?
58int set_voice_device_mode(int dev_mode)
59{
60
61 struct mixer *voice_mixer = NULL;
62 printf("%s: start dev_mode=%d!\n",__func__, dev_mode);
63
64 if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
65 printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
66 return -1;
67 }
68
69 //open mixer dev for control
70 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
71 if (!voice_mixer) {
72 printf("voice_mixer open failed!\n");
73 return -1;
74 }
75
76 //config mixer dev
77 mix_set_voice_path(voice_mixer, dev_mode);
78
79 //close mixer
80 mixer_close(voice_mixer);
81 voice_mixer = NULL;
82
83
84 return 0;
85
86
87}
88
89
90
91int sc_audio_set_voice_device_mode(int dev_mode)
92{
93
94 struct mixer *voice_mixer = NULL;
95 printf("%s: start dev_mode=%d!\n",__func__, dev_mode);
96
97 if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
98 printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
99 return -1;
100 }
101
102 //open mixer dev for control
103 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
104 if (!voice_mixer) {
105 printf("voice_mixer open failed!\n");
106 return -1;
107 }
108#ifdef _ALSA_CODEC_IN_CAP
109 mix_set_vp_path(voice_mixer,dev_mode);
110
111#else
112 //config mixer dev
113 mix_set_voice_path(voice_mixer, dev_mode);
114#endif
115
116
117 //close mixer
118 mixer_close(voice_mixer);
119 voice_mixer = NULL;
120
121
122 return 0;
123
124
125}
126
127
128int sc_audio_get_voice_device_mode(int *p_dev_mode)
129{
xf.li742dd022023-06-08 01:43:32 -0700130 int ret = 0;
xf.libdd93d52023-05-12 07:10:14 -0700131 struct mixer *voice_mixer = NULL;
132 printf("%s: start!\n",__func__);
133
134 //open mixer dev for control
135 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
136 if (!voice_mixer) {
137 printf("voice_mixer open failed!\n");
138 return -1;
139 }
140
141 //config mixer dev
142 mix_get_vp_path(voice_mixer, p_dev_mode);
143
144
145 if((*p_dev_mode < T_OUTPUT_HANDSET ) ||(*p_dev_mode >= T_OUTPUT_MAX)){
146 printf("%s: dev_mode not support, *p_dev_mode=%d!\n",__func__, *p_dev_mode);
xf.li742dd022023-06-08 01:43:32 -0700147 ret = -1;
xf.libdd93d52023-05-12 07:10:14 -0700148 }
149 printf("%s: start *p_dev_mode=%d!\n",__func__, *p_dev_mode);
150
151 //close mixer
152 mixer_close(voice_mixer);
153 voice_mixer = NULL;
154
xf.li742dd022023-06-08 01:43:32 -0700155 return ret;
xf.libdd93d52023-05-12 07:10:14 -0700156
157}
158
159
160int sc_audio_set_rx_voice_vol(int vol)
161{
162 struct mixer *voice_mixer = NULL;
163 printf("%s: start vol=%d!\n",__func__, vol);
164
165 if ((vol < 0 ) ||(vol > 11)){
166 printf("%s: vol not support, vol=%d!\n",__func__, vol);
167 return -1;
168 }
169
170 //open mixer dev for control
171 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
172 if (!voice_mixer) {
173 printf("voice_mixer open failed!\n");
174 return -1;
175 }
176
177 //config mixer dev
178 mix_set_voice_vol(voice_mixer, vol);
179
180 //close mixer
181 mixer_close(voice_mixer);
182 voice_mixer = NULL;
183
184
185 return 0;
186
187
188
189
190}
191
192
193
194int sc_audio_get_rx_voice_vol(int * p_vol)
195{
xf.li742dd022023-06-08 01:43:32 -0700196 int ret = 0;
xf.libdd93d52023-05-12 07:10:14 -0700197 struct mixer *voice_mixer = NULL;
198
199 printf("%s: start!\n",__func__);
200
201 //open mixer dev for control
202 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
203 if (!voice_mixer) {
204 printf("voice_mixer open failed!\n");
205 return -1;
206 }
207
208 //config mixer dev
209 mix_get_voice_vol(voice_mixer, p_vol);
210
211
212 if ((*p_vol < 0 ) ||(*p_vol > 11)){
213 printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
xf.li742dd022023-06-08 01:43:32 -0700214 ret = -1;
xf.libdd93d52023-05-12 07:10:14 -0700215 }
216 printf("%s: *p_vol=%d!\n",__func__, *p_vol);
217
218 //close mixer
219 mixer_close(voice_mixer);
220 voice_mixer = NULL;
221
222
xf.li742dd022023-06-08 01:43:32 -0700223 return ret;
xf.libdd93d52023-05-12 07:10:14 -0700224
225
226
227}
228
xf.lif2330622024-05-15 18:17:18 -0700229int sc_audio_set_rx_voice_vol_gain(int gain)
230{
231 struct mixer *voice_mixer = NULL;
232 printf("%s: start vol=%d!\n",__func__, gain);
xf.libdd93d52023-05-12 07:10:14 -0700233
xf.lif2330622024-05-15 18:17:18 -0700234 if ((gain < -15 ) ||(gain > 24)){
235 printf("%s: gain not support, gain=%d!\n",__func__, gain);
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_voice_vol_gain(voice_mixer, gain);
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_rx_voice_vol_gain(int * p_gain)
262{
263 int ret = 0;
264 struct mixer *voice_mixer = NULL;
265
266 printf("%s: start!\n",__func__);
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_voice_vol_gain(voice_mixer, p_gain);
277
278
279 if ((*p_gain < -15 ) ||(*p_gain > 24)){
280 printf("%s: gain not support, *p_gain=%d!\n",__func__, *p_gain);
281 ret = -1;
282 }
283 printf("%s: *p_gain=%d!\n",__func__, *p_gain);
284
285 //close mixer
286 mixer_close(voice_mixer);
287 voice_mixer = NULL;
288
289
290 return ret;
291
292
293
294}
295
296int sc_audio_set_tx_voice_vol_gain(int gain)
297{
298 struct mixer *voice_mixer = NULL;
299 printf("%s: start vol=%d!\n",__func__, gain);
300
301 if ((gain < -15 ) ||(gain > 24)){
302 printf("%s: gain not support, gain=%d!\n",__func__, gain);
303 return -1;
304 }
305
306 //open mixer dev for control
307 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
308 if (!voice_mixer) {
309 printf("voice_mixer open failed!\n");
310 return -1;
311 }
312
313 //config mixer dev
314 mix_set_tx_voice_vol_gain(voice_mixer, gain);
315
316 //close mixer
317 mixer_close(voice_mixer);
318 voice_mixer = NULL;
319
320
321 return 0;
322
323
324
325
326}
327
328int sc_audio_get_tx_voice_vol_gain(int * p_gain)
329{
330 int ret = 0;
331 struct mixer *voice_mixer = NULL;
332
333 printf("%s: start!\n",__func__);
334
335 //open mixer dev for control
336 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
337 if (!voice_mixer) {
338 printf("voice_mixer open failed!\n");
339 return -1;
340 }
341
342 //config mixer dev
343 mix_get_tx_voice_vol_gain(voice_mixer, p_gain);
344
345
346 if ((*p_gain < -15 ) ||(*p_gain > 24)){
347 printf("%s: gain not support, *p_gain=%d!\n",__func__, *p_gain);
348 ret = -1;
349 }
350 printf("%s: *p_gain=%d!\n",__func__, *p_gain);
351
352 //close mixer
353 mixer_close(voice_mixer);
354 voice_mixer = NULL;
355
356
357 return ret;
358
359
360
361}
xf.libdd93d52023-05-12 07:10:14 -0700362
363int sc_audio_set_tx_voice_vol(int vol)
364{
365 struct mixer *voice_mixer = NULL;
366 printf("%s: start vol=%d!\n",__func__, vol);
367
368 if ((vol < 0 ) ||(vol > 11)){
369 printf("%s: vol not support, vol=%d!\n",__func__, vol);
370 return -1;
371 }
372
373 //open mixer dev for control
374 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
375 if (!voice_mixer) {
376 printf("voice_mixer open failed!\n");
377 return -1;
378 }
379
380 //config mixer dev
381 mix_set_tx_voice_vol(voice_mixer, vol);
382
383 //close mixer
384 mixer_close(voice_mixer);
385 voice_mixer = NULL;
386
387
388 return 0;
389
390
391}
392
393
394
395int sc_audio_get_tx_voice_vol(int *p_vol)
396{
xf.li742dd022023-06-08 01:43:32 -0700397 int ret = 0;
xf.libdd93d52023-05-12 07:10:14 -0700398 struct mixer *voice_mixer = NULL;
399 printf("%s: start!\n",__func__);
400
401
402 //open mixer dev for control
403 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
404 if (!voice_mixer) {
405 printf("voice_mixer open failed!\n");
406 return -1;
407 }
408
409 //config mixer dev
410 mix_get_tx_voice_vol(voice_mixer, p_vol);
411
412
413 if((*p_vol < 0 ) ||(*p_vol > 5)){
414 printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
xf.li742dd022023-06-08 01:43:32 -0700415 ret = -1;
xf.libdd93d52023-05-12 07:10:14 -0700416 }
417 printf("%s: *p_vol=%d!\n",__func__, *p_vol);
418
419 //close mixer
420 mixer_close(voice_mixer);
421 voice_mixer = NULL;
xf.li742dd022023-06-08 01:43:32 -0700422 return ret;
xf.libdd93d52023-05-12 07:10:14 -0700423}
424
425
426
427int sc_audio_set_tx_voice_mute_state(int mute )
428{
429 struct mixer *voice_mixer = NULL;
430 printf("%s: start mute=%d!\n",__func__, mute);
431
432 if((mute != 0 ) &&(mute != 1)) {
433 printf("%s: mute not support, mute=%d!\n",__func__, mute);
434 return -1;
435 }
436
437 //open mixer dev for control
438 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
439 if (!voice_mixer) {
440 printf("voice_mixer open failed!\n");
441 return -1;
442 }
443
444 //config mixer dev
445 mix_set_voice_mute(voice_mixer, mute);
446
447 //close mixer
448 mixer_close(voice_mixer);
449 voice_mixer = NULL;
450 return 0;
451
452}
453
454int sc_audio_get_tx_voice_mute_state(int *p_mute)
455{
xf.li742dd022023-06-08 01:43:32 -0700456 int ret = 0;
xf.libdd93d52023-05-12 07:10:14 -0700457 struct mixer *voice_mixer = NULL;
458
459 printf("%s: start!\n",__func__);
460
461 //open mixer dev for control
462 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
463 if (!voice_mixer) {
464 printf("voice_mixer open failed!\n");
465 return -1;
466 }
467
468 //config mixer dev
469 mix_get_voice_mute(voice_mixer, p_mute);
470
471
472 if((*p_mute != 0 ) &&(*p_mute != 1)) {
473 printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
xf.li742dd022023-06-08 01:43:32 -0700474
475 ret = -1;
xf.libdd93d52023-05-12 07:10:14 -0700476 }
477 printf("%s: *p_mute=%d!\n",__func__, *p_mute);
478
479 //close mixer
480 mixer_close(voice_mixer);
481 voice_mixer = NULL;
482
xf.li742dd022023-06-08 01:43:32 -0700483 return ret;
xf.libdd93d52023-05-12 07:10:14 -0700484}
485
486
487
488
489
490
491
492int sc_audio_set_rx_voice_mute_state(int mute)
493{
494 struct mixer *voice_mixer = NULL;
495 printf("%s: start mute=%d!\n",__func__, mute);
496
497 if((mute != 0 ) &&(mute != 1)) {
498 printf("%s: mute not support, mute=%d!\n",__func__, mute);
499 return -1;
500 }
501
502 //open mixer dev for control
503 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
504 if (!voice_mixer) {
505 printf("voice_mixer open failed!\n");
506 return -1;
507 }
508
509 //config mixer dev
510 mix_set_rx_voice_mute(voice_mixer, mute);
511
512 //close mixer
513 mixer_close(voice_mixer);
514 voice_mixer = NULL;
515 return 0;
516
517}
518
519
xf.li742dd022023-06-08 01:43:32 -0700520int sc_audio_get_rx_voice_mute_state(int *p_mute)
521{
522 int ret = 0;
xf.libdd93d52023-05-12 07:10:14 -0700523 struct mixer *voice_mixer = NULL;
524
525 printf("%s: start!\n",__func__);
526
527 //open mixer dev for control
528 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
529 if (!voice_mixer) {
530 printf("voice_mixer open failed!\n");
531 return -1;
532 }
533
534 //config mixer dev
535 mix_get_rx_voice_mute(voice_mixer, p_mute);
536
537 if((*p_mute != 0 ) &&(*p_mute != 1)) {
538
539 printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
xf.li742dd022023-06-08 01:43:32 -0700540 ret = -1;
xf.libdd93d52023-05-12 07:10:14 -0700541 }
542 printf("%s: *p_mute=%d!\n",__func__, *p_mute);
543
544 //close mixer
545 mixer_close(voice_mixer);
546 voice_mixer = NULL;
547
xf.li742dd022023-06-08 01:43:32 -0700548 return ret;
xf.libdd93d52023-05-12 07:10:14 -0700549
550}
551
552int sc_audio_set_loopback_enable_state(int enable)
553{
554 return 0;
555}
556
557int sc_audio_get_loopback_enable_state(int *p_enable)
558{
559 return 0;
560}
561
lh758261d2023-07-13 05:52:04 -0700562int ap_audio_set_loopback_enable(int dev_mode,int enable)
563{
564
565 struct mixer *voice_mixer = NULL;
566 int ret = 0;
567 struct pcm_config config_voice = {0};
568
569
570 printf("%s: start dev_mode=%d,enable=%d!\n",__func__, dev_mode,enable);
571
572 if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
573 printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
574 return -1;
575 }
576 if ((enable != 0 )&&(enable != 1)){
577 printf("%s: enable val not support, enable=%d!\n",__func__, enable);
578 return -1;
579 }
580 if(enable == 1){
581
582 //open mixer dev for control
583 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
584 if (!voice_mixer) {
585 printf("voice_mixer open failed!\n");
586 return -1;
587 }
588
589 //config mixer dev
590 ret = mix_set_voice_path(voice_mixer, dev_mode);
591 printf("mix_set_voice_path ret=%d!\n",ret);
592
593 ret = mix_set_vploop(voice_mixer, dev_mode);
594 printf("mix_set_vploop ret=%d!\n",ret);
595
596 //close mixer
597 mixer_close(voice_mixer);
598 voice_mixer = NULL;
599
600
601
602
603
604
605 }
606 else{
607
608 //open mixer dev for control
609 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
610 if (!voice_mixer) {
611 printf("voice_mixer open failed!\n");
612 return -1;
613 }
614
615
616 ret = mix_set_vploop(voice_mixer, VP_PATH_OFF);
617 //close mixer
618 mixer_close(voice_mixer);
619 voice_mixer = NULL;
620
621
622 printf("mix_set_vploop off end ret=%d!\n",ret);
623
624
625
626
627
628 }
629
630 //return 0;
631
632 printf("%s: end enable=%d!\n",__func__, enable);
633
634 return ret;
635
636
637}
638
639
640
641int ap_audio_get_loopback_enable(int *p_enable)
642{
643 struct mixer *voice_mixer = NULL;
644 int ret = 0;
645 printf("%s: start!\n",__func__);
646
647 //open mixer dev for control
648 voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
649 if (!voice_mixer) {
650 printf("voice_mixer open failed!\n");
651 return -1;
652 }
653
654 //config mixer dev
655 ret = mix_get_vploop(voice_mixer, p_enable);
656 if((*p_enable != 0 ) &&(*p_enable != 1)){
657 printf("%s: p_enable not support, *p_enable=%d!\n",__func__, *p_enable);
658 ret = -1;
659 }
660 printf("%s: end *p_enable=%d!\n",__func__, *p_enable);
661
662 //close mixer
663 mixer_close(voice_mixer);
664 voice_mixer = NULL;
665
666 return ret;
667
668}
669
670