blob: 69f0361684d5bff42aa430da45bc4f2303141c0a [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{
409// return 0;
410 return mbtk_audio_mp3_to_wav(wavpath, mp3path);
411}
412
413int Ql_Mp3_To_Play(char *mp3path, int hdl,int sample_rate)
414{
415 // return 0;
416 return mbtk_audio_mp3_to_play(mp3path, hdl, sample_rate);
417}
418
419//add by grady, 2018-6-2
420/*
421 * describe : this function is use to open mixer device
422 * paras :
423 * device: mixer device
424 * return
425 * mixer handle
426 */
427struct mixer *quec_mixer_open(const char *device)
428{
429
430 return NULL;
431}
432
433/*
434 * describe : this function is use to close mixer device
435 * paras :
436 * mixer: mixer handle
437 * return
438 * none
439 */
440void quec_mixer_close(struct mixer *mixer)
441{
442
443
444}
445
446/*
447 * describe : this function is use to get mixer devie control
448 * paras :
449 * mixer: mixer handle
450 * name: mixer device
451 * index: mixer index
452 * return
453 * mixer control
454 */
455struct mixer_ctl *quec_mixer_get_control(struct mixer *mixer, const char *name, unsigned index)
456{
457
458 return NULL;
459}
460
461/*
462 * describe : this function is use to set mulvalues
463 * paras :
464 * mixer: mixer handle
465 * count: count
466 * argv: data
467 * return :
468 *
469 */
470int quec_mixer_ctl_mulvalues(struct mixer_ctl *ctl, int count, char ** argv)
471{
472
473 return 0;
474}
475
476
477//end grady
478
479/*****************************************************************
480* Function: Ql_AudPlayer_OpenExt
481*
482* Description:
483* expend function from Ql_AudPlayer_OpenExt
484* Open audio play device, and specify the callback function.
485* This function can be called twice to play different audio sources.
486*
487* Parameters:
488* device : a string that specifies the PCM device.
489* NULL, means the audio will be played on the default PCM device.
490*
491* If you want to mixedly play audio sources, you can call this
492* API twice with specifying different PCM device.
493* The string devices available:
494* "hw:0,0" (the default play device)
495* "hw:0,13" (this device can mix audio and TTS)
496* "hw:0,14"
497*
498* cb_func : callback function for audio player.
499* The results of all operations on audio player
500* are informed in callback function.
501*
502* flags : pcm flags, eg: PCM_MMAP, PCM_NMMAP.
503*
504* channels: pcm sample channels.
505*
506* rate : pcm sample rate.
507*
508* format : pcm sample fromat
509*
510* Return:
511* pcm device handle
512* NULL, fail
513*****************************************************************/
514int Ql_AudPlayer_OpenExt(
515 char *dev,
516 _cb_onPlayer cb_fun,
517 int flags,
518 int channels,
519 int rate,
520 int format)
521{
522 return 0;
523}
524
525/*****************************************************************
526* Function: Ql_AudRecorder_Open
527*
528* Description:
529* Open audio record device, and specify the callback function.
530*
531* Parameters:
532* device : not used. MUST be NULL.
533*
534* cb_func : callback function for audio player.
535* The results of all operations on audio recorder
536* are informed in callback function.
537*
538* flags : pcm flags, eg: PCM_MMAP, PCM_NMMAP.
539*
540* channels: pcm sample channels.
541*
542* rate : pcm sample rate.
543*
544* format : pcm sample fromat
545*
546* Return:
547* pcm device handle
548* NULL, fail
549*****************************************************************/
550int Ql_AudRecorder_OpenExt(
551 char *dev,
552 _cb_onRecorder cb_fun,
553 int flags,
554 int channels,
555 int rate,
556 int format)
557{
558
559
560 return 0;
561}
562
563/*
564* Function: uac enable
565*
566* Description:
567* uac enable
568*
569* Parameters:
570* none
571* Return:
572* TURE or FALSE
573*/
574int ql_uac_enable(void)
575{
576
577 return 0;
578}
579
580/*
581* Function: uac disable
582*
583* Description:
584* uac disable
585*
586* Parameters:
587* none
588* Return:
589* TURE or FALSE
590*/
591int ql_uac_disable(void)
592{
593
594 return 0;
595}