Add toolchain and mbtk source

Change-Id: Ie12546301367ea59240bf23d5e184ad7e36e40b3
diff --git a/mbtk/ql_lib/src/ql_audio.c b/mbtk/ql_lib/src/ql_audio.c
new file mode 100755
index 0000000..69f0361
--- /dev/null
+++ b/mbtk/ql_lib/src/ql_audio.c
@@ -0,0 +1,595 @@
+#include "ql/ql_audio.h"
+#include "mbtk_log.h"
+#include "mbtk_audio.h"
+
+static mbtk_audio_handle record_hdl = NULL;
+static _cb_onRecorder record_cb_fun = NULL;
+static int Samprate = 8000;
+
+/*****************************************************************
+* Function:     Ql_AudPlayer_Open
+*
+* Description:
+*               Open audio play device, and specify the callback function.
+*               This function can be called twice to play different audio sources.
+*
+* Parameters:
+*               device  : a string that specifies the PCM device.
+*                         NULL, means the audio will be played on the default PCM device.
+*
+*                         If you want to mixedly play audio sources, you can call this
+*                         API twice with specifying different PCM device.
+*                         The string devices available:
+*                            "hw:0,0"  (the default play device)
+*                            "hw:0,13" (this device can mix audio and TTS)
+*                            "hw:0,14"
+*
+*		        cb_func : callback function for audio player.
+*                         The results of all operations on audio player
+*                         are informed in callback function.
+*
+* Return:
+*               pcm device handle on success
+*               -1 for failure
+*****************************************************************/
+int Ql_AudPlayer_Open(char* device, _cb_onPlayer cb_func)
+{
+    return (int)mbtk_audio_open(MBTK_AUTIO_TYPE_OUT, 1, Samprate, cb_func);
+}
+
+/*========================================================================
+  FUNCTION:  Ql_AudPlayer_Play
+=========================================================================*/
+/** @brief
+    This function writes pcm data to pcm device to play.
+
+    @param[in] hdl, the handle returned by Ql_AudPlayer_Open().
+    @param[in] pData, pointer to the start address of pcm data.
+    @param[in] length, the length of pcm data.
+
+    @return
+    on success, the return value is the number of bytes to play
+    on failure, the return value is -1;
+
+    @dependencies
+    Ql_AudPlayer_Open() must be first called successfully.
+*/
+/*=======================================================================*/
+int Ql_AudPlayer_Play(int hdl, unsigned char* pData, unsigned int length)
+{
+    return mbtk_audio_play_stream((void *)hdl, pData, length);
+}
+
+/*========================================================================
+  FUNCTION:  Ql_AudPlayer_PlayFrmFile
+=========================================================================*/
+/** @brief
+    This function plays the pcm data from the specified file.
+
+    @param[in] hdl, the handle returned by Ql_AudPlayer_Open().
+    @param[in] fd, a file descriptor that contains pcm data.
+               Note:
+                 the file offset should be set to the start position of pcm
+                 data region, which means you should move the file offset
+                 skipping the file header (such as wave header, amr header).
+    @param[in] offset, file offset. Please set it to -1 if no need to use.
+
+    @return
+       0 on success
+      -1 on failure
+
+    @dependencies
+    Ql_AudPlayer_Open() must be first called successfully.
+*/
+/*=======================================================================*/
+int  Ql_AudPlayer_PlayFrmFile(int hdl, int fd, int offset)
+{
+    return mbtk_audio_play_file((void *)hdl, fd, offset);
+}
+
+//
+// Function:  Ql_AudPlayer_Pause
+//
+// Description:
+//   Pause playing.
+// @param hdl:
+//   Handle received from Ql_AudPlayer_Open().
+int  Ql_AudPlayer_Pause(int hdl)
+{
+    return mbtk_audio_pause((void *)hdl);
+}
+
+//
+// Function:  Ql_AudPlayer_Resume
+//
+// Description:
+//   Resume playing.
+// @param hdl:
+//   Handle received from Ql_AudPlayer_Open().
+int  Ql_AudPlayer_Resume(int hdl)
+{
+    return mbtk_audio_resume((void *)hdl);
+}
+
+//
+// Function:  Ql_AudPlayer_Stop
+//
+// Description:
+//   Stop playing audio
+// hdl:
+//   Handle received from Ql_AudPlayer_Open().
+void Ql_AudPlayer_Stop(int hdl)
+{
+    return mbtk_audio_stop((void *)hdl);
+}
+
+//
+// Function:  Ql_AudPlayer_Close
+//
+// Description:
+//   Close player, and free the resource.
+// @param hdl:
+//   Handle received from Ql_AudPlayer_Open().
+void Ql_AudPlayer_Close(int hdl)
+{
+    mbtk_audio_close((void *)hdl);
+}
+
+
+int Ql_AudPlayer_set_LessDataThreshold(int hdl, unsigned short threshSize)
+{
+
+    return 0;
+}
+
+int Ql_AudPlayer_get_freeSpace(int hdl)
+{
+
+    return 0;
+}
+
+
+/*****************************************************************
+* Function:     Ql_AudRecorder_Open
+*
+* Description:
+*               Open audio record device, and specify the callback function.
+*
+* Parameters:
+*               device  : not used. MUST be NULL.
+*
+*		        cb_func : callback function for audio player.
+*                         The results of all operations on audio recorder
+*                         are informed in callback function.
+*
+* Return:
+*               pcm device handle
+*               -1 for failure
+*****************************************************************/
+int  Ql_AudRecorder_Open(char* device, _cb_onRecorder cb_fun)
+{
+    record_hdl = mbtk_audio_open(MBTK_AUTIO_TYPE_IN, 1, 8000, NULL);
+    record_cb_fun = cb_fun;
+    return (int)record_hdl;
+}
+
+//
+// Function:  Ql_AudRecorder_StartRecord
+//
+// Description:
+//   Start to record.
+//   The record data is output in _cb_onRecorder.
+//
+// Return:
+//            0 on success
+//            -1 on failure
+int  Ql_AudRecorder_StartRecord(void)
+{
+    return mbtk_audio_record(record_hdl, record_cb_fun, NULL);
+}
+
+//
+// Function:  Ql_AudRecorder_Pause
+//
+// Description:
+//   Pause recording
+int  Ql_AudRecorder_Pause(void)
+{
+    return 0;
+}
+
+//
+// Function:  Ql_AudRecorder_Resume
+//
+// Description:
+//   Resume recording
+int  Ql_AudRecorder_Resume(void)
+{
+    return 0;
+}
+
+//
+// Function:  Ql_AudRecorder_Stop
+//
+// Description:
+//   Stop recording
+void Ql_AudRecorder_Stop(void)
+{
+
+}
+
+//
+// Function:  Ql_AudRecorder_Close
+//
+// Description:
+//   Close recorder, and free the resource
+void Ql_AudRecorder_Close(void)
+{
+    mbtk_audio_close(record_hdl);
+    record_hdl = NULL;
+    record_cb_fun = NULL;
+}
+
+//
+// Function:  Ql_clt_set_mixer_value
+//
+// Description:
+//   Close recorder, and free the resource
+boolean Ql_clt_set_mixer_value(const char *device, int count, const char *value)
+{
+
+    return FALSE;
+}
+
+
+int Ql_AudTone_Open(char* device, _cb_onPlayer cb)//cb not support now
+{
+    return 0;
+}
+
+int Ql_AudTone_Start(int hdl, struct Ql_TonePara *para)
+{
+    return 0;
+}
+
+void Ql_AudTone_Stop(int hdl)
+{
+
+}
+
+void Ql_AudTone_Close(int hdl)
+{
+
+}
+
+
+//****************QL Codec API************************//
+
+//
+// Function:  Ql_AudCodec_Set_ALC5616_DRCAGC
+//
+// Description:
+//   Set ALC5616 DRC/AGC configuration
+int Ql_AudCodec_Set_ALC5616_DRCAGC(const char *i2c, struct Ql_ALC5616_DRCAGC *cfg)
+{
+    return 0;
+}
+
+//
+// Function:   Ql_Update_wav_size
+//
+// Description:
+//   update wav format file size in the header
+// @param fd:
+//   wav file discriptor
+// @param size:
+//   wav file size to update
+int Ql_Update_wav_size(int fd, int size)
+{
+    return 0;
+}
+
+//add by grady, 2018-5-29
+/*
+ * describe : this function is use to open pcm device
+ * paras    :
+ *        device : this should be fix to hw:0,0
+ *        flags ; pcm play flags
+ *        rate: sample rate
+ *        channels  : audio channal 1 or 2
+ *        format: format to play or record, 16bit line,MP3
+ *        hostless: if there is no file it is true
+ * return    :
+ *        pcm : pcm handle, use can use this handle to read write data
+ */
+struct pcm *quec_pcm_open(char *device, unsigned flags, unsigned rate, unsigned channels, unsigned format, unsigned hostless)
+{
+    return NULL;
+}
+
+/*
+ * describe : this function is use to close pcm handle
+ * paras    :
+ *        pcm : pcm handle to close
+ * return    :
+ */
+int quec_pcm_close(struct pcm *pcm )
+{
+    return 0;
+}
+
+/*
+ * describe : this function is use to read pcm buffer
+ * paras    :
+ *        pcm : pcm handle to write date
+ *        buffer: data buffer
+ *        lenth: data length
+ * return    :
+ */
+int quec_read_pcm(struct pcm *pcm, void * buffer, int length)
+{
+
+    return 0;
+}
+
+/*
+ * describe : this function is use to get pcm buffer lenth
+ * paras    :
+ *        lenth: data length
+ * return
+ *        buffer length
+ */
+int quec_get_pem_buffer_len(struct pcm *pcm)
+{
+
+    return 0;
+}
+
+void dtmf_cb1(char dtmf)
+{
+    printf("%s:%c\n", __FUNCTION__, dtmf);
+}
+
+/**
+ * @brief Set RX DSP Gain
+ * @details
+ *      Gain support [-36,12] dB
+ *
+ * @param gain
+ *      DSP gain
+ */
+
+int Ql_Rxgain_Set(int value)
+{
+
+	printf("Volume is %d \n",value);
+	int volume =0;
+	int handler = 0;
+
+    if(value < -36 || value > 12)
+    {
+        volume = 0;
+    }
+    else
+    {
+        volume = value;
+    }
+
+    mbtk_audio_ubus_client_init(&handler, dtmf_cb1);
+	mbtk_audio_dsp_set(1, volume);
+
+	return 0;
+}
+
+
+/** Ql_Playback_Samprate_Set
+ * @brief Set Playback PCM Samprate
+ * @details
+ *      0 for NB 1 for WB
+ *
+ * @param samprate
+ *      samprate for PCM playback,default value is PCM NB
+ */
+int Ql_Playback_Samprate_Set(int samprate)
+{
+    printf("samprate is %d \n",samprate);
+    if(samprate == 1)
+    {
+       Samprate = 16000;
+    }
+    else{
+        Samprate = 8000;
+    }
+
+    return 0;
+}
+
+int Ql_Mp3_To_Wav(const char *wavpath, char *mp3path)
+{
+//    return 0;
+    return mbtk_audio_mp3_to_wav(wavpath, mp3path);
+}
+
+int Ql_Mp3_To_Play(char *mp3path, int hdl,int sample_rate)
+{
+ //   return 0;
+    return mbtk_audio_mp3_to_play(mp3path, hdl, sample_rate);
+}
+
+//add by grady, 2018-6-2
+/*
+ * describe : this function is use to open mixer device
+ * paras        :
+ *              device: mixer device
+ * return
+ *              mixer handle
+ */
+struct mixer *quec_mixer_open(const char *device)
+{
+
+    return NULL;
+}
+
+/*
+ * describe : this function is use to close mixer device
+ * paras        :
+ *              mixer: mixer handle
+ * return
+ *              none
+ */
+void quec_mixer_close(struct mixer *mixer)
+{
+
+
+}
+
+/*
+ * describe : this function is use to get mixer devie control
+ * paras        :
+ *              mixer: mixer handle
+ *              name: mixer device
+ *              index: mixer index
+ * return
+ *              mixer control
+ */
+struct mixer_ctl *quec_mixer_get_control(struct mixer *mixer, const char *name, unsigned index)
+{
+
+    return NULL;
+}
+
+/*
+ * describe : this function is use to set mulvalues
+ * paras        :
+ *              mixer: mixer handle
+ *              count: count
+ *              argv: data
+ * return       :
+ *
+ */
+int quec_mixer_ctl_mulvalues(struct mixer_ctl *ctl, int count, char ** argv)
+{
+
+    return 0;
+}
+
+
+//end grady
+
+/*****************************************************************
+* Function:     Ql_AudPlayer_OpenExt
+*
+* Description:
+*               expend function from Ql_AudPlayer_OpenExt
+*               Open audio play device, and specify the callback function.
+*               This function can be called twice to play different audio sources.
+*
+* Parameters:
+*               device  : a string that specifies the PCM device.
+*                         NULL, means the audio will be played on the default PCM device.
+*
+*                         If you want to mixedly play audio sources, you can call this
+*                         API twice with specifying different PCM device.
+*                         The string devices available:
+*                            "hw:0,0"  (the default play device)
+*                            "hw:0,13" (this device can mix audio and TTS)
+*                            "hw:0,14"
+*
+*		        cb_func : callback function for audio player.
+*                         The results of all operations on audio player
+*                         are informed in callback function.
+*
+*               flags   : pcm flags, eg: PCM_MMAP, PCM_NMMAP.
+*
+*               channels: pcm sample channels.
+*
+*               rate    : pcm sample rate.
+*
+*               format  : pcm sample fromat
+*
+* Return:
+*               pcm device handle
+*               NULL, fail
+*****************************************************************/
+int Ql_AudPlayer_OpenExt(
+            char *dev,
+            _cb_onPlayer cb_fun,
+            int flags,
+            int channels,
+            int rate,
+            int format)
+{
+    return 0;
+}
+
+/*****************************************************************
+* Function:     Ql_AudRecorder_Open
+*
+* Description:
+*               Open audio record device, and specify the callback function.
+*
+* Parameters:
+*               device  : not used. MUST be NULL.
+*
+*		        cb_func : callback function for audio player.
+*                         The results of all operations on audio recorder
+*                         are informed in callback function.
+*
+*               flags   : pcm flags, eg: PCM_MMAP, PCM_NMMAP.
+*
+*               channels: pcm sample channels.
+*
+*               rate    : pcm sample rate.
+*
+*               format  : pcm sample fromat
+*
+* Return:
+*               pcm device handle
+*               NULL, fail
+*****************************************************************/
+int Ql_AudRecorder_OpenExt(
+            char *dev,
+            _cb_onRecorder cb_fun,
+            int flags,
+            int channels,
+            int rate,
+            int format)
+{
+
+
+    return 0;
+}
+
+/*
+* Function:     uac enable
+*
+* Description:
+*               uac enable
+*
+* Parameters:
+*               none
+* Return:
+*               TURE or FALSE
+*/
+int ql_uac_enable(void)
+{
+
+    return 0;
+}
+
+/*
+* Function:     uac disable
+*
+* Description:
+*               uac disable
+*
+* Parameters:
+*               none
+* Return:
+*               TURE or FALSE
+*/
+int ql_uac_disable(void)
+{
+
+    return 0;
+}