blob: 68c219068f1474b410933a63622b173be765db59 [file] [log] [blame]
liubin281ac462023-07-19 14:22:54 +08001/**
2 @file
3 ql_audio.h
4
5 @brief
6 This file provides the definitions for audio & record, and declares the
7 API functions.
8
9*/
10/*============================================================================
11 Copyright (c) 2017 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
12 Quectel Wireless Solution Proprietary and Confidential.
13 =============================================================================*/
14/*===========================================================================
15
16 EDIT HISTORY FOR MODULE
17
18This section contains comments describing changes made to the module.
19Notice that changes are listed in reverse chronological order.
20
21
22WHEN WHO WHAT, WHERE, WHY
23---------- ------------ ----------------------------------------------------
2407/06/2018 Stanley.yong Revise the comments for API.
2519/04/2018 Zichar.zhang Add Ql_Update_wav_size function.
26 Add Ql_AudPlayer_OpenExt function.
27 Add Ql_AudRecorder_OpenExt function.
2819/12/2016 Stanley.yong Optimize the APIs, and add comments.
2913/12/2016 Running.qian Implement newly-designed APIs.
3018/07/2016 Jun.wu Create
31=============================================================================*/
32
33#ifndef __AUD_H__
34#define __AUD_H__
35
36//this two headers for alsa params setting
37// #include "asoundlib.h"
38//#include "alsa-intf/alsa_audio.h"
39
40#include "mbtk_type.h"
41
42#define QUEC_PCM_8K 8000
43#define QUEC_PCM_16K 16000
44#define QUEC_PCM_44k 44100
45#define QUEC_PCM_MONO 1
46#define QUEC_PCM_STEREO 2
47
48typedef enum {
49 AUD_UP_LINK = 0,
50 AUD_DOWN_LINK,
51} Enum_AudDlink;
52
53typedef enum {
54 AUD_PLAYER_ERROR = -1,
55 AUD_PLAYER_START = 0,
56 AUD_PLAYER_PAUSE,
57 AUD_PLAYER_RESUME,
58 AUD_PLAYER_NODATA, //Buff no data and play tread will sleep
59 AUD_PLAYER_LESSDATA, //Buff has less data
60 AUD_PLAYER_FINISHED,
61} Enum_AudPlayer_State;
62
63typedef enum {
64 AUD_RECORDER_ERROR = -1,
65 AUD_RECORDER_START = 0,
66 AUD_RECORDER_PAUSE,
67 AUD_RECORDER_RESUME,
68 AUD_RECORDER_FINISHED,
69} Enum_AudRecorder_State;
70
71
72/****************************************************************************
73* Audio Volume Level Definition
74***************************************************************************/
75typedef enum {
76 AUD_VOLUME_LEVEL1 = 0,
77 AUD_VOLUME_LEVEL2,
78 AUD_VOLUME_LEVEL3,
79 AUD_VOLUME_LEVEL4,
80 AUD_VOLUME_LEVEL5,
81 AUD_VOLUME_LEVEL_END
82}Enum_AudVolumeLevel;
83
84/****************************************************************************
85* Audio Format
86***************************************************************************/
87typedef enum {
88 AUD_STREAM_FORMAT_MP3 = 0,
89 AUD_STREAM_FORMAT_AMR = 1,
90 AUD_STREAM_FORMAT_PCM = 2,
91 AUD_STREAM_FORMAT_END
92} Enum_AudStreamFormat;
93
94/****************************************************************************
95* Audio Direct
96***************************************************************************/
97typedef enum {
98 AUD_LINK_REVERSE = 0,
99 AUD_LINK_FORWARD = 1,
100 AUD_LINK_BOTH = 2,
101 AUD_LINK_INVALID
102}Enum_AudStreamDirection;
103
104
105/*****************************************************************
106********************New Advanced Audio High API******************
107* ***************************************************************/
108struct wav_header {
109 uint32_t riff_id;
110 uint32_t riff_sz;
111 uint32_t riff_fmt;
112 uint32_t fmt_id;
113 uint32_t fmt_sz;
114 uint16_t audio_format;
115 uint16_t num_channels;
116 uint32_t sample_rate;
117 uint32_t byte_rate; /* sample_rate * num_channels * bps / 8 */
118 uint16_t block_align; /* num_channels * bps / 8 */
119 uint16_t bits_per_sample;
120 uint32_t data_id;
121 uint32_t data_sz;
122};
123
124#define ID_RIFF 0x46464952
125#define ID_WAVE 0x45564157
126#define ID_FMT 0x20746d66
127#define ID_DATA 0x61746164
128#define FORMAT_PCM 1
129
130struct ST_MediaParams {
131 Enum_AudStreamFormat format;
132 Enum_AudVolumeLevel volume;
133 Enum_AudStreamDirection direct;
134};
135
136
137//
138// Function: _cb_onPlayer
139//
140// Description:
141// This callback function handles the result of audio player.
142//
143// @param hdl:
144// Handle received from Ql_AudPlayer_Open().
145// @param result:
146// the executing result for previous operation, such as Open, Play, Pause, Resume, Stop.
147// see the definition of Enum_AudPlayer_State for the specific meaning.
148typedef int(*_cb_onPlayer)(int hdl, int result);
149//
150// Function: _cb_onRecorder
151//
152// Description:
153// This callback function handles the result of audio recorder.
154// If result < 0, the recorder will stop the recording automatically.
155//
156// @param result:
157// the executing result for previous operation, such as Open, StartRecord, Pause, Resume, Stop.
158// see the definition of Enum_AudRecorder_State for the specific meaning.
159// @param pBuf:
160// pointer to the output recording (PCM) data.
161// @param length:
162// the length of the output recording (PCM) data.
163typedef int(*_cb_onRecorder)(int result, unsigned char* pBuf, unsigned int length); //if result < 0 will stop record, else continue record
164
165/*****************************************************************
166* Function: Ql_AudPlayer_Open
167*
168* Description:
169* Open audio play device, and specify the callback function.
170* This function can be called twice to play different audio sources.
171*
172* Parameters:
173* device : a string that specifies the PCM device.
174* NULL, means the audio will be played on the default PCM device.
175*
176* If you want to mixedly play audio sources, you can call this
177* API twice with specifying different PCM device.
178* The string devices available:
179* "hw:0,0" (the default play device)
180* "hw:0,13" (this device can mix audio and TTS)
181* "hw:0,14"
182*
183* cb_func : callback function for audio player.
184* The results of all operations on audio player
185* are informed in callback function.
186*
187* Return:
188* pcm device handle on success
189* -1 for failure
190*****************************************************************/
191int Ql_AudPlayer_Open(char* device, _cb_onPlayer cb_func);
192
193/*========================================================================
194 FUNCTION: Ql_AudPlayer_Play
195=========================================================================*/
196/** @brief
197 This function writes pcm data to pcm device to play.
198
199 @param[in] hdl, the handle returned by Ql_AudPlayer_Open().
200 @param[in] pData, pointer to the start address of pcm data.
201 @param[in] length, the length of pcm data.
202
203 @return
204 on success, the return value is the number of bytes to play
205 on failure, the return value is -1;
206
207 @dependencies
208 Ql_AudPlayer_Open() must be first called successfully.
209*/
210/*=======================================================================*/
211int Ql_AudPlayer_Play(int hdl, unsigned char* pData, unsigned int length);
212
213/*========================================================================
214 FUNCTION: Ql_AudPlayer_PlayFrmFile
215=========================================================================*/
216/** @brief
217 This function plays the pcm data from the specified file.
218
219 @param[in] hdl, the handle returned by Ql_AudPlayer_Open().
220 @param[in] fd, a file descriptor that contains pcm data.
221 Note:
222 the file offset should be set to the start position of pcm
223 data region, which means you should move the file offset
224 skipping the file header (such as wave header, amr header).
225 @param[in] offset, file offset. Please set it to -1 if no need to use.
226
227 @return
228 0 on success
229 -1 on failure
230
231 @dependencies
232 Ql_AudPlayer_Open() must be first called successfully.
233*/
234/*=======================================================================*/
235int Ql_AudPlayer_PlayFrmFile(int hdl, int fd, int offset);
236//
237// Function: Ql_AudPlayer_Pause
238//
239// Description:
240// Pause playing.
241// @param hdl:
242// Handle received from Ql_AudPlayer_Open().
243int Ql_AudPlayer_Pause(int hdl);
244//
245// Function: Ql_AudPlayer_Resume
246//
247// Description:
248// Resume playing.
249// @param hdl:
250// Handle received from Ql_AudPlayer_Open().
251int Ql_AudPlayer_Resume(int hdl);
252//
253// Function: Ql_AudPlayer_Stop
254//
255// Description:
256// Stop playing audio
257// hdl:
258// Handle received from Ql_AudPlayer_Open().
259void Ql_AudPlayer_Stop(int hdl);
260//
261// Function: Ql_AudPlayer_Close
262//
263// Description:
264// Close player, and free the resource.
265// @param hdl:
266// Handle received from Ql_AudPlayer_Open().
267void Ql_AudPlayer_Close(int hdl);
268
269
270int Ql_AudPlayer_set_LessDataThreshold(int hdl, unsigned short threshSize);
271
272int Ql_AudPlayer_get_freeSpace(int hdl);
273
274
275/*****************************************************************
276* Function: Ql_AudRecorder_Open
277*
278* Description:
279* Open audio record device, and specify the callback function.
280*
281* Parameters:
282* device : not used. MUST be NULL.
283*
284* cb_func : callback function for audio player.
285* The results of all operations on audio recorder
286* are informed in callback function.
287*
288* Return:
289* pcm device handle
290* -1 for failure
291*****************************************************************/
292int Ql_AudRecorder_Open(char* device, _cb_onRecorder cb_fun);
293//
294// Function: Ql_AudRecorder_StartRecord
295//
296// Description:
297// Start to record.
298// The record data is output in _cb_onRecorder.
299//
300// Return:
301// 0 on success
302// -1 on failure
303int Ql_AudRecorder_StartRecord(void);
304//
305// Function: Ql_AudRecorder_Pause
306//
307// Description:
308// Pause recording
309int Ql_AudRecorder_Pause(void);
310//
311// Function: Ql_AudRecorder_Resume
312//
313// Description:
314// Resume recording
315int Ql_AudRecorder_Resume(void);
316//
317// Function: Ql_AudRecorder_Stop
318//
319// Description:
320// Stop recording
321void Ql_AudRecorder_Stop(void);
322//
323// Function: Ql_AudRecorder_Close
324//
325// Description:
326// Close recorder, and free the resource
327void Ql_AudRecorder_Close(void);
328
329//
330// Function: Ql_clt_set_mixer_value
331//
332// Description:
333// Close recorder, and free the resource
334boolean Ql_clt_set_mixer_value(const char *device, int count, const char *value);
335
336
337//****************QL TONE API************************//
338struct Ql_TonePara {
339 unsigned int lowFreq; //100-4000HZ
340 unsigned int highFreq; //100-4000HZ
341 unsigned int volume; //0 -1000
342 unsigned int duration; // >0 ms
343};
344
345int Ql_AudTone_Open(char* device, _cb_onPlayer cb);//cb not support now
346int Ql_AudTone_Start(int hdl, struct Ql_TonePara *para);
347void Ql_AudTone_Stop(int hdl);
348void Ql_AudTone_Close(int hdl);
349
350
351//****************QL Codec API************************//
352struct Ql_ALC5616_DRCAGC {
353 unsigned short control1_mask;
354 unsigned short control1_value;
355 unsigned short control2_mask;
356 unsigned short control2_value;
357 unsigned short control3_mask;
358 unsigned short control3_value;
359};
360
361//
362// Function: Ql_AudCodec_Set_ALC5616_DRCAGC
363//
364// Description:
365// Set ALC5616 DRC/AGC configuration
366int Ql_AudCodec_Set_ALC5616_DRCAGC(const char *i2c, struct Ql_ALC5616_DRCAGC *cfg);
367
368//
369// Function: Ql_Update_wav_size
370//
371// Description:
372// update wav format file size in the header
373// @param fd:
374// wav file discriptor
375// @param size:
376// wav file size to update
377int Ql_Update_wav_size(int fd, int size);
378
379//add by grady, 2018-5-29
380/*
381 * describe : this function is use to open pcm device
382 * paras :
383 * device : this should be fix to hw:0,0
384 * flags ; pcm play flags
385 * rate: sample rate
386 * channels : audio channal 1 or 2
387 * format: format to play or record, 16bit line,MP3
388 * hostless: if there is no file it is true
389 * return :
390 * pcm : pcm handle, use can use this handle to read write data
391 */
392struct pcm *quec_pcm_open(char *device, unsigned flags, unsigned rate, unsigned channels, unsigned format, unsigned hostless);
393
394/*
395 * describe : this function is use to close pcm handle
396 * paras :
397 * pcm : pcm handle to close
398 * return :
399 */
400int quec_pcm_close(struct pcm *pcm );
401
402/*
403 * describe : this function is use to read pcm buffer
404 * paras :
405 * pcm : pcm handle to write date
406 * buffer: data buffer
407 * lenth: data length
408 * return :
409 */
410int quec_read_pcm(struct pcm *pcm, void * buffer, int length);
411
412/*
413 * describe : this function is use to get pcm buffer lenth
414 * paras :
415 * lenth: data length
416 * return
417 * buffer length
418 */
419int quec_get_pem_buffer_len(struct pcm *pcm);
420
421//add by grady, 2018-6-2
422/*
423 * describe : this function is use to open mixer device
424 * paras :
425 * device: mixer device
426 * return
427 * mixer handle
428 */
429struct mixer *quec_mixer_open(const char *device);
430
431/*
432 * describe : this function is use to close mixer device
433 * paras :
434 * mixer: mixer handle
435 * return
436 * none
437 */
438void quec_mixer_close(struct mixer *mixer);
439
440/*
441 * describe : this function is use to get mixer devie control
442 * paras :
443 * mixer: mixer handle
444 * name: mixer device
445 * index: mixer index
446 * return
447 * mixer control
448 */
449struct mixer_ctl *quec_mixer_get_control(struct mixer *mixer, const char *name, unsigned index);
450
451/*
452 * describe : this function is use to set mulvalues
453 * paras :
454 * mixer: mixer handle
455 * count: count
456 * argv: data
457 * return :
458 *
459 */
460int quec_mixer_ctl_mulvalues(struct mixer_ctl *ctl, int count, char ** argv);
461
462
463//end grady
464
465/**
466 * @brief Set RX DSP Gain
467 * @details
468 * Gain support [-36,12] dB
469 *
470 * @param gain
471 * DSP gain
472 */
473
474int Ql_Rxgain_Set(int gain);
475
476/**
477 * @brief Set Playback PCM Samprate
478 * @details
479 * 0 for NB 1 for WB
480 *
481 * @param samprate
482 * samprate for PCM playback,default value is PCM NB
483 */
484
485
486int Ql_Playback_Samprate_Set(int samprate);
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/*****************************************************************
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* Function: Ql_Mp3_To_Wav
566*
567* Description:
568* set mp3 file change to wav file.
569*
570* Parameters:
571* wavpath : wav path
572*
573* mp3path : mp3 path
574*
575* Return:
576* 0: success
577* -1: fail
578*****************************************************************/
579int Ql_Mp3_To_Wav(const char *wavpath, char *mp3path);
580
581
582/*****************************************************************
583* Function: Ql_Mp3_To_Wav
584*
585* Description:
586* flay mp3 file.
587*
588* Parameters:
589* wavpath : wav path
590*
591* hdl : Device handle
592*
593* sample_rate : 0 for NB(8000) 1 for WB(16000)
594*
595* Return:
596* 0: success
597* -1: fail
598*****************************************************************/
599
600int Ql_Mp3_To_Play(char *mp3path, int hdl,int sample_rate);
601/*
602* Function: uac enable
603*
604* Description:
605* uac enable
606*
607* Parameters:
608* none
609* Return:
610* TURE or FALSE
611*/
612int ql_uac_enable(void);
613
614/*
615* Function: uac disable
616*
617* Description:
618* uac disable
619*
620* Parameters:
621* none
622* Return:
623* TURE or FALSE
624*/
625int ql_uac_disable(void);
626
627#endif //__AUD_H__