blob: 37a4820bbde8d658ce14a5da7ece7bddeccbf077 [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 */
xf.liaa4d92f2023-09-13 00:18:58 -0700126 if(!(voice_mixer = mixer_open(0))) {
xf.libdd93d52023-05-12 07:10:14 -0700127 printf("mixer open fail, file(%s), line(%d)\n", __FILE__, __LINE__);
xf.liaa4d92f2023-09-13 00:18:58 -0700128 return -2;
129 }
xf.libdd93d52023-05-12 07:10:14 -0700130
131
132 if(T_OUTPUT_SPEAKER == current_chanl) {
133 mix_set_voice_path(voice_mixer,T_OUTPUT_SPEAKER);
134
135 printf("chanl SPEAKER: mix_set_voice_path ret=%d!\n",ret);
136 mix_set_voice_vol(voice_mixer,T_VOICE_VOL_5_LEVEL);
137
138 printf("chanl SPEAKER: mix_set_voice_vol ret=%d!\n",ret);
139 }
140 else if (T_OUTPUT_RECEIVER == current_chanl){
141 mix_set_voice_path(voice_mixer, T_OUTPUT_RECEIVER);
142
143 printf("chanl RECEIVER: mix_set_voice_path ret=%d!\n",ret);
144 mix_set_voice_vol(voice_mixer,T_VOICE_VOL_5_LEVEL);
145
146 printf("chanl RECEIVER: mix_set_voice_vol ret=%d!\n",ret);
147 }
148 else if (T_OUTPUT_HEADSET == current_chanl){
149
150 ret= mix_set_voice_path(voice_mixer, T_OUTPUT_HEADSET);
151
152 printf("chanl HEADSET: mix_set_voice_path ret=%d!\n",ret);
153 ret = mix_set_voice_vol(voice_mixer,T_VOICE_VOL_5_LEVEL);
154 printf("chanl HEADSET: mix_set_voice_vol ret=%d!\n",ret);
155
156 }
157 else
158 {
159 printf("alsa_voice_open: chanl not support fail!\n");
xf.liaa4d92f2023-09-13 00:18:58 -0700160 mixer_close(voice_mixer);
xf.libdd93d52023-05-12 07:10:14 -0700161 return -2;
162
163 }
164
165 /*close mixer */
166 mixer_close(voice_mixer);
167
168 /* open pcm dev for data tranf*/
169 config_voice.channels = 1; /* one channel */
170 config_voice.rate = 8000; /* 8K rate */
171 config_voice.period_count = 3; /* buffer num */
172 config_voice.period_size = 640; /* buffer size */
173 config_voice.format = PCM_FORMAT_S16_LE; /* 16-bit signed */
174 if(vmode == AVOICE_TEAK_2G_3G)
175 {
176 dev_num = AVOICE_TEAK_2G_3G_DEV_NUM;
177 config_voice.rate = 8000; /* 8K rate */
178 }
179 else if(vmode == AVOICE_SOFT_3G_NB)
180 {
181 dev_num = AVOICE_SOFT_3G_DEV_NUM;
182 config_voice.rate = 8000; /* 8K rate */
183 }
184 else if(vmode == AVOICE_SOFT_3G_WB)
185 {
186 dev_num = AVOICE_SOFT_3G_DEV_NUM;
187 config_voice.rate = 16000; /* 16K rate */
188 }
189 else if(vmode == AVOICE_4G_NB)
190 {
191 dev_num = AVOICE_4G_DEV_NUM;
192 config_voice.rate = 8000; /* 8K rate */
193 }
194 else if(vmode == AVOICE_4G_WB)
195 {
196 dev_num = AVOICE_4G_DEV_NUM;
197 config_voice.rate = 16000; /* 16K rate */
198 }
199 else if(vmode == AVOICE_5G_NB)
200 {
201 dev_num = AVOICE_5G_DEV_NUM;
202 config_voice.rate = 8000; /* 8K rate */
203 }
204 else if(vmode == AVOICE_5G_WB)
205 {
206 dev_num = AVOICE_5G_DEV_NUM;
207 config_voice.rate = 16000; /* 16K rate */
208 }
209 else
210 {
211 printf("alsa_voice_open: mode not support fail!\n");
212 return -2;
213
214 }
215
216
217 if(!(voice_handle.pcm_voice_out = pcm_open(0, dev_num, PCM_OUT, &config_voice)))
218 printf("pcm_out dev_num=%d open fail, file(%s), line(%d)\n",dev_num, __FILE__, __LINE__);
219
220 printf("%s:pcm_open pcm_voice_out dev_num=%d end!\n",__func__,dev_num);
221
222 if(!(voice_handle.pcm_voice_in = pcm_open(0,dev_num,PCM_IN, &config_voice)))
223 printf("pcm_in open dev_num=%d fail, file(%s), line(%d)\n",dev_num, __FILE__, __LINE__);
224
225 printf("%s:pcm_open pcm_voice_in dev_num=%d end!\n",__func__,dev_num);
226
227 if(0 != pcm_prepare(voice_handle.pcm_voice_out))
228 printf("pcm_out dev_num=%d prepare fail, file(%s), line(%d)\n",dev_num, __FILE__, __LINE__);
229
230 printf("%s: pcm_voice_out pcm_prepare dev_num=%d end!\n",__func__,dev_num);
231
232 if(0 != pcm_prepare(voice_handle.pcm_voice_in))
233 printf("pcm_in dev_num=%d prepare fail, file(%s), line(%d)\n",dev_num, __FILE__, __LINE__);
234
235
236 printf("%s: pcm_voice_in pcm_prepare vmode=%d dev_num=%d end!\n",__func__,vmode,dev_num);
237 current_mode = vmode;
238 printf("%s: end!\n",__func__);
239
240 return 0;
241}
242
243int alsa_voice_close(int vmode)
244{
245 int ret = 0;
246 printf("%s: start!\n",__func__);
247
248 if(vmode >= MAX_AVOICE_MODE||vmode < AVOICE_TEAK_2G_3G)
249 {
250 printf("alsa_voice_close: mode not support fail!\n");
251 return -2;
252
253 }
254
255if(voice_handle.pcm_voice_in) {
256 ret = pcm_close(voice_handle.pcm_voice_in);
257 voice_handle.pcm_voice_in = 0;
258
259 printf("pcm_close pcm_voice_in ret=%d!\n",ret);
260}
261
262if(voice_handle.pcm_voice_out) {
263 ret = pcm_close(voice_handle.pcm_voice_out);
264 voice_handle.pcm_voice_out = 0;
265
266 printf("pcm_close pcm_voice_out ret=%d!\n",ret);
267}
268
269
270
271
272
273 current_mode = MAX_AVOICE_MODE;
274 printf("%s: end!\n",__func__);
275
276 return ret;
277}
278
279
280
281#endif