blob: b94db61a8d93e4f8c5a2309475e3d54824e02c54 [file] [log] [blame]
liubin281ac462023-07-19 14:22:54 +08001#include "ql/ql_audio.h"
2#include "mbtk_log.h"
3#include "mbtk_audio.h"
4
5static mbtk_audio_handle record_hdl = NULL;
zhangzh8711cea2023-10-20 10:47:43 +08006static mbtk_audio_handle player_hdl = NULL;
liubin281ac462023-07-19 14:22:54 +08007static _cb_onRecorder record_cb_fun = NULL;
8static int Samprate = 8000;
9
10/*****************************************************************
11* Function: Ql_AudPlayer_Open
12*
13* Description:
14* Open audio play device, and specify the callback function.
15* This function can be called twice to play different audio sources.
16*
17* Parameters:
18* device : a string that specifies the PCM device.
19* NULL, means the audio will be played on the default PCM device.
20*
21* If you want to mixedly play audio sources, you can call this
22* API twice with specifying different PCM device.
23* The string devices available:
24* "hw:0,0" (the default play device)
25* "hw:0,13" (this device can mix audio and TTS)
26* "hw:0,14"
27*
28* cb_func : callback function for audio player.
29* The results of all operations on audio player
30* are informed in callback function.
31*
32* Return:
33* pcm device handle on success
34* -1 for failure
35*****************************************************************/
36int Ql_AudPlayer_Open(char* device, _cb_onPlayer cb_func)
37{
zhangzh8711cea2023-10-20 10:47:43 +080038 player_hdl = mbtk_audio_open(MBTK_AUTIO_TYPE_OUT, 1, Samprate, cb_func);
39 return (int)player_hdl;
liubin281ac462023-07-19 14:22:54 +080040}
41
42/*========================================================================
43 FUNCTION: Ql_AudPlayer_Play
44=========================================================================*/
45/** @brief
46 This function writes pcm data to pcm device to play.
47
48 @param[in] hdl, the handle returned by Ql_AudPlayer_Open().
49 @param[in] pData, pointer to the start address of pcm data.
50 @param[in] length, the length of pcm data.
51
52 @return
53 on success, the return value is the number of bytes to play
54 on failure, the return value is -1;
55
56 @dependencies
57 Ql_AudPlayer_Open() must be first called successfully.
58*/
59/*=======================================================================*/
60int Ql_AudPlayer_Play(int hdl, unsigned char* pData, unsigned int length)
61{
62 return mbtk_audio_play_stream((void *)hdl, pData, length);
63}
64
65/*========================================================================
66 FUNCTION: Ql_AudPlayer_PlayFrmFile
67=========================================================================*/
68/** @brief
69 This function plays the pcm data from the specified file.
70
71 @param[in] hdl, the handle returned by Ql_AudPlayer_Open().
72 @param[in] fd, a file descriptor that contains pcm data.
73 Note:
74 the file offset should be set to the start position of pcm
75 data region, which means you should move the file offset
76 skipping the file header (such as wave header, amr header).
77 @param[in] offset, file offset. Please set it to -1 if no need to use.
78
79 @return
80 0 on success
81 -1 on failure
82
83 @dependencies
84 Ql_AudPlayer_Open() must be first called successfully.
85*/
86/*=======================================================================*/
zhangzh8711cea2023-10-20 10:47:43 +080087
liubin281ac462023-07-19 14:22:54 +080088int Ql_AudPlayer_PlayFrmFile(int hdl, int fd, int offset)
89{
zhangzhd04babd2023-10-24 16:55:57 +080090 return mbtk_audio_play_file((void *)hdl, fd, offset);
liubin281ac462023-07-19 14:22:54 +080091}
92
93//
94// Function: Ql_AudPlayer_Pause
95//
96// Description:
97// Pause playing.
98// @param hdl:
99// Handle received from Ql_AudPlayer_Open().
100int Ql_AudPlayer_Pause(int hdl)
101{
102 return mbtk_audio_pause((void *)hdl);
103}
104
105//
106// Function: Ql_AudPlayer_Resume
107//
108// Description:
109// Resume playing.
110// @param hdl:
111// Handle received from Ql_AudPlayer_Open().
112int Ql_AudPlayer_Resume(int hdl)
113{
114 return mbtk_audio_resume((void *)hdl);
115}
116
117//
118// Function: Ql_AudPlayer_Stop
119//
120// Description:
121// Stop playing audio
122// hdl:
123// Handle received from Ql_AudPlayer_Open().
124void Ql_AudPlayer_Stop(int hdl)
125{
126 return mbtk_audio_stop((void *)hdl);
127}
128
129//
130// Function: Ql_AudPlayer_Close
131//
132// Description:
133// Close player, and free the resource.
134// @param hdl:
135// Handle received from Ql_AudPlayer_Open().
136void Ql_AudPlayer_Close(int hdl)
137{
138 mbtk_audio_close((void *)hdl);
139}
140
141
142int Ql_AudPlayer_set_LessDataThreshold(int hdl, unsigned short threshSize)
143{
144
145 return 0;
146}
147
148int Ql_AudPlayer_get_freeSpace(int hdl)
149{
150
151 return 0;
152}
153
154
155/*****************************************************************
156* Function: Ql_AudRecorder_Open
157*
158* Description:
159* Open audio record device, and specify the callback function.
160*
161* Parameters:
162* device : not used. MUST be NULL.
163*
164* cb_func : callback function for audio player.
165* The results of all operations on audio recorder
166* are informed in callback function.
167*
168* Return:
169* pcm device handle
170* -1 for failure
171*****************************************************************/
172int Ql_AudRecorder_Open(char* device, _cb_onRecorder cb_fun)
173{
174 record_hdl = mbtk_audio_open(MBTK_AUTIO_TYPE_IN, 1, 8000, NULL);
175 record_cb_fun = cb_fun;
176 return (int)record_hdl;
177}
178
179//
180// Function: Ql_AudRecorder_StartRecord
181//
182// Description:
183// Start to record.
184// The record data is output in _cb_onRecorder.
185//
186// Return:
187// 0 on success
188// -1 on failure
189int Ql_AudRecorder_StartRecord(void)
190{
191 return mbtk_audio_record(record_hdl, record_cb_fun, NULL);
192}
193
194//
195// Function: Ql_AudRecorder_Pause
196//
197// Description:
198// Pause recording
199int Ql_AudRecorder_Pause(void)
200{
201 return 0;
202}
203
204//
205// Function: Ql_AudRecorder_Resume
206//
207// Description:
208// Resume recording
209int Ql_AudRecorder_Resume(void)
210{
211 return 0;
212}
213
214//
215// Function: Ql_AudRecorder_Stop
216//
217// Description:
218// Stop recording
219void Ql_AudRecorder_Stop(void)
220{
221
222}
223
224//
225// Function: Ql_AudRecorder_Close
226//
227// Description:
228// Close recorder, and free the resource
229void Ql_AudRecorder_Close(void)
230{
231 mbtk_audio_close(record_hdl);
232 record_hdl = NULL;
233 record_cb_fun = NULL;
234}
235
236//
237// Function: Ql_clt_set_mixer_value
238//
239// Description:
240// Close recorder, and free the resource
241boolean Ql_clt_set_mixer_value(const char *device, int count, const char *value)
242{
243
244 return FALSE;
245}
246
247
248int Ql_AudTone_Open(char* device, _cb_onPlayer cb)//cb not support now
249{
250 return 0;
251}
252
253int Ql_AudTone_Start(int hdl, struct Ql_TonePara *para)
254{
255 return 0;
256}
257
258void Ql_AudTone_Stop(int hdl)
259{
260
261}
262
263void Ql_AudTone_Close(int hdl)
264{
265
266}
267
268
269//****************QL Codec API************************//
270
271//
272// Function: Ql_AudCodec_Set_ALC5616_DRCAGC
273//
274// Description:
275// Set ALC5616 DRC/AGC configuration
276int Ql_AudCodec_Set_ALC5616_DRCAGC(const char *i2c, struct Ql_ALC5616_DRCAGC *cfg)
277{
278 return 0;
279}
280
281//
282// Function: Ql_Update_wav_size
283//
284// Description:
285// update wav format file size in the header
286// @param fd:
287// wav file discriptor
288// @param size:
289// wav file size to update
290int Ql_Update_wav_size(int fd, int size)
291{
292 return 0;
293}
294
295//add by grady, 2018-5-29
296/*
297 * describe : this function is use to open pcm device
298 * paras :
299 * device : this should be fix to hw:0,0
300 * flags ; pcm play flags
301 * rate: sample rate
302 * channels : audio channal 1 or 2
303 * format: format to play or record, 16bit line,MP3
304 * hostless: if there is no file it is true
305 * return :
306 * pcm : pcm handle, use can use this handle to read write data
307 */
308struct pcm *quec_pcm_open(char *device, unsigned flags, unsigned rate, unsigned channels, unsigned format, unsigned hostless)
309{
310 return NULL;
311}
312
313/*
314 * describe : this function is use to close pcm handle
315 * paras :
316 * pcm : pcm handle to close
317 * return :
318 */
319int quec_pcm_close(struct pcm *pcm )
320{
321 return 0;
322}
323
324/*
325 * describe : this function is use to read pcm buffer
326 * paras :
327 * pcm : pcm handle to write date
328 * buffer: data buffer
329 * lenth: data length
330 * return :
331 */
332int quec_read_pcm(struct pcm *pcm, void * buffer, int length)
333{
334
335 return 0;
336}
337
338/*
339 * describe : this function is use to get pcm buffer lenth
340 * paras :
341 * lenth: data length
342 * return
343 * buffer length
344 */
345int quec_get_pem_buffer_len(struct pcm *pcm)
346{
347
348 return 0;
349}
350
351void dtmf_cb1(char dtmf)
352{
353 printf("%s:%c\n", __FUNCTION__, dtmf);
354}
355
356/**
357 * @brief Set RX DSP Gain
358 * @details
359 * Gain support [-36,12] dB
360 *
361 * @param gain
362 * DSP gain
363 */
364
365int Ql_Rxgain_Set(int value)
366{
367
368 printf("Volume is %d \n",value);
369 int volume =0;
370 int handler = 0;
371
372 if(value < -36 || value > 12)
373 {
374 volume = 0;
375 }
376 else
377 {
378 volume = value;
379 }
380
381 mbtk_audio_ubus_client_init(&handler, dtmf_cb1);
382 mbtk_audio_dsp_set(1, volume);
383
384 return 0;
385}
386
387
388/** Ql_Playback_Samprate_Set
389 * @brief Set Playback PCM Samprate
390 * @details
391 * 0 for NB 1 for WB
392 *
393 * @param samprate
394 * samprate for PCM playback,default value is PCM NB
395 */
396int Ql_Playback_Samprate_Set(int samprate)
397{
398 printf("samprate is %d \n",samprate);
399 if(samprate == 1)
400 {
401 Samprate = 16000;
402 }
403 else{
404 Samprate = 8000;
405 }
406
407 return 0;
408}
409
410int Ql_Mp3_To_Wav(const char *wavpath, char *mp3path)
411{
b.liuc1064f82023-10-11 16:47:39 +0800412#ifdef MBTK_MP3_SUPPORT
liubin281ac462023-07-19 14:22:54 +0800413 return mbtk_audio_mp3_to_wav(wavpath, mp3path);
b.liuc1064f82023-10-11 16:47:39 +0800414#else
415 return 0;
416#endif
liubin281ac462023-07-19 14:22:54 +0800417}
418
419int Ql_Mp3_To_Play(char *mp3path, int hdl,int sample_rate)
420{
b.liuc1064f82023-10-11 16:47:39 +0800421#ifdef MBTK_MP3_SUPPORT
liubin281ac462023-07-19 14:22:54 +0800422 return mbtk_audio_mp3_to_play(mp3path, hdl, sample_rate);
b.liuc1064f82023-10-11 16:47:39 +0800423#else
424 return 0;
425#endif
liubin281ac462023-07-19 14:22:54 +0800426}
427
428//add by grady, 2018-6-2
429/*
430 * describe : this function is use to open mixer device
431 * paras :
432 * device: mixer device
433 * return
434 * mixer handle
435 */
436struct mixer *quec_mixer_open(const char *device)
437{
438
439 return NULL;
440}
441
442/*
443 * describe : this function is use to close mixer device
444 * paras :
445 * mixer: mixer handle
446 * return
447 * none
448 */
449void quec_mixer_close(struct mixer *mixer)
450{
451
452
453}
454
455/*
456 * describe : this function is use to get mixer devie control
457 * paras :
458 * mixer: mixer handle
459 * name: mixer device
460 * index: mixer index
461 * return
462 * mixer control
463 */
464struct mixer_ctl *quec_mixer_get_control(struct mixer *mixer, const char *name, unsigned index)
465{
466
467 return NULL;
468}
469
470/*
471 * describe : this function is use to set mulvalues
472 * paras :
473 * mixer: mixer handle
474 * count: count
475 * argv: data
476 * return :
477 *
478 */
479int quec_mixer_ctl_mulvalues(struct mixer_ctl *ctl, int count, char ** argv)
480{
481
482 return 0;
483}
484
485
486//end grady
487
488/*****************************************************************
489* Function: Ql_AudPlayer_OpenExt
490*
491* Description:
492* expend function from Ql_AudPlayer_OpenExt
493* Open audio play device, and specify the callback function.
494* This function can be called twice to play different audio sources.
495*
496* Parameters:
497* device : a string that specifies the PCM device.
498* NULL, means the audio will be played on the default PCM device.
499*
500* If you want to mixedly play audio sources, you can call this
501* API twice with specifying different PCM device.
502* The string devices available:
503* "hw:0,0" (the default play device)
504* "hw:0,13" (this device can mix audio and TTS)
505* "hw:0,14"
506*
507* cb_func : callback function for audio player.
508* The results of all operations on audio player
509* are informed in callback function.
510*
511* flags : pcm flags, eg: PCM_MMAP, PCM_NMMAP.
512*
513* channels: pcm sample channels.
514*
515* rate : pcm sample rate.
516*
517* format : pcm sample fromat
518*
519* Return:
520* pcm device handle
521* NULL, fail
522*****************************************************************/
523int Ql_AudPlayer_OpenExt(
524 char *dev,
525 _cb_onPlayer cb_fun,
526 int flags,
527 int channels,
528 int rate,
529 int format)
530{
531 return 0;
532}
533
534/*****************************************************************
535* Function: Ql_AudRecorder_Open
536*
537* Description:
538* Open audio record device, and specify the callback function.
539*
540* Parameters:
541* device : not used. MUST be NULL.
542*
543* cb_func : callback function for audio player.
544* The results of all operations on audio recorder
545* are informed in callback function.
546*
547* flags : pcm flags, eg: PCM_MMAP, PCM_NMMAP.
548*
549* channels: pcm sample channels.
550*
551* rate : pcm sample rate.
552*
553* format : pcm sample fromat
554*
555* Return:
556* pcm device handle
557* NULL, fail
558*****************************************************************/
559int Ql_AudRecorder_OpenExt(
560 char *dev,
561 _cb_onRecorder cb_fun,
562 int flags,
563 int channels,
564 int rate,
565 int format)
566{
567
568
569 return 0;
570}
571
572/*
573* Function: uac enable
574*
575* Description:
576* uac enable
577*
578* Parameters:
579* none
580* Return:
581* TURE or FALSE
582*/
583int ql_uac_enable(void)
584{
585
586 return 0;
587}
588
589/*
590* Function: uac disable
591*
592* Description:
593* uac disable
594*
595* Parameters:
596* none
597* Return:
598* TURE or FALSE
599*/
600int ql_uac_disable(void)
601{
602
603 return 0;
zhangzh8711cea2023-10-20 10:47:43 +0800604}