[Audio_test]修复了回调方法的实现

1.修复了回调方法的实现
2.修复了录音功能的bug
3.修改了程序选项

Change-Id: Ib8688ddb0966c2d6c40422fac7d7f82a52ed76c3
diff --git a/mbtk/mbtk_lib/src/mbtk_audio.c b/mbtk/mbtk_lib/src/mbtk_audio.c
index ff58fe9..f026769 100755
--- a/mbtk/mbtk_lib/src/mbtk_audio.c
+++ b/mbtk/mbtk_lib/src/mbtk_audio.c
@@ -59,6 +59,30 @@
     PARAM_INT_POLICY_3,
     PARAM_INT_POLICY_MAX,
 } PARAM_INT_POLICY;
+
+#define FAILURE -1
+#define ID_RIFF 0x46464952
+#define ID_WAVE 0x45564157
+#define ID_FMT  0x20746d66
+#define ID_DATA 0x61746164
+#define FORMAT_PCM 1
+
+struct wav_header {
+	uint32_t riff_id;
+	uint32_t riff_sz;
+	uint32_t riff_fmt;
+	uint32_t fmt_id;
+	uint32_t fmt_sz;
+	uint16_t audio_format;
+	uint16_t num_channels;
+	uint32_t sample_rate;
+	uint32_t byte_rate;       /* sample_rate * num_channels * bps / 8 */
+	uint16_t block_align;     /* num_channels * bps / 8 */
+	uint16_t bits_per_sample;
+	uint32_t data_id;
+	uint32_t data_sz;
+};
+
 const struct blobmsg_policy int_policy[] ={
 	[PARAM_INT_POLICY_0] = {
 		.name = "param0",
@@ -105,6 +129,36 @@
 #define AUDIO_FILE_DIR	"/data"
 #define MBTK_AUD_DEMO_WAV "/data/demo.wav"
 
+int MBTK_wav_pcm16Le_set(int fd)
+{
+    struct wav_header hdr;
+
+    if (fd <= 0)
+        return -1;
+
+    memset(&hdr, 0, sizeof(struct wav_header));
+
+    hdr.riff_id = ID_RIFF;
+    hdr.riff_fmt = ID_WAVE;
+    hdr.fmt_id = ID_FMT;
+    hdr.fmt_sz = 16;
+    hdr.audio_format = FORMAT_PCM;
+    hdr.num_channels = 1;
+    hdr.sample_rate = 8000;
+    hdr.bits_per_sample = 16;
+    hdr.byte_rate = (8000 * 1 * hdr.bits_per_sample) / 8;
+    hdr.block_align = (hdr.bits_per_sample * 1) / 8;
+    hdr.data_id = ID_DATA;
+    hdr.data_sz = 0;
+
+    hdr.riff_sz = hdr.data_sz + 44 - 8;
+    if (write(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
+        return -1;
+    }
+
+    return 0;
+}
+
 int create_audio_dir(const char *dirname)
 {
     DIR *p_dir;
@@ -199,15 +253,25 @@
         goto err;
     }
 
-    if(-1 == mbtk_audio_record(record_hdl, record_cb_func, NULL))
+    if(0 == MBTK_wav_pcm16Le_set(record_fd))// 设置格式,否则音频播放不了
     {
-        printf("file write error\n");
+        if( 0 != mbtk_audio_record(record_hdl, record_cb_func, NULL))
+        {
+            printf("file write error\n");
+            close(record_fd);
+            record_fd = 0;
+        }
+    }
+    else
+    {
+        printf("arec set file header error\n");
         close(record_fd);
         record_fd = 0;
     }
-    sleep(10);
+
+    sleep(10);// 录音 10S
 err:
-    mbtk_audio_close(record_hdl);
+    mbtk_audio_close(record_hdl);// 关闭录音
     record_hdl = NULL;
     if(record_fd > 0)
     {