blob: 72f82cec47f278474f07bf4c234f7991d28a80c6 [file] [log] [blame]
xf.libdd93d52023-05-12 07:10:14 -07001/*****************************************************************************
2** °æÈ¨ËùÓÐ (C)2015, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
3**
4** ÎļþÃû³Æ: alsa_voice.c
5** Îļþ±êʶ:
6** ÄÚÈÝÕªÒª:
7** ʹÓ÷½·¨:
8**
9** ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
10** -----------------------------------------------------------------------------
11** 2019/09/25 V1.0 Create xxq ´´½¨
12**
13* ******************************************************************************/
14#ifdef _USE_VOICE_ALSA
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 <sys/ioctl.h>
24#include <fcntl.h>
25#include <tinyalsa/audio_mixer_ctrl.h>
26
27
28
29#include <stdbool.h>
30#include "tinyalsa/asoundlib.h"
31#include "tinyalsa/audio_mixer_ctrl.h"
32//#include "audio_res_ctrl.h"
33#include "voice_lib.h"
34
35
36/**************************************************************************
37* ºê¶¨Òå *
38**************************************************************************/
39
40//#define AVOICE_TEAK_2G_3G_DEV_NUM 3
41//#define AVOICE_SOFT_3G_DEV_NUM 4
42//#define AVOICE_4G_DEV_NUM 2
43//#define AVOICE_5G_DEV_NUM 2
44
45/**************************************************************************
46* ÀàÐͶ¨Òå *
47**************************************************************************/
48/*
49typedef enum
50{
51 AVOICE_TEAK_2G_3G = 0,
52 AVOICE_SOFT_3G_NB,//1
53 AVOICE_SOFT_3G_WB, //2
54 AVOICE_4G_NB, //3
55 AVOICE_4G_WB, //4
56 AVOICE_5G_NB,//5
57 AVOICE_5G_WB,//6
58 MAX_AVOICE_MODE
59}T_Alsa_Voice_Mode;
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/* start for testing ctm*/
89
90/* data type for voice device handle */
91
92struct voice_handle
93{
94 struct pcm *pcm_voice_out;
95 struct pcm *pcm_voice_in;
96};
97
98/* static handle */
99static struct voice_handle voice_handle = {0};
100
101static int current_chanl = T_OUTPUT_RECEIVER;//T_OUTPUT_HEADSET;//T_OUTPUT_RECEIVER;
102static int current_vol = T_VOICE_VOL_5_LEVEL;
103static int dev_num = 1;
104static int current_mode = MAX_AVOICE_MODE;
105char* vocie_mode[]={"AVOICE_TEAK_2G_3G","AVOICE_SOFT_3G_NB","AVOICE_SOFT_3G_WB","AVOICE_4G_NB","AVOICE_4G_WB","AVOICE_5G_NB","AVOICE_5G_WB"};
106
107/*
108 * phone call
109 */
110int alsa_voice_open(int vmode)
111{
112 int ret = 0;
113 //int status = 0;
114 struct pcm_config config_voice = {0};
115 struct mxier *voice_mixer = NULL;
116
117 printf( "%s: start vocie_mode(%d) %s, current_mode=%d!\n",__func__,vmode,vocie_mode[vmode],current_mode);
118
119 if(vmode >= MAX_AVOICE_MODE||vmode < AVOICE_TEAK_2G_3G)
120 {
121 printf("alsa_voice_open: mode not support fail!\n");
122 return -2;
123
124 }
125 /* open mixer dev for codec control */
126 if(!(voice_mixer = mixer_open(0)))
127 printf("mixer open fail, file(%s), line(%d)\n", __FILE__, __LINE__);
128
129
130 if(T_OUTPUT_SPEAKER == current_chanl) {
131 mix_set_voice_path(voice_mixer,T_OUTPUT_SPEAKER);
132
133 printf("chanl SPEAKER: mix_set_voice_path ret=%d!\n",ret);
134 mix_set_voice_vol(voice_mixer,T_VOICE_VOL_5_LEVEL);
135
136 printf("chanl SPEAKER: mix_set_voice_vol ret=%d!\n",ret);
137 }
138 else if (T_OUTPUT_RECEIVER == current_chanl){
139 mix_set_voice_path(voice_mixer, T_OUTPUT_RECEIVER);
140
141 printf("chanl RECEIVER: mix_set_voice_path ret=%d!\n",ret);
142 mix_set_voice_vol(voice_mixer,T_VOICE_VOL_5_LEVEL);
143
144 printf("chanl RECEIVER: mix_set_voice_vol ret=%d!\n",ret);
145 }
146 else if (T_OUTPUT_HEADSET == current_chanl){
147
148 ret= mix_set_voice_path(voice_mixer, T_OUTPUT_HEADSET);
149
150 printf("chanl HEADSET: mix_set_voice_path ret=%d!\n",ret);
151 ret = mix_set_voice_vol(voice_mixer,T_VOICE_VOL_5_LEVEL);
152 printf("chanl HEADSET: mix_set_voice_vol ret=%d!\n",ret);
153
154 }
155 else
156 {
157 printf("alsa_voice_open: chanl not support fail!\n");
158 return -2;
159
160 }
161
162 /*close mixer */
163 mixer_close(voice_mixer);
164
165 /* open pcm dev for data tranf*/
166 config_voice.channels = 1; /* one channel */
167 config_voice.rate = 8000; /* 8K rate */
168 config_voice.period_count = 3; /* buffer num */
169 config_voice.period_size = 640; /* buffer size */
170 config_voice.format = PCM_FORMAT_S16_LE; /* 16-bit signed */
171 if(vmode == AVOICE_TEAK_2G_3G)
172 {
173 dev_num = AVOICE_TEAK_2G_3G_DEV_NUM;
174 config_voice.rate = 8000; /* 8K rate */
175 }
176 else if(vmode == AVOICE_SOFT_3G_NB)
177 {
178 dev_num = AVOICE_SOFT_3G_DEV_NUM;
179 config_voice.rate = 8000; /* 8K rate */
180 }
181 else if(vmode == AVOICE_SOFT_3G_WB)
182 {
183 dev_num = AVOICE_SOFT_3G_DEV_NUM;
184 config_voice.rate = 16000; /* 16K rate */
185 }
186 else if(vmode == AVOICE_4G_NB)
187 {
188 dev_num = AVOICE_4G_DEV_NUM;
189 config_voice.rate = 8000; /* 8K rate */
190 }
191 else if(vmode == AVOICE_4G_WB)
192 {
193 dev_num = AVOICE_4G_DEV_NUM;
194 config_voice.rate = 16000; /* 16K rate */
195 }
196 else if(vmode == AVOICE_5G_NB)
197 {
198 dev_num = AVOICE_5G_DEV_NUM;
199 config_voice.rate = 8000; /* 8K rate */
200 }
201 else if(vmode == AVOICE_5G_WB)
202 {
203 dev_num = AVOICE_5G_DEV_NUM;
204 config_voice.rate = 16000; /* 16K rate */
205 }
206 else
207 {
208 printf("alsa_voice_open: mode not support fail!\n");
209 return -2;
210
211 }
212
213
214 if(!(voice_handle.pcm_voice_out = pcm_open(0, dev_num, PCM_OUT, &config_voice)))
215 printf("pcm_out dev_num=%d open fail, file(%s), line(%d)\n",dev_num, __FILE__, __LINE__);
216
217 printf("%s:pcm_open pcm_voice_out dev_num=%d end!\n",__func__,dev_num);
218
219 if(!(voice_handle.pcm_voice_in = pcm_open(0,dev_num,PCM_IN, &config_voice)))
220 printf("pcm_in open dev_num=%d fail, file(%s), line(%d)\n",dev_num, __FILE__, __LINE__);
221
222 printf("%s:pcm_open pcm_voice_in dev_num=%d end!\n",__func__,dev_num);
223
224 if(0 != pcm_prepare(voice_handle.pcm_voice_out))
225 printf("pcm_out dev_num=%d prepare fail, file(%s), line(%d)\n",dev_num, __FILE__, __LINE__);
226
227 printf("%s: pcm_voice_out pcm_prepare dev_num=%d end!\n",__func__,dev_num);
228
229 if(0 != pcm_prepare(voice_handle.pcm_voice_in))
230 printf("pcm_in dev_num=%d prepare fail, file(%s), line(%d)\n",dev_num, __FILE__, __LINE__);
231
232
233 printf("%s: pcm_voice_in pcm_prepare vmode=%d dev_num=%d end!\n",__func__,vmode,dev_num);
234 current_mode = vmode;
235 printf("%s: end!\n",__func__);
236
237 return 0;
238}
239
240int alsa_voice_close(int vmode)
241{
242 int ret = 0;
243 printf("%s: start!\n",__func__);
244
245 if(vmode >= MAX_AVOICE_MODE||vmode < AVOICE_TEAK_2G_3G)
246 {
247 printf("alsa_voice_close: mode not support fail!\n");
248 return -2;
249
250 }
251
252if(voice_handle.pcm_voice_in) {
253 ret = pcm_close(voice_handle.pcm_voice_in);
254 voice_handle.pcm_voice_in = 0;
255
256 printf("pcm_close pcm_voice_in ret=%d!\n",ret);
257}
258
259if(voice_handle.pcm_voice_out) {
260 ret = pcm_close(voice_handle.pcm_voice_out);
261 voice_handle.pcm_voice_out = 0;
262
263 printf("pcm_close pcm_voice_out ret=%d!\n",ret);
264}
265
266
267
268
269
270 current_mode = MAX_AVOICE_MODE;
271 printf("%s: end!\n",__func__);
272
273 return ret;
274}
275
276
277
278#endif