Support 24bit sample format and up-to 192kHz sample rate
[platform/core/api/audio-io.git] / test / audio_io_test.c
1 /*
2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <unistd.h>
21 #include <math.h>
22 #include <sound_manager.h>
23 #include <audio_io.h>
24
25 #ifndef M_PI
26 #define M_PI  (3.14159265)
27 #endif
28
29 #define TABLE_SIZE   (200)
30 typedef struct {
31         float sine[TABLE_SIZE];
32         int left_channel;
33         int right_channel;
34 } test_wav_t;
35 test_wav_t test_wav;
36
37 static int ch_table[3] = { 0, AUDIO_CHANNEL_MONO, AUDIO_CHANNEL_STEREO };
38
39 static char *state_str[] = { "IDLE", "RUNNING", "PAUSED" };
40
41 static void _audio_in_state_cb(audio_in_h handle, audio_io_state_e previous, audio_io_state_e current, bool by_policy, void *user_data)
42 {
43         printf(">>> _audio_in_state_cb() : handle(%p), previous(%d,%s) => current(%d,%s), by_policy(%d), user_data(%p)\n",
44                         handle, previous, state_str[previous], current, state_str[current], by_policy, user_data);
45 }
46
47 static void _audio_out_state_cb(audio_in_h handle, audio_io_state_e previous, audio_io_state_e current, bool by_policy, void *user_data)
48 {
49         printf(">>> _audio_out_state_cb() : handle(%p), previous(%d,%s) => current(%d,%s), by_policy(%d), user_data(%p)\n",
50                         handle, previous, state_str[previous], current, state_str[current], by_policy, user_data);
51 }
52
53 void play_file(char *file, int length, int num, int ch)
54 {
55         int i = 0;
56         int ret = 0;
57         int total_length = length * num;
58         audio_out_h output;
59         FILE *fp = fopen(file, "r");
60         if (fp == NULL) {
61                 printf("fopen failed\n");
62                 return;
63         }
64
65         char *buf = malloc(total_length);
66         if (buf == NULL) {
67                 printf("malloc failed\n");
68                 fclose(fp);
69                 return;
70         }
71
72         printf("start to play [%s][%d][%d]\n", file, total_length, ch);
73         printf("create\n");
74         audio_out_create_new(44100, ch_table[ch], AUDIO_SAMPLE_TYPE_S16_LE, &output);
75         if (fread(buf, 1, total_length, fp) != length)
76                 printf("error!!!!\n");
77
78         ret = audio_out_set_state_changed_cb(output, _audio_out_state_cb, NULL);
79         if (ret != AUDIO_IO_ERROR_NONE) {
80                 printf("audio_out_set_state_changed_cb failed. \n");
81         }
82
83         printf("prepare\n");
84         audio_out_prepare(output);
85
86         char *pbuf = buf;
87         for (i = 0; i < num; i++) {
88                 printf("### write = (%d/%d) ============== \n", i, num);
89                 audio_out_write(output, pbuf, length);
90                 pbuf += length;
91
92         }
93         printf("unprepare\n");
94         audio_out_drain(output);
95         audio_out_unprepare(output);
96
97         printf("destroy\n");
98         audio_out_destroy(output);
99
100         fclose(fp);
101         free(buf);
102
103         printf("play done\n");
104 }
105
106 #define DUMP_FILE "/root/test.raw"
107
108 void play_file_sample(char *file, int frequency, int ch, int type)
109 {
110         audio_out_h output;
111         int file_size = 0;
112         int read_bytes = 0;
113         int buffer_size = 0;
114         char *buf = NULL;
115
116         if (ch < 0 || ch > 2)
117                 ch = 0;
118
119         FILE *fp = fopen(file, "r");
120         if (fp == NULL) {
121                 printf("open failed\n");
122                 return;
123         }
124         /* Get the size */
125         fseek(fp, 0, SEEK_END);
126         file_size = ftell(fp);
127         fseek(fp, 0, SEEK_SET);
128
129         printf("start to play [%s] of size [%d] with [%d][%d][%d]\n", file, file_size, frequency, ch, type);
130         audio_out_create_new(frequency, ch_table[ch], AUDIO_SAMPLE_TYPE_U8 + type, &output);
131
132         audio_out_prepare(output);
133         audio_out_get_buffer_size(output, &buffer_size);
134
135         buf = (char *)malloc(buffer_size);
136         if (buf == NULL) {
137                 printf("malloc failed\n");
138                 audio_out_unprepare(output);
139                 audio_out_destroy(output);
140                 fclose(fp);
141                 return;
142         }
143
144         getchar();
145
146         while (file_size > 0) {
147                 read_bytes = fread(buf, 1, buffer_size, fp);
148                 printf("Read %d Requested - %d\n", read_bytes, buffer_size);
149                 audio_out_write(output, buf, read_bytes);
150                 file_size = file_size - read_bytes;
151         }
152
153         audio_out_unprepare(output);
154         audio_out_destroy(output);
155
156         free(buf);
157         fclose(fp);
158         printf("play done\n");
159 }
160
161 int audio_io_test(int length, int num, int ch)
162 {
163         int ret, size, i;
164         audio_in_h input;
165         if ((ret = audio_in_create(44100, ch_table[ch], AUDIO_SAMPLE_TYPE_S16_LE, &input)) == AUDIO_IO_ERROR_NONE) {
166                 ret = audio_in_set_state_changed_cb(input, _audio_in_state_cb, NULL);
167                 if (ret != AUDIO_IO_ERROR_NONE) {
168                         printf("audio_in_set_state_changed_cb failed. \n");
169                         goto error;
170                 }
171
172                 ret = audio_in_prepare(input);
173                 if (ret != 0) {
174                         printf("ERROR, prepare\n");
175                         goto error;
176                 }
177
178                 FILE *fp = fopen(DUMP_FILE, "wb+");
179                 if (fp == NULL) {
180                         printf("ERROR, file open failed\n");
181                         goto error;
182                 }
183
184                 if ((ret = audio_in_get_buffer_size(input, &size)) == AUDIO_IO_ERROR_NONE) {
185                         size = length;
186                         char *buffer = alloca(size);
187
188                         for (i = 0; i < num; i++) {
189                                 printf("### read = (%d/%d) ============== ", i, num);
190                                 if ((ret = audio_in_read(input, (void *)buffer, size)) > AUDIO_IO_ERROR_NONE) {
191                                         fwrite(buffer, size, sizeof(char), fp);
192                                         printf("PASS, size=%d, ret=0x%x\n", size, ret);
193                                 } else {
194                                         printf("FAIL, size=%d, ret=0x%x\n", size, ret);
195                                 }
196                         }
197                 }
198
199                 fclose(fp);
200
201                 audio_in_unprepare(input);
202                 audio_in_destroy(input);
203         }
204
205         play_file(DUMP_FILE, length, num, ch);
206
207         return 0;
208 error:
209         audio_in_destroy(input);
210         return -1;
211 }
212
213 int audio_io_loopback_in_test()
214 {
215         int ret, size;
216         audio_in_h input;
217         FILE *fp = fopen("/tmp/dump_test.raw", "wb+");
218
219         if (fp == NULL) {
220                 printf("open failed \n");
221                 return -1;
222         }
223
224         if ((ret = audio_in_create(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &input)) == AUDIO_IO_ERROR_NONE) {
225                 ret = audio_in_prepare(input);
226                 if (ret != 0) {
227                         printf("ERROR, prepare\n");
228                         goto exit;
229                 }
230
231                 ret = audio_in_get_buffer_size(input, &size);
232                 if (ret != AUDIO_IO_ERROR_NONE) {
233                         printf("audio_in_get_buffer_size failed.\n");
234                         goto exit;
235                 }
236
237                 char *buffer = alloca(size);
238
239                 while (1) {
240                         if ((ret = audio_in_read(input, (void *)buffer, size)) > AUDIO_IO_ERROR_NONE) {
241                                 fwrite(buffer, size, sizeof(char), fp);
242                                 printf("PASS, size=%d, ret=0x%x\n", size, ret);
243                         } else {
244                                 printf("FAIL, size=%d, ret=0x%x\n", size, ret);
245                         }
246                 }
247         }
248
249  exit:
250         audio_in_destroy(input);
251
252         fclose(fp);
253
254         return ret;
255
256 }
257
258 int audio_io_loopback_test()
259 {
260         int ret, size;
261         audio_in_h input = NULL;
262         audio_out_h output = NULL;
263         char *buffer = NULL;
264
265         ret = audio_in_create(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &input);
266         if (ret != AUDIO_IO_ERROR_NONE) {
267                 printf("audio_in_create_ex failed. \n");
268                 return ret;
269         }
270         ret = audio_out_create_new(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &output);
271         if (ret != AUDIO_IO_ERROR_NONE) {
272                 printf("audio_out_create_new failed. \n");
273                 goto exit;
274         }
275
276         ret = audio_in_prepare(input);
277         if (ret != 0) {
278                 printf("audio_in_prepare failed, err(0x%x)\n", ret);
279                 goto exit;
280         } else {
281                 ret = audio_in_get_buffer_size(input, &size);
282                 if (ret != AUDIO_IO_ERROR_NONE) {
283                         printf("audio_in_get_buffer_size failed, err(0x%x)\n", ret);
284                         goto exit;
285                 } else {
286                         printf("size(%d)\n", size);
287                         buffer = alloca(size);
288                 }
289         }
290
291         ret = audio_out_prepare(output);
292         if (ret != 0) {
293                 printf("audio_out_prepare failed, err(0x%x)\n", ret);
294                 goto exit;
295         }
296
297         if (buffer == NULL) {
298                 printf("buffer is null\n");
299                 ret = -1;
300                 goto exit;
301         }
302
303         while (1) {
304                 ret = audio_in_read(input, (void *)buffer, size);
305                 if (ret > AUDIO_IO_ERROR_NONE) {
306                         ret = audio_out_write(output, buffer, size);
307                         if (ret > AUDIO_IO_ERROR_NONE)
308                                 printf("audio read/write success. buffer(%p), size(%d)\n", buffer, size);
309                         else
310                                 printf("audio read success, write failed. buffer(%p), size(%d)\n", buffer, size);
311                 } else
312                         printf("audio read/write failed. buffer(%p), size(%d)\n", buffer, size);
313         }
314
315 exit:
316         if (input)
317                 audio_in_destroy(input);
318         if (output)
319                 audio_out_destroy(output);
320
321         return ret;
322
323 }
324
325 audio_in_h input;
326 audio_out_h output;
327
328 FILE *fp_w = NULL;
329
330 sound_stream_info_h g_stream_info_read_h = NULL;
331 sound_stream_info_h g_stream_info_write_h = NULL;
332
333 static void focus_callback(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state,
334                                 sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *additional_info, void *user_data)
335 {
336         printf("*** focus_callback_read is called, stream_info(%p, read(%p)/write(%p)) ***\n", stream_info, g_stream_info_read_h, g_stream_info_write_h);
337         printf(" - reason_for_change(%d), additional_info(%s), user_data(%p)\n", reason_for_change, additional_info, user_data);
338         printf(" - focus_state is :%d \n", focus_state);
339
340         return;
341 }
342
343 static void _audio_io_stream_read_cb(audio_in_h handle, size_t nbytes, void *user_data)
344 {
345         const void *buffer = NULL;
346         unsigned int len = (unsigned int)nbytes;
347
348         if (len > 0) {
349                 audio_in_peek(handle, &buffer, &len);
350                 if (fp_w)
351                         fwrite(buffer, sizeof(char), len, fp_w);
352                 audio_in_drop(handle);
353         }
354 }
355
356 static void _audio_io_stream_write_cb(audio_out_h handle, size_t nbytes, void *user_data)
357 {
358         short *buffer = NULL;
359         int i = 0;
360
361         if (nbytes > 0) {
362                 buffer = (short *)malloc(nbytes);
363                 if (buffer == NULL) {
364                         printf("malloc failed\n");
365                         return;
366                 }
367                 memset(buffer, 0, nbytes);
368
369                 for (i = 0; i < nbytes / 2; i += 2) {
370                         buffer[i] = (short)32768 *test_wav.sine[test_wav.left_channel]; /* left */
371                         buffer[i + 1] = (short)32768 *test_wav.sine[test_wav.right_channel];    /* right */
372                         test_wav.left_channel += 1;
373                         if (test_wav.left_channel >= TABLE_SIZE)
374                                 test_wav.left_channel -= TABLE_SIZE;
375                         test_wav.right_channel += 3;
376                         if (test_wav.right_channel >= TABLE_SIZE)
377                                 test_wav.right_channel -= TABLE_SIZE;
378                 }
379
380                 audio_out_write(handle, buffer, nbytes);
381
382                 free(buffer);
383         }
384 }
385
386 int _convert_cmd_and_run(char cmd, int mode)
387 {
388         int ret = 0;
389         switch (cmd) {
390         case 'P':
391                 if (mode & 0x01)
392                         ret = audio_out_prepare(output);
393                 if (mode & 0x02)
394                         ret = audio_in_prepare(input);
395                 break;
396         case 'u':
397                 if (mode & 0x01)
398                         ret = audio_out_unprepare(output);
399                 if (mode & 0x02)
400                         ret = audio_in_unprepare(input);
401                 break;
402         case 'p':
403                 if (mode & 0x01)
404                         ret = audio_out_pause(output);
405                 if (mode & 0x02)
406                         ret = audio_in_pause(input);
407                 break;
408         case 'r':
409                 if (mode & 0x01)
410                         ret = audio_out_resume(output);
411                 if (mode & 0x02)
412                         ret = audio_in_resume(input);
413                 break;
414         case 'd':
415                 if (mode & 0x01)
416                         ret = audio_out_drain(output);
417                 break;
418         case 'f':
419                 if (mode & 0x01)
420                         ret = audio_out_flush(output);
421                 if (mode & 0x02)
422                         ret = audio_in_flush(input);
423                 break;
424         case 'i':
425                 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_write_h);
426                 if (ret)
427                         printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
428                 break;
429         case 'q':                                       /* quit */
430                 ret = 1;
431                 break;
432         default:
433                 ret = 1;
434                 break;
435         }
436         return ret;
437 }
438
439 int audio_io_async_test(int mode)
440 {
441         int ret, size;
442         char *buffer = NULL;
443         int i = 0;
444
445         char cmd = 0;
446         int cmd_ret;
447
448         int write_mode = (mode & 0x01);
449         int read_mode = (mode & 0x02);
450
451         sound_stream_focus_state_e playback_focus_state;
452         sound_stream_focus_state_e recording_focus_state;
453
454         if ((write_mode == 0) && (read_mode == 0)) {
455                 printf("not vaild mode.\n");
456                 return 0;
457         }
458
459         if (read_mode) {
460
461                 printf("audio_in_create\n");
462                 ret = audio_in_create(44100, AUDIO_CHANNEL_STEREO, AUDIO_SAMPLE_TYPE_S16_LE, &input);
463                 if (ret != AUDIO_IO_ERROR_NONE) {
464                         printf("audio_in_create_ex failed. \n");
465                         return 0;
466                 }
467                 printf("audio_in_create success!!! [%p]\n", input);
468
469                 ret = audio_in_set_stream_cb(input, _audio_io_stream_read_cb, NULL);
470                 if (ret != AUDIO_IO_ERROR_NONE) {
471                         printf("audio_in_set_stream_cb failed. \n");
472                         goto EXIT;
473                 }
474                 printf("audio_in_set_stream_cb success!!! [%p]\n", input);
475
476                 ret = audio_in_set_state_changed_cb(input, _audio_in_state_cb, NULL);
477                 if (ret != AUDIO_IO_ERROR_NONE) {
478                         printf("audio_out_set_state_changed_cb failed. \n");
479                         goto EXIT;
480                 }
481                 printf("audio_out_set_state_changed_cb success!!! [%p]\n", input);
482
483                 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_read_h);
484                 if (ret) {
485                         printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
486                         goto EXIT;
487                 }
488                 ret = audio_in_set_sound_stream_info(input, g_stream_info_read_h);
489                 if (ret)
490                         printf("fail to audio_in_set_sound_stream_info(), ret(0x%x)\n", ret);
491
492                 ret = sound_manager_acquire_focus(g_stream_info_read_h, SOUND_STREAM_FOCUS_FOR_RECORDING, SOUND_BEHAVIOR_NONE, NULL);
493                 if (ret) {
494                         printf("fail to sound_manager_acquire_focus() for RECORDING, ret(0x%x)\n", ret);
495                         goto EXIT;
496                 }
497
498                 fp_w = fopen("/tmp/pcm_w.raw", "w");
499         }
500
501         if (write_mode) {
502                 printf("before audio_out_create_new\n");
503                 getchar();
504
505                 printf("audio_out_create_new\n");
506                 ret = audio_out_create_new(44100, AUDIO_CHANNEL_STEREO, AUDIO_SAMPLE_TYPE_S16_LE, &output);
507                 if (ret != AUDIO_IO_ERROR_NONE) {
508                         printf("audio_out_create_new failed. \n");
509                         goto EXIT;
510                 }
511                 printf("audio_out_create_new success!!! [%p]\n", output);
512
513                 ret = audio_out_set_stream_cb(output, _audio_io_stream_write_cb, NULL);
514                 if (ret != AUDIO_IO_ERROR_NONE) {
515                         printf("audio_out_set_stream_cb failed. \n");
516                         goto EXIT;
517                 }
518                 printf("audio_out_set_stream_cb success!!! [%p]\n", output);
519
520                 ret = audio_out_set_state_changed_cb(output, _audio_out_state_cb, NULL);
521                 if (ret != AUDIO_IO_ERROR_NONE) {
522                         printf("audio_out_set_state_changed_cb failed. \n");
523                         goto EXIT;
524                 }
525                 printf("audio_out_set_state_changed_cb success!!! [%p]\n", output);
526
527                 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_write_h);
528                 if (ret) {
529                         printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
530                         goto EXIT;
531                 }
532
533                 ret = audio_out_set_sound_stream_info(output, g_stream_info_write_h);
534                 if (ret)
535                         printf("fail to audio_out_set_sound_stream_info(), ret(0x%x)\n", ret);
536
537                 ret = sound_manager_acquire_focus(g_stream_info_write_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
538                 if (ret) {
539                         printf("fail to sound_manager_acquire_focus() for PLAYBACK, ret(0x%x)\n", ret);
540                         goto EXIT;
541                 }
542
543                 /* generate wave data */
544                 for (i = 0; i < TABLE_SIZE; i++)
545                         test_wav.sine[i] = 0.9 * (float)sin(((double)i / (double)TABLE_SIZE) * M_PI * 2.);
546                 test_wav.left_channel = test_wav.right_channel = 0;
547         }
548
549         if (read_mode) {
550                 printf("before audio_in_prepare\n");
551                 getchar();
552                 printf("audio_in_prepare\n");
553                 ret = audio_in_prepare(input);
554                 if (ret != 0) {
555                         printf("audio_in_prepare failed, err(0x%x)\n", ret);
556                         audio_in_destroy(input);
557                         goto EXIT;
558                 } else {
559                         ret = audio_in_get_buffer_size(input, &size);
560                         if (ret != AUDIO_IO_ERROR_NONE) {
561                                 printf("audio_in_get_buffer_size failed, err(0x%x)\n", ret);
562                                 goto EXIT;
563                         } else {
564                                 printf("size(%d)\n", size);
565                                 buffer = alloca(size);
566                         }
567                 }
568
569                 if (buffer == NULL) {
570                         printf("buffer is null\n");
571                         goto EXIT;
572                 }
573         }
574
575         if (write_mode) {
576                 printf("before audio_out_prepare\n");
577                 getchar();
578                 printf("audio_out_prepare\n");
579                 ret = audio_out_prepare(output);
580                 if (ret != 0) {
581                         printf("audio_out_prepare failed, err(0x%x)\n", ret);
582                         audio_out_destroy(output);
583                         goto EXIT;
584                 }
585         }
586
587         do {
588                 printf("command(q:quit) : ");
589                 ret = getchar();
590                 if (ret == EOF)
591                         goto EXIT;
592                 cmd = (char)ret;
593                 if (cmd != '\n')
594                         getchar();
595                 cmd_ret = _convert_cmd_and_run(cmd, mode);
596                 printf("  - result code : %d\n", cmd_ret);
597         } while (cmd != 'q');
598
599 EXIT:
600         if (read_mode) {
601                 if (input) {
602                         printf("audio_in_unprepare\n");
603                         audio_in_unprepare(input);
604                         printf("audio_in_destroy\n");
605                         audio_in_destroy(input);
606                         input = NULL;
607                 }
608
609                 if (fp_w) {
610                         fclose(fp_w);
611                         fp_w = NULL;
612                 }
613
614                 if (g_stream_info_read_h) {
615                         ret = sound_manager_get_focus_state(g_stream_info_read_h, NULL, &recording_focus_state);
616                         if (recording_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
617                                 ret = sound_manager_release_focus(g_stream_info_read_h, SOUND_STREAM_FOCUS_FOR_RECORDING, SOUND_BEHAVIOR_NONE, NULL);
618                                 if (ret)
619                                         printf("fail to sound_manager_release_focus() for recording, ret(0x%x)\n", ret);
620                         }
621                         ret = sound_manager_destroy_stream_information(g_stream_info_read_h);
622                         if (ret)
623                                 printf("fail to sound_manager_destroy_stream_information(), ret(0x%x)\n", ret);
624                         g_stream_info_read_h = NULL;
625                 }
626         }
627
628         if (write_mode) {
629                 if (output) {
630                         printf("audio_out_unprepare\n");
631                         audio_out_unprepare(output);
632                         printf("audio_out_destroy\n");
633                         audio_out_destroy(output);
634                 }
635
636                 if (g_stream_info_write_h) {
637                         ret = sound_manager_get_focus_state(g_stream_info_write_h, &playback_focus_state, NULL);
638                         if (playback_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
639                                 ret = sound_manager_release_focus(g_stream_info_write_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
640                                 if (ret)
641                                         printf("fail to sound_manager_release_focus() for playback, ret(0x%x)\n", ret);
642                         }
643                         ret = sound_manager_destroy_stream_information(g_stream_info_write_h);
644                         if (ret)
645                                 printf("fail to sound_manager_destroy_stream_information(), ret(0x%x)\n", ret);
646                         g_stream_info_write_h = NULL;
647                 }
648         }
649
650         return 0;
651 }
652
653 int main(int argc, char **argv)
654 {
655         if (argc == 2 && !strcmp(argv[1], "call-forwarding-loop")) {
656                 audio_io_loopback_test();
657         } else if (argc == 2 && !strcmp(argv[1], "call-forwarding-in")) {
658                 audio_io_loopback_in_test();
659         } else if (argc == 3 && !strcmp(argv[1], "async")) {
660                 audio_io_async_test(atoi(argv[2]));
661         } else if (argc == 4) {
662                 int channel_idx = atoi(argv[3]);
663                 if (channel_idx < 0 || channel_idx > 2) {
664                         printf("Invalid channel\n");
665                         return 0;
666                 }
667                 printf("run with [%s][%s][%s]\n", argv[1], argv[2], argv[3]);
668                 audio_io_test(atoi(argv[1]), atoi(argv[2]), channel_idx);
669         } else if (argc == 6) {
670                 play_file_sample(argv[2], atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
671         } else {
672                 printf("1. usage : audio_io_test call-forwarding-loop\n");
673                 printf("2. usage : audio_io_test call-forwarding-in\n");
674                 printf("3. usage : audio_io_test [length to read] [number of iteration] [channels]\n");
675                 printf("4. usage : audio_io_test async [write(1) | read(2)]\n");
676                 printf("5. Uasge : audio_io_test play [filename] [sample rate] [channels] [type(0:U8,1:S16LE,2:S24LE,3:S24_32LE)]\n");
677         }
678         return 0;
679 }