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