diff --git a/mbtk/mbtk_audio_lib/src/mbtk_mp3.c b/mbtk/mbtk_audio_lib/src/mbtk_mp3.c
new file mode 100755
index 0000000..8b13789
--- /dev/null
+++ b/mbtk/mbtk_audio_lib/src/mbtk_mp3.c
@@ -0,0 +1 @@
+
diff --git a/mbtk/mbtk_audio_lib/src/mbtk_pcm_stream.c b/mbtk/mbtk_audio_lib/src/mbtk_pcm_stream.c
new file mode 100755
index 0000000..54ae1be
--- /dev/null
+++ b/mbtk/mbtk_audio_lib/src/mbtk_pcm_stream.c
@@ -0,0 +1,526 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "mbtk_log.h"
+#include "mbtk_audio_internal.h"
+
+#define LOCK_FILE "/var/run/mbtk_audio.lock"
+#define AUDIO_DEBUG 0
+
+#define AUDIO_LOG(fmt, args ...) \
+    do{ \
+        if(AUDIO_DEBUG) {LOGD(fmt, ##args);} \
+    } while(0)
+
+extern void* audio_hal_install(void);
+extern void audio_hal_uninstall(void);
+extern void configure_vcm(unsigned int data[]);
+
+static audio_inter_info_t *audio_info = NULL;
+static pthread_t recorder_thread_play;
+
+static int lock_get() {
+    int fd = open(LOCK_FILE, O_WRONLY | O_CREAT | O_TRUNC);
+    if (fd == -1) {
+        LOGE("Open(%s) fail:%d", LOCK_FILE, errno);
+        return -1;
+    }
+    // 尝试对文件进行加锁
+    struct flock fl;
+    fl.l_type = F_WRLCK;
+    fl.l_whence = SEEK_SET;
+    fl.l_start = 0;
+    fl.l_len = 1;
+    int ret = fcntl(fd, F_SETLK, &fl);
+    if (ret == -1) {
+        LOGE("Another instance is running, exiting...");
+        close(fd);
+        return -1;
+    }
+    close(fd);
+    LOGD("Get file lock.");
+    return 0;
+}
+
+static int lock_free() {
+    int fd = open(LOCK_FILE, O_WRONLY | O_CREAT | O_TRUNC);
+    if (fd == -1) {
+        LOGE("Open(%s) fail:%d", LOCK_FILE, errno);
+        return -1;
+    }
+    // 释放文件锁
+    struct flock fl;
+    fl.l_type = F_UNLCK;
+    fl.l_whence = SEEK_SET;
+    fl.l_start = 0;
+    fl.l_len = 1;
+    int ret = fcntl(fd, F_SETLK, &fl);
+    if (ret == -1) {
+        LOGE("Another instance is running, exiting...");
+        close(fd);
+        return -1;
+    }
+
+    LOGD("Free file lock.");
+    return 0;
+}
+
+static void audio_recorder_thread(void *arg)
+{
+    int rc, len, frames = 0;
+    char buff[MBTK_PCM_WB_BUF_SIZE];
+
+    audio_info->info.recorder.state = AUDIO_RECORDER_STATE_RUNNING;
+    pthread_mutex_init(&audio_info->info.recorder.mutex, NULL);
+    pthread_cond_init(&audio_info->info.recorder.cond, NULL);
+
+    while (TRUE) {
+        /* Playback loop */
+        pthread_mutex_lock(&audio_info->info.recorder.mutex);
+        if(audio_info->info.recorder.state == AUDIO_RECORDER_STATE_STOP) {
+            LOGD("Stop recorder...");
+            pthread_mutex_unlock(&audio_info->info.recorder.mutex);
+            break;
+        } else if(audio_info->info.recorder.state == AUDIO_RECORDER_STATE_PAUSE) {
+            pthread_cond_wait(&audio_info->info.recorder.cond, &audio_info->info.recorder.mutex);
+            pthread_mutex_unlock(&audio_info->info.recorder.mutex);
+            continue;
+        } else {
+            pthread_mutex_unlock(&audio_info->info.recorder.mutex);
+        }
+
+        //record the needed format stream from the device.
+        //only read pcm stream, no send command.
+        len = audio_info->info.recorder.stream_in->read(audio_info->info.recorder.stream_in, buff,
+                    audio_info->playback_size);
+        if (len <= 0) {
+            LOGE("%s: error reading!", __FUNCTION__);
+            goto thread_end;
+        }
+
+        AUDIO_LOG("Recorder data : len - %d", len);
+
+        if(audio_info->info.recorder.recorder_cb) {
+            audio_info->info.recorder.recorder_cb(buff, len);
+        }
+
+        LOGD("%s: No.%d frame playback.", __FUNCTION__, ++frames);
+    }
+
+
+thread_end:
+    pthread_mutex_destroy(&audio_info->info.recorder.mutex);
+    pthread_cond_destroy(&audio_info->info.recorder.cond);
+
+    audio_info->info.recorder.stream_in->common.standby(&audio_info->info.recorder.stream_in->common);
+    audio_info->audio_ahw_dev_ubus->close_input_stream(audio_info->audio_ahw_dev_ubus, audio_info->info.recorder.stream_in);
+    VCMDeinit();//close the fd of audiostub_ctl when exit the thread.
+    audio_info->info.recorder.stream_in = NULL;
+    LOGD("%s: finished pcm playback.", __FUNCTION__);
+
+    // Notify audio recorder data end.
+    if(audio_info->info.recorder.recorder_cb) {
+        audio_info->info.recorder.recorder_cb(NULL, 0);
+    }
+    return;
+}
+
+
+static int config_parameters(mbtk_audio_direction_enum direction, mbtk_audio_sample_rate_enum NBWB)
+{
+    unsigned int srcdst, priority, dest;
+    char kvpair[128];
+    struct str_parms *param = NULL;
+    int data[5];
+    const char *key = NULL;
+    bool update_vcm = false;
+
+    srcdst = 1;/* 0-None, 1-Near end, 2-Far end, 3-Both ends */
+    priority = 1;/* 0-Do not combine(override), 1-Combine */
+    dest = 1;/* 0-Near codec, 1-Near Vocoder */
+
+    if(direction == MBTK_AUDIO_DIRECTION_OUTPUT){//output
+        if(NBWB == MBTK_AUDIO_SAMPLE_RATE_8000)
+            audio_info->playback_size = MBTK_PCM_NB_BUF_SIZE;
+        else
+            audio_info->playback_size = MBTK_PCM_WB_BUF_SIZE;
+
+        LOGD("config playback parameters.");
+    }
+    else if(direction == MBTK_AUDIO_DIRECTION_INPUT){//input
+        if(NBWB == MBTK_AUDIO_SAMPLE_RATE_8000)
+            audio_info->playback_size = MBTK_PCM_NB_BUF_SIZE;
+        else
+            audio_info->playback_size = MBTK_PCM_WB_BUF_SIZE;
+
+        LOGD("config record parameters.");
+    }
+
+    memset(kvpair, 0x00, sizeof(kvpair));
+    sprintf(kvpair, "%s=%d;%s=%d;%s=%d;%s=%d;%s=%d", VCM_CONFIG_DIRECTION, direction,
+            VCM_CONFIG_TYPE, NBWB, VCM_CONFIG_SRC_DST, srcdst,
+            VCM_CONFIG_PRIORITY, priority, VCM_CONFIG_DEST, dest);
+
+    LOGD("%s: config information kvpair is %s.\n", __FUNCTION__, kvpair);
+
+    //extract the parameter and config from string
+    param = str_parms_create_str(kvpair);
+    if (!param) {
+        LOGE("%s: param create str is null!", __FUNCTION__);
+        return -1;
+    }
+
+    //set vcm configurations
+    key = VCM_CONFIG_DIRECTION;
+    if (str_parms_get_int(param, key, &data[0]) == 0) {
+        update_vcm = true;
+        str_parms_del(param, key);
+    }
+    key = VCM_CONFIG_TYPE;
+    if (str_parms_get_int(param, key, &data[1]) == 0) {
+        update_vcm = true;
+        str_parms_del(param, key);
+    }
+    key = VCM_CONFIG_SRC_DST;
+    if (str_parms_get_int(param, key, &data[2]) == 0) {
+        update_vcm = true;
+        str_parms_del(param, key);
+    }
+    key = VCM_CONFIG_PRIORITY;
+    if (str_parms_get_int(param, key, &data[3]) == 0) {
+        update_vcm = true;
+        str_parms_del(param, key);
+    }
+    key = VCM_CONFIG_DEST;
+    if (str_parms_get_int(param, key, &data[4]) == 0) {
+        update_vcm = true;
+        str_parms_del(param, key);
+    }
+
+    //printf("Direction is %d, Type is %d, Src_Dst is %d, Priority is %d, Dest is %d. \n",data[0], data[1], data[2], data[3], data[4]);
+
+    if (update_vcm) {
+        configure_vcm(data);   /*TODO check if all inputs got all values successfully*/
+    }
+
+    return 0;
+}
+
+int mbtk_audio_pcm_init()
+{
+    //mbtk_log_init("radio", "MBTK_AUDIO");
+    // Audio is running...
+    if(lock_get()) {
+        return -1;
+    }
+
+    if(audio_info) {
+        return 0;
+    }
+
+    audio_info = (audio_inter_info_t*)malloc(sizeof(audio_inter_info_t));
+    if(audio_info == NULL) {
+        LOGE("malloc() fail:%d", errno);
+        return -1;
+    }
+    memset(audio_info, 0x00, sizeof(audio_inter_info_t));
+
+    // Set default audio parameter.
+    audio_info->channel = 1;
+    audio_info->sample_rate = MBTK_AUDIO_SAMPLE_RATE_8000;
+    audio_info->playback_size = MBTK_PCM_NB_BUF_SIZE;
+
+    audio_info->audio_ahw_dev_ubus = audio_hal_install();
+    if (audio_info->audio_ahw_dev_ubus == NULL) {
+        LOGE("audio_hal_install() failed!");
+        goto init_fail;
+    }
+    return 0;
+init_fail:
+    free(audio_info);
+    audio_info = NULL;
+    return -1;
+}
+
+int mbtk_audio_pcm_sample_rate_set(mbtk_audio_sample_rate_enum sample_rate)
+{
+    if(!audio_info) {
+        LOGE("Not inited.");
+        return -1;
+    }
+
+    audio_info->sample_rate = sample_rate;
+
+    return 0;
+}
+
+int mbtk_audio_pcm_play_start()
+{
+    if(!audio_info) {
+        LOGE("Not inited.");
+        return -1;
+    }
+
+    if(!audio_info->audio_ahw_dev_ubus) {
+        LOGE("audio_info->audio_ahw_dev_ubus is NULL.");
+        return -1;
+    }
+
+    config_parameters(MBTK_AUDIO_DIRECTION_OUTPUT, audio_info->sample_rate);
+
+    int rc = audio_info->audio_ahw_dev_ubus->open_output_stream(audio_info->audio_ahw_dev_ubus, 0,
+            audio_info->audio_ahw_dev_ubus->get_supported_devices(audio_info->audio_ahw_dev_ubus),
+            AUDIO_OUTPUT_FLAG_DIRECT, NULL, &(audio_info->info.play.stream_out), 0);
+    if (rc < 0) {
+        LOGE("Open output device fail:%d", rc);
+        goto play_start_fail;
+    }
+
+    audio_info->direction = MBTK_AUDIO_DIRECTION_OUTPUT;
+    audio_info->info.play.buff_remain_len = 0;
+
+    return 0;
+play_start_fail:
+
+    return -1;
+}
+
+int mbtk_audio_pcm_play_data_send(const void* data,uint32 data_len)
+{
+    UNUSED(data);
+    UNUSED(data_len);
+
+    if(!audio_info) {
+        LOGE("Not inited.");
+        return -1;
+    }
+
+    if(!audio_info->info.play.stream_out) {
+        LOGE("Output device not open.");
+        return -1;
+    }
+
+    uint32 index = 0;
+    // There are remaining data from the previous package。
+    if(audio_info->info.play.buff_remain_len > 0) {
+        // Too less for one package.
+        if(data_len + audio_info->info.play.buff_remain_len < audio_info->playback_size) {
+            AUDIO_LOG("Save remain data : len - %d", data_len);
+            memcpy(audio_info->info.play.buff_remain + audio_info->info.play.buff_remain_len, data, data_len);
+            audio_info->info.play.buff_remain_len += data_len;
+            return data_len;
+        } else {
+            AUDIO_LOG("Write remain data : %d + %d", audio_info->info.play.buff_remain_len, audio_info->playback_size - audio_info->info.play.buff_remain_len);
+            memcpy(audio_info->info.play.buff_remain + audio_info->info.play.buff_remain_len, data, audio_info->playback_size - audio_info->info.play.buff_remain_len);
+
+            int rc = audio_info->info.play.stream_out->write(audio_info->info.play.stream_out, audio_info->info.play.buff_remain, audio_info->playback_size);
+            if (rc < 0) {
+                LOGE("%s: error writing (child).", __FUNCTION__);
+                goto send_fail;
+            } else if (rc < (signed int)audio_info->playback_size) {
+                LOGW("%s: wrote less than buffer size, rc=%d.", __FUNCTION__, rc);
+                index += rc;
+                goto send_fail;
+            }
+
+            index += (audio_info->playback_size - audio_info->info.play.buff_remain_len);
+            audio_info->info.play.buff_remain_len = 0;
+        }
+    }
+
+    while(data_len - index >= audio_info->playback_size) {
+        AUDIO_LOG("Package : %d -> %d", index, index + audio_info->playback_size - 1);
+        int rc = audio_info->info.play.stream_out->write(audio_info->info.play.stream_out, (const char*)data + index, audio_info->playback_size);
+        if (rc < 0) {
+            LOGE("%s: error writing (child).", __FUNCTION__);
+            goto send_fail;
+        } else if (rc < (signed int)audio_info->playback_size) {
+            LOGW("%s: wrote less than buffer size, rc=%d.", __FUNCTION__, rc);
+            goto send_fail;
+        }
+
+        index += rc;
+    }
+
+    // Last package.( less then audio_info->playback_size)
+    // Save to buffer audio_info->play_buff_remain
+    if(data_len - index > 0) {
+        AUDIO_LOG("Save remain data : len - %d", data_len - index);
+        memcpy(audio_info->info.play.buff_remain, data + index, data_len - index);
+        audio_info->info.play.buff_remain_len = data_len - index;
+    }
+
+    return data_len;
+send_fail:
+    return -1;
+}
+
+int mbtk_audio_pcm_play_stop()
+{
+    if(!audio_info) {
+        LOGE("Not inited.");
+        return -1;
+    }
+
+    if(!audio_info->info.play.stream_out) {
+        LOGE("Output device not open.");
+        return -1;
+    }
+
+    // Write last package.
+    if(audio_info->info.play.buff_remain_len > 0) {
+        char buf[MBTK_PCM_WB_BUF_SIZE];
+        memset(buf, 0x00, sizeof(buf));
+        memcpy(buf, audio_info->info.play.buff_remain, audio_info->info.play.buff_remain_len);
+
+        LOGD("len %d is smaller than needed %d, so fill the buffer with 0.", audio_info->info.play.buff_remain_len, audio_info->playback_size);
+
+        int rc = audio_info->info.play.stream_out->write(audio_info->info.play.stream_out, buf, audio_info->playback_size);
+        if (rc < 0) {
+            LOGE("%s: error writing (child).", __FUNCTION__);
+            //goto send_fail;
+        } else if (rc < (signed int)audio_info->playback_size) {
+            LOGW("%s: wrote less than buffer size, rc=%d.", __FUNCTION__, rc);
+            //goto send_fail;
+        }
+        audio_info->info.play.buff_remain_len = 0;
+    }
+
+    vcm_playback_drain(0);//wait for drain the AP audiostub queue.
+    usleep(80000);//delay 80ms until DSP play out its buffered data.
+    audio_info->info.play.stream_out->common.standby(&(audio_info->info.play.stream_out->common));
+    audio_info->audio_ahw_dev_ubus->close_output_stream(audio_info->audio_ahw_dev_ubus, audio_info->info.play.stream_out);
+
+    audio_info->info.play.stream_out = NULL;
+    return 0;
+}
+
+
+int mbtk_audio_pcm_recorder_start(mbtk_recorder_callback_func recorder_cb)
+{
+    if(!audio_info) {
+        LOGE("Not inited.");
+        return -1;
+    }
+
+    if(!audio_info->audio_ahw_dev_ubus) {
+        LOGE("audio_info->audio_ahw_dev_ubus is NULL.");
+        return -1;
+    }
+
+    if(audio_info->info.recorder.state != AUDIO_RECORDER_STATE_STOP) {
+        LOGW("Audio is recorder...");
+        return -1;
+    }
+
+    config_parameters(MBTK_AUDIO_DIRECTION_INPUT, audio_info->sample_rate);
+
+    VCMInit();
+
+    int rc = audio_info->audio_ahw_dev_ubus->open_input_stream(audio_info->audio_ahw_dev_ubus, 0,
+                audio_info->audio_ahw_dev_ubus->get_supported_devices(audio_info->audio_ahw_dev_ubus),
+                NULL, &(audio_info->info.recorder.stream_in), 0, 0, AUDIO_SOURCE_VOICE_CALL);
+    if (rc < 0) {
+        LOGE("Open input device fail:%d", rc);
+        goto recorder_start_fail;
+    }
+
+    audio_info->direction = MBTK_AUDIO_DIRECTION_INPUT;
+    audio_info->info.recorder.recorder_cb = recorder_cb;
+
+    pthread_attr_t thread_attr;
+    pthread_attr_init(&thread_attr);
+    if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
+    {
+        LOGE("pthread_attr_setdetachstate() fail.");
+        return -1;
+    }
+
+    if (pthread_create(&recorder_thread_play, NULL, (void *)&audio_recorder_thread, NULL) < 0) {
+        LOGE("%s: error creating thread_recorder!", __FUNCTION__);
+        return -1;
+    }
+
+    return 0;
+recorder_start_fail:
+
+    return -1;
+}
+
+int mbtk_audio_pcm_recorder_pause()
+{
+    int result = 0;
+    pthread_mutex_lock(&audio_info->info.recorder.mutex);
+    if(audio_info->info.recorder.state == AUDIO_RECORDER_STATE_RUNNING) {
+        audio_info->info.recorder.state = AUDIO_RECORDER_STATE_PAUSE;
+    } else {
+        result = -1;
+        LOGW("Audio state : %d", audio_info->info.recorder.state);
+    }
+    pthread_mutex_unlock(&audio_info->info.recorder.mutex);
+    return result;
+}
+
+int mbtk_audio_pcm_recorder_resume()
+{
+    int result = 0;
+    pthread_mutex_lock(&audio_info->info.recorder.mutex);
+    if(audio_info->info.recorder.state == AUDIO_RECORDER_STATE_PAUSE) {
+        audio_info->info.recorder.state = AUDIO_RECORDER_STATE_RUNNING;
+        pthread_cond_signal(&audio_info->info.recorder.cond);
+    } else {
+        result = -1;
+        LOGW("Audio state : %d", audio_info->info.recorder.state);
+    }
+    pthread_mutex_unlock(&audio_info->info.recorder.mutex);
+    return result;
+}
+
+
+int mbtk_audio_pcm_recorder_stop()
+{
+    int result = 0;
+    pthread_mutex_lock(&audio_info->info.recorder.mutex);
+    if(audio_info->info.recorder.state == AUDIO_RECORDER_STATE_PAUSE || audio_info->info.recorder.state == AUDIO_RECORDER_STATE_RUNNING) {
+        if(audio_info->info.recorder.state == AUDIO_RECORDER_STATE_PAUSE) {
+            pthread_cond_signal(&audio_info->info.recorder.cond);
+        }
+        audio_info->info.recorder.state = AUDIO_RECORDER_STATE_STOP;
+        pthread_mutex_unlock(&audio_info->info.recorder.mutex);
+
+        LOGD("Waitting recorder thread exit...");
+        if (pthread_join(recorder_thread_play, NULL)) {
+            LOGE("error join thread_recorder!");
+            // abort();
+        }
+        LOGD("Recorder thread exit success.");
+    } else {
+        pthread_mutex_unlock(&audio_info->info.recorder.mutex);
+        result = -1;
+        LOGW("Audio state : %d", audio_info->info.recorder.state);
+    }
+
+    return result;
+}
+
+int mbtk_audio_pcm_deinit()
+{
+    if(!audio_info) {
+        LOGE("Not inited.");
+        return -1;
+    }
+
+    audio_hal_uninstall();
+
+    if(lock_free()) {
+        return -1;
+    }
+
+    free(audio_info);
+    audio_info = NULL;
+    return 0;
+}
+
diff --git a/mbtk/mbtk_audio_lib/src/mbtk_wav.c b/mbtk/mbtk_audio_lib/src/mbtk_wav.c
new file mode 100755
index 0000000..dca245c
--- /dev/null
+++ b/mbtk/mbtk_audio_lib/src/mbtk_wav.c
@@ -0,0 +1,333 @@
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "mbtk_log.h"
+#include "mbtk_audio_internal.h"
+
+#define WAV_PLAY_BUFF 2048
+
+static int wav_play_fd = -1;
+static audio_play_state_enum play_state = AUDIO_PLAY_STATE_STOP;
+static pthread_cond_t play_cond;
+static pthread_mutex_t play_mutex;
+static pthread_t play_thread_play;
+
+static int wav_recorder_fd = -1;
+static struct wav_header recorder_header;
+static uint32 recorver_data_count = 0;
+
+static void audio_play_thread(void *arg)
+{
+    int rc, len, frames = 0;
+    char buf[WAV_PLAY_BUFF];
+
+    play_state = AUDIO_PLAY_STATE_RUNNING;
+    pthread_mutex_init(&play_mutex, NULL);
+    pthread_cond_init(&play_cond, NULL);
+
+    while (TRUE) {
+        /* Playback loop */
+        pthread_mutex_lock(&play_mutex);
+        if(play_state == AUDIO_PLAY_STATE_STOP) {
+            LOGD("Stop play...");
+            pthread_mutex_unlock(&play_mutex);
+            break;
+        } else if(play_state == AUDIO_PLAY_STATE_PAUSE) {
+            pthread_cond_wait(&play_cond, &play_mutex);
+            pthread_mutex_unlock(&play_mutex);
+            continue;
+        } else {
+            pthread_mutex_unlock(&play_mutex);
+        }
+
+        memset(buf, 0x00, sizeof(buf));
+        len = read(wav_play_fd, buf, WAV_PLAY_BUFF);
+        if (len == -1) {
+            LOGE("%s: error reading from file", __FUNCTION__);
+            goto thread_end;
+        }
+
+        if (len == 0) {
+            /* reached EOF */
+            LOGE("%s: Read wav file end.", __FUNCTION__);
+            break;
+        }
+
+        if((rc = mbtk_audio_pcm_play_data_send(buf, len)) < len) {
+            LOGE("Send data %d/%d", rc, len);
+            goto thread_end;
+        }
+
+        LOGD("%s: No.%d frame playback", __FUNCTION__, ++frames);
+    }
+
+    play_state = AUDIO_PLAY_STATE_STOP;
+
+thread_end:
+    pthread_mutex_destroy(&play_mutex);
+    pthread_cond_destroy(&play_cond);
+    mbtk_audio_pcm_play_stop();
+
+    if (close(wav_play_fd))
+        LOGE("%s: error closing file", __FUNCTION__);
+
+    wav_play_fd = -1;
+    LOGD("%s: finished pcm playback.", __FUNCTION__);
+    return;
+}
+
+static void audio_recorder_cb(void *data, uint32 data_len)
+{
+    if(data_len > 0) {
+        LOGD("Recorver data:%d, count:%d", data_len, recorver_data_count);
+        if (write(wav_recorder_fd, data, data_len) < data_len) {
+            LOGE("%s: error writing to file!", __FUNCTION__);
+        }
+        recorver_data_count += data_len;
+    } else {
+        LOGD("Recorver data end.");
+        recorder_header.data_sz = recorver_data_count;
+        recorder_header.riff_sz = recorder_header.data_sz + sizeof(recorder_header) - 8;
+        lseek(wav_recorder_fd, 0, SEEK_SET);
+        write(wav_recorder_fd, &recorder_header, sizeof(struct wav_header));
+
+        close(wav_recorder_fd);
+        wav_recorder_fd = -1;
+    }
+}
+
+int mbtk_audio_wav_init()
+{
+    //mbtk_log_init("radio", "MBTK_AUDIO");
+    return mbtk_audio_pcm_init();
+}
+
+int mbtk_audio_wav_play_start(const void *wav_file)
+{
+    struct stat st;
+    const char *path = (const char *)wav_file;
+    struct riff_wave_header riff_wave_header;
+    struct chunk_header chunk_header;
+    struct chunk_fmt chunk_fmt = {0};
+    unsigned int more_chunks = 1;
+
+    if(play_state != AUDIO_PLAY_STATE_STOP) {
+        LOGW("Audio is playing...");
+        return -1;
+    }
+
+    /* Check and open source file */
+    if (access(path, F_OK) || stat(path, &st)) {
+        LOGE("%s: error reading from file %s", __FUNCTION__, path);
+        return -1;
+    }
+
+    if (!st.st_size) {
+        LOGE("%s: empty file %s", __FUNCTION__, path);
+        return -1;
+    }
+
+    wav_play_fd = open(path, O_RDONLY);
+    if (wav_play_fd < 0) {
+        LOGE("%s: error opening file %s", __FUNCTION__, path);
+        return -1;
+    }
+
+    read(wav_play_fd, &riff_wave_header, sizeof(riff_wave_header));
+    if ((riff_wave_header.riff_id != ID_RIFF) || (riff_wave_header.wave_id != ID_WAVE)) {
+        LOGE("Error: '%s' is not a riff/wave file", path);
+        close(wav_play_fd);
+        return -1;
+    }
+
+    do {
+        read(wav_play_fd, &chunk_header, sizeof(chunk_header));
+
+        switch (chunk_header.id) {
+            case ID_FMT:
+                read(wav_play_fd, &chunk_fmt, sizeof(chunk_fmt));
+                /* If the format header is larger, skip the rest */
+                if (chunk_header.sz > sizeof(chunk_fmt))
+                    lseek(wav_play_fd, chunk_header.sz - sizeof(chunk_fmt), SEEK_CUR);
+                break;
+            case ID_DATA:
+                /* Stop looking for chunks */
+                more_chunks = 0;
+                break;
+            default:
+                /* Unknown chunk, skip bytes */
+                lseek(wav_play_fd, chunk_header.sz, SEEK_CUR);
+        }
+    } while (more_chunks);
+
+    //Support 8k/16k & mono wave file
+    if (((chunk_fmt.sample_rate != 8000) && (chunk_fmt.sample_rate != 16000))
+            || (chunk_fmt.num_channels != 1) ) {
+        LOGD("%s: error wave file:sample_rate = %d, num_channels = %d!!",
+                __FUNCTION__,chunk_fmt.sample_rate, chunk_fmt.num_channels);
+        close(wav_play_fd);
+        return -1;
+    }
+
+    LOGE("%s: success open wave file:%s, sample_rate = %d, num_channels = %d.",
+            __FUNCTION__, path, chunk_fmt.sample_rate, chunk_fmt.num_channels);
+
+    if ((8000 == chunk_fmt.sample_rate) && (1 == chunk_fmt.num_channels)) {
+        mbtk_audio_pcm_sample_rate_set(MBTK_AUDIO_SAMPLE_RATE_8000);
+    } else if ((16000 == chunk_fmt.sample_rate) && (1 == chunk_fmt.num_channels)) {
+        mbtk_audio_pcm_sample_rate_set(MBTK_AUDIO_SAMPLE_RATE_16000);
+    }
+
+    if (mbtk_audio_pcm_play_start()) {
+        LOGE("%s: error opening output device.", __FUNCTION__);
+        return -1;
+    }
+
+    LOGD("Start play wav file...");
+
+    pthread_attr_t thread_attr;
+    pthread_attr_init(&thread_attr);
+    if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
+    {
+        LOGE("pthread_attr_setdetachstate() fail.");
+        return -1;
+    }
+
+    if (pthread_create(&play_thread_play, NULL, (void *)&audio_play_thread, NULL) < 0) {
+        LOGE("%s: error creating thread_play!", __FUNCTION__);
+        return -1;
+    }
+
+    return 0;
+}
+
+int mbtk_audio_wav_play_pause()
+{
+    int result = 0;
+    pthread_mutex_lock(&play_mutex);
+    if(play_state == AUDIO_PLAY_STATE_RUNNING) {
+        play_state = AUDIO_PLAY_STATE_PAUSE;
+    } else {
+        result = -1;
+        LOGW("Audio state : %d", play_state);
+    }
+    pthread_mutex_unlock(&play_mutex);
+    return result;
+}
+
+int mbtk_audio_wav_play_resume()
+{
+    int result = 0;
+    pthread_mutex_lock(&play_mutex);
+    if(play_state == AUDIO_PLAY_STATE_PAUSE) {
+        play_state = AUDIO_PLAY_STATE_RUNNING;
+        pthread_cond_signal(&play_cond);
+    } else {
+        result = -1;
+        LOGW("Audio state : %d", play_state);
+    }
+    pthread_mutex_unlock(&play_mutex);
+    return result;
+}
+
+
+int mbtk_audio_wav_play_stop()
+{
+    int result = 0;
+    pthread_mutex_lock(&play_mutex);
+    if(play_state == AUDIO_PLAY_STATE_PAUSE || play_state == AUDIO_PLAY_STATE_RUNNING) {
+        if(play_state == AUDIO_PLAY_STATE_PAUSE) {
+            pthread_cond_signal(&play_cond);
+        }
+        play_state = AUDIO_PLAY_STATE_STOP;
+        pthread_mutex_unlock(&play_mutex);
+
+        LOGD("Waitting play thread exit...");
+        if (pthread_join(play_thread_play, NULL)) {
+            LOGE("error join thread_play!");
+            // abort();
+        }
+        LOGD("Play thread exit success.");
+    } else {
+        pthread_mutex_unlock(&play_mutex);
+        result = -1;
+        LOGW("Audio state : %d", play_state);
+    }
+
+    return result;
+}
+
+int mbtk_audio_wav_recorder_start(const void *wav_file, mbtk_audio_sample_rate_enum sample_rate)
+{
+    int rc;
+    const char *path = (const char *)wav_file;
+
+    LOGD("wav_file is %s.", path);
+    if(wav_recorder_fd > 0) {
+        LOGW("Audio is recorder...");
+    }
+
+    memset(&recorder_header, 0x0, sizeof(struct wav_header));
+    recorder_header.riff_id = ID_RIFF;
+    recorder_header.riff_sz = 0;
+    recorder_header.riff_fmt = ID_WAVE;
+    recorder_header.fmt_id = ID_FMT;
+    recorder_header.fmt_sz = 16;
+    recorder_header.audio_format = 1;        //FORMAT_PCM;
+    recorder_header.num_channels = 1;        //Modem ONLY support mono recording
+    recorder_header.sample_rate = (sample_rate == MBTK_AUDIO_SAMPLE_RATE_8000 ? 8000 : 16000);
+    recorder_header.bits_per_sample = 16;    //PCM_SAMPLEBITS_S16_LE;
+    recorder_header.byte_rate = (recorder_header.bits_per_sample / 8) * recorder_header.num_channels * recorder_header.sample_rate;
+    recorder_header.block_align = recorder_header.num_channels * (recorder_header.bits_per_sample / 8);
+    recorder_header.data_id = ID_DATA;
+
+    mbtk_audio_pcm_sample_rate_set(sample_rate);
+
+    wav_recorder_fd = open(path, O_WRONLY | O_CREAT | O_TRUNC);
+    if (wav_recorder_fd < 0) {
+        LOGE("%s: error opening file %s!", __FUNCTION__, path);
+        return -1;
+    }
+
+    //leave enough room for header
+    lseek(wav_recorder_fd, sizeof(struct wav_header), SEEK_SET);
+
+    recorver_data_count = 0;
+
+    return mbtk_audio_pcm_recorder_start(audio_recorder_cb);
+}
+
+int mbtk_audio_wav_recorder_pause()
+{
+    return mbtk_audio_pcm_recorder_pause();
+}
+
+int mbtk_audio_wav_recorder_resume()
+{
+    return mbtk_audio_pcm_recorder_resume();
+}
+
+
+int mbtk_audio_wav_recorder_stop()
+{
+    return mbtk_audio_pcm_recorder_stop();
+}
+
+int mbtk_audio_wav_deinit()
+{
+    if(play_state != AUDIO_PLAY_STATE_STOP) {
+        if(mbtk_audio_wav_play_stop()) {
+            LOGE("mbtk_audio_wav_play_stop() fail.");
+        }
+    }
+
+    if(wav_recorder_fd > 0) {
+        mbtk_audio_wav_recorder_stop();
+    }
+
+    return mbtk_audio_pcm_deinit();
+}
+
