blob: 3e4923b6040ff01ba9a276d0ad14bbd74a3e130e [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 *
3 * Based on 7510_dev.c
4 *
5 */
6
7#include <tinyalsa/audio_mixer_ctrl.h>
8
9
10struct pcm *voicePcmOut = NULL;
11struct pcm *voicePcmIn = NULL;
12
13typedef struct
14{
15 // uint32_t voice_mode;//0, 2/3g;1, volte nb;2 ,volte wb;
16 uint32_t clock_rate; //8000, 2/3g;8000, volte nb;16000 ,volte wb;
17 uint32_t channel_count;
18 uint32_t samples_per_frame;//160, 2/3g;160, volte nb;320 ,volte wb;
19 uint32_t bits_per_sample;
20} T_voiceCfg;
21
22T_voiceCfg cfgParam = {0,8000,1,160,16};
23
24
25
26
27 int voice_PreOpen(T_voiceCfg *cfgParam)
28{
29 struct mixer *voice_mixer = NULL;
30 struct pcm_config config_voice = {0};
31
32 /* open mixer dev for codec control */
33 voice_mixer = mixer_open(0);
34 if(!voice_mixer)
35 {
36 printf("zte voice_mixer open failed!");
37 goto err_ret;
38 }
39
40 /* config mixer dev */
41 mix_set_voice_path(voice_mixer, T_OUTPUT_SPEAKER);
42 mix_set_voice_vol(voice_mixer, T_VOICE_VOL_3_LEVEL);
43
44 /*close mixer */
45 mixer_close(voice_mixer);
46 voice_mixer = NULL;
47
48 /* open pcm dev for data tranf*/
49 config_voice.channels = cfgParam->channel_count;
50 config_voice.rate = cfgParam->clock_rate;
51 /* buffer num */
52 config_voice.period_count = 3;
53 /* buffer size */
54 config_voice.period_size = cfgParam->samples_per_frame * cfgParam->bits_per_sample / 8;
55 /* 16-bit signed */
56 config_voice.format = PCM_FORMAT_S16_LE;
57
58 //card 0 dev 1
59 //23G card 0 dev 2
60 voicePcmOut = pcm_open(0, 1, PCM_OUT, &config_voice);
61 if(!voicePcmOut || !pcm_is_ready(voicePcmOut))
62 {
63 printf( "zte voicePcmOut open failed!");
64 goto err_ret;
65 }
66
67 voicePcmIn = pcm_open(0, 1, PCM_IN, &config_voice);
68 if(!voicePcmIn || !pcm_is_ready(voicePcmIn))
69 {
70 printf( "zte voicePcmIn open failed!");
71 goto err_ret;
72 }
73
74 if(0 != pcm_prepare(voicePcmOut))
75 {
76 printf("zte voicePcmOut pcm_prepare failed!");
77 goto err_ret;
78 }
79
80 if(0 != pcm_prepare(voicePcmIn))
81 {
82 printf("zte voicePcmIn pcm_prepare failed!");
83 goto err_ret;
84 }
85 return 0;
86err_ret:
87 if(voice_mixer)
88 {
89 mixer_close(voice_mixer);
90 voice_mixer = NULL;
91 }
92
93 if(voicePcmOut)
94 {
95 pcm_close(voicePcmOut);
96 voicePcmOut = NULL;
97 }
98 if(voicePcmIn)
99 {
100 pcm_close(voicePcmIn);
101 voicePcmIn = NULL;
102 }
103 return -1;
104
105}
106
107
108 void voice_PreClose(void)
109{
110 if(voicePcmOut)
111 {
112 pcm_close(voicePcmOut);
113 voicePcmOut = NULL;
114 }
115 if(voicePcmIn)
116 {
117 pcm_close(voicePcmIn);
118 voicePcmIn = NULL;
119 }
120}
121
122