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