Merge branch 'tizen_3.0' into tizen
[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         if (type)
131                 audio_out_create_new(frequency, ch_table[ch], AUDIO_SAMPLE_TYPE_S16_LE, &output);
132         else
133                 audio_out_create_new(frequency, ch_table[ch], AUDIO_SAMPLE_TYPE_U8, &output);
134
135         audio_out_prepare(output);
136         audio_out_get_buffer_size(output, &buffer_size);
137
138         buf = (char *)malloc(buffer_size);
139         if (buf == NULL) {
140                 printf("malloc failed\n");
141                 audio_out_unprepare(output);
142                 audio_out_destroy(output);
143                 fclose(fp);
144                 return;
145         }
146
147         getchar();
148
149         while (file_size > 0) {
150                 read_bytes = fread(buf, 1, buffer_size, fp);
151                 printf("Read %d Requested - %d\n", read_bytes, buffer_size);
152                 audio_out_write(output, buf, read_bytes);
153                 file_size = file_size - read_bytes;
154         }
155
156         audio_out_unprepare(output);
157         audio_out_destroy(output);
158
159         free(buf);
160         fclose(fp);
161         printf("play done\n");
162 }
163
164 int audio_io_test(int length, int num, int ch)
165 {
166         int ret, size, i;
167         audio_in_h input;
168         if ((ret = audio_in_create(44100, ch_table[ch], AUDIO_SAMPLE_TYPE_S16_LE, &input)) == AUDIO_IO_ERROR_NONE) {
169                 ret = audio_in_set_state_changed_cb(input, _audio_in_state_cb, NULL);
170                 if (ret != AUDIO_IO_ERROR_NONE) {
171                         printf("audio_in_set_state_changed_cb failed. \n");
172                         goto error;
173                 }
174
175                 ret = audio_in_prepare(input);
176                 if (ret != 0) {
177                         printf("ERROR, prepare\n");
178                         goto error;
179                 }
180
181                 FILE *fp = fopen(DUMP_FILE, "wb+");
182                 if (fp == NULL) {
183                         printf("ERROR, file open failed\n");
184                         goto error;
185                 }
186
187                 if ((ret = audio_in_get_buffer_size(input, &size)) == AUDIO_IO_ERROR_NONE) {
188                         size = length;
189                         char *buffer = alloca(size);
190
191                         for (i = 0; i < num; i++) {
192                                 printf("### read = (%d/%d) ============== ", i, num);
193                                 if ((ret = audio_in_read(input, (void *)buffer, size)) > AUDIO_IO_ERROR_NONE) {
194                                         fwrite(buffer, size, sizeof(char), fp);
195                                         printf("PASS, size=%d, ret=0x%x\n", size, ret);
196                                 } else {
197                                         printf("FAIL, size=%d, ret=0x%x\n", size, ret);
198                                 }
199                         }
200                 }
201
202                 fclose(fp);
203
204                 audio_in_unprepare(input);
205                 audio_in_destroy(input);
206         }
207
208         play_file(DUMP_FILE, length, num, ch);
209
210         return 0;
211 error:
212         audio_in_destroy(input);
213         return -1;
214 }
215
216 int audio_io_loopback_in_test()
217 {
218         int ret, size;
219         audio_in_h input;
220         FILE *fp = fopen("/tmp/dump_test.raw", "wb+");
221
222         if (fp == NULL) {
223                 printf("open failed \n");
224                 return -1;
225         }
226
227         if ((ret = audio_in_create(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &input)) == AUDIO_IO_ERROR_NONE) {
228                 ret = audio_in_ignore_session(input);
229                 if (ret != 0) {
230                         printf("ERROR, set session mix\n");
231                         goto exit;
232                 }
233
234                 ret = audio_in_prepare(input);
235                 if (ret != 0) {
236                         printf("ERROR, prepare\n");
237                         goto exit;
238                 }
239
240                 ret = audio_in_get_buffer_size(input, &size);
241                 if (ret != AUDIO_IO_ERROR_NONE) {
242                         printf("audio_in_get_buffer_size failed.\n");
243                         goto exit;
244                 }
245
246                 while (1) {
247                         char *buffer = alloca(size);
248                         if ((ret = audio_in_read(input, (void *)buffer, size)) > AUDIO_IO_ERROR_NONE) {
249                                 fwrite(buffer, size, sizeof(char), fp);
250                                 printf("PASS, size=%d, ret=0x%x\n", size, ret);
251                         } else {
252                                 printf("FAIL, size=%d, ret=0x%x\n", size, ret);
253                         }
254                 }
255         }
256
257  exit:
258         audio_in_destroy(input);
259
260         fclose(fp);
261
262         return ret;
263
264 }
265
266 int audio_io_loopback_test()
267 {
268         int ret, size;
269         audio_in_h input;
270         audio_out_h output;
271         char *buffer = NULL;
272
273         ret = audio_in_create(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &input);
274         if (ret != AUDIO_IO_ERROR_NONE) {
275                 printf("audio_in_create_ex failed. \n");
276                 return ret;
277         }
278         ret = audio_out_create_new(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &output);
279         if (ret != AUDIO_IO_ERROR_NONE) {
280                 printf("audio_out_create failed. \n");
281                 return ret;
282         }
283
284         ret = audio_in_prepare(input);
285         if (ret != 0) {
286                 printf("audio_in_prepare failed, err(0x%x)\n", ret);
287                 audio_in_destroy(input);
288                 return ret;
289         } else {
290                 ret = audio_in_get_buffer_size(input, &size);
291                 if (ret != AUDIO_IO_ERROR_NONE) {
292                         printf("audio_in_get_buffer_size failed, err(0x%x)\n", ret);
293                         return 0;
294                 } else {
295                         printf("size(%d)\n", size);
296                         buffer = alloca(size);
297                 }
298         }
299
300         ret = audio_out_prepare(output);
301         if (ret != 0) {
302                 printf("audio_out_prepare failed, err(0x%x)\n", ret);
303                 audio_out_destroy(output);
304                 return ret;
305         }
306
307         if (buffer == NULL) {
308                 printf("buffer is null\n");
309                 return -1;
310         }
311
312         while (1) {
313                 ret = audio_in_read(input, (void *)buffer, size);
314                 if (ret > AUDIO_IO_ERROR_NONE) {
315                         ret = audio_out_write(output, buffer, size);
316                         if (ret > AUDIO_IO_ERROR_NONE)
317                                 printf("audio read/write success. buffer(%p), size(%d)\n", buffer, size);
318                         else
319                                 printf("audio read success, write failed. buffer(%p), size(%d)\n", buffer, size);
320                 } else
321                         printf("audio read/write failed. buffer(%p), size(%d)\n", buffer, size);
322         }
323
324 }
325
326 audio_in_h input;
327 audio_out_h output;
328
329 FILE *fp_w = NULL;
330
331 sound_stream_info_h g_stream_info_read_h = NULL;
332 sound_stream_info_h g_stream_info_write_h = NULL;
333
334 static void focus_callback(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state,
335                                 sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *additional_info, void *user_data)
336 {
337         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);
338         printf(" - reason_for_change(%d), additional_info(%s), user_data(%p)\n", reason_for_change, additional_info, user_data);
339         printf(" - focus_state is :%d \n", focus_state);
340
341         return;
342 }
343
344 static void _audio_io_stream_read_cb(audio_in_h handle, size_t nbytes, void *user_data)
345 {
346         const void *buffer = NULL;
347         unsigned int len = (unsigned int)nbytes;
348
349         if (len > 0) {
350                 audio_in_peek(handle, &buffer, &len);
351                 if (fp_w)
352                         fwrite(buffer, sizeof(char), len, fp_w);
353                 audio_in_drop(handle);
354         }
355 }
356
357 static void _audio_io_stream_write_cb(audio_out_h handle, size_t nbytes, void *user_data)
358 {
359         short *buffer = NULL;
360         int i = 0;
361
362         if (nbytes > 0) {
363                 buffer = (short *)malloc(nbytes);
364                 if (buffer == NULL) {
365                         printf("malloc failed\n");
366                         return;
367                 }
368                 memset(buffer, 0, nbytes);
369
370                 for (i = 0; i < nbytes / 2; i += 2) {
371                         buffer[i] = (short)32768 *test_wav.sine[test_wav.left_channel]; /* left */
372                         buffer[i + 1] = (short)32768 *test_wav.sine[test_wav.right_channel];    /* right */
373                         test_wav.left_channel += 1;
374                         if (test_wav.left_channel >= TABLE_SIZE)
375                                 test_wav.left_channel -= TABLE_SIZE;
376                         test_wav.right_channel += 3;
377                         if (test_wav.right_channel >= TABLE_SIZE)
378                                 test_wav.right_channel -= TABLE_SIZE;
379                 }
380
381                 audio_out_write(handle, buffer, nbytes);
382
383                 free(buffer);
384         }
385 }
386
387 int _convert_cmd_and_run(char cmd, int mode)
388 {
389         int ret = 0;
390         switch (cmd) {
391         case 'P':
392                 if (mode & 0x01)
393                         ret = audio_out_prepare(output);
394                 if (mode & 0x02)
395                         ret = audio_in_prepare(input);
396                 break;
397         case 'u':
398                 if (mode & 0x01)
399                         ret = audio_out_unprepare(output);
400                 if (mode & 0x02)
401                         ret = audio_in_unprepare(input);
402                 break;
403         case 'p':
404                 if (mode & 0x01)
405                         ret = audio_out_pause(output);
406                 if (mode & 0x02)
407                         ret = audio_in_pause(input);
408                 break;
409         case 'r':
410                 if (mode & 0x01)
411                         ret = audio_out_resume(output);
412                 if (mode & 0x02)
413                         ret = audio_in_resume(input);
414                 break;
415         case 'd':
416                 if (mode & 0x01)
417                         ret = audio_out_drain(output);
418                 break;
419         case 'f':
420                 if (mode & 0x01)
421                         ret = audio_out_flush(output);
422                 if (mode & 0x02)
423                         ret = audio_in_flush(input);
424                 break;
425         case 'i':
426                 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_write_h);
427                 if (ret)
428                         printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
429                 break;
430         case 'q':                                       /* quit */
431                 ret = 1;
432                 break;
433         default:
434                 ret = 1;
435                 break;
436         }
437         return ret;
438 }
439
440 int audio_io_async_test(int mode)
441 {
442         int ret, size;
443         char *buffer = NULL;
444         int i = 0;
445
446         char cmd = 0;
447         int cmd_ret;
448
449         int write_mode = (mode & 0x01);
450         int read_mode = (mode & 0x02);
451
452         sound_stream_focus_state_e playback_focus_state;
453         sound_stream_focus_state_e recording_focus_state;
454
455         if ((write_mode == 0) && (read_mode == 0)) {
456                 printf("not vaild mode.\n");
457                 return 0;
458         }
459
460         if (read_mode) {
461
462                 printf("audio_in_create\n");
463                 ret = audio_in_create(44100, AUDIO_CHANNEL_STEREO, AUDIO_SAMPLE_TYPE_S16_LE, &input);
464                 if (ret != AUDIO_IO_ERROR_NONE) {
465                         printf("audio_in_create_ex failed. \n");
466                         return 0;
467                 }
468                 printf("audio_in_create success!!! [%p]\n", input);
469
470                 ret = audio_in_set_stream_cb(input, _audio_io_stream_read_cb, NULL);
471                 if (ret != AUDIO_IO_ERROR_NONE) {
472                         printf("audio_in_set_stream_cb failed. \n");
473                         goto EXIT;
474                 }
475                 printf("audio_in_set_stream_cb success!!! [%p]\n", input);
476
477                 ret = audio_in_set_state_changed_cb(input, _audio_in_state_cb, NULL);
478                 if (ret != AUDIO_IO_ERROR_NONE) {
479                         printf("audio_out_set_state_changed_cb failed. \n");
480                         goto EXIT;
481                 }
482                 printf("audio_out_set_state_changed_cb success!!! [%p]\n", input);
483
484                 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_read_h);
485                 if (ret) {
486                         printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
487                         goto EXIT;
488                 }
489                 ret = audio_in_set_sound_stream_info(input, g_stream_info_read_h);
490                 if (ret)
491                         printf("fail to audio_in_set_sound_stream_info(), ret(0x%x)\n", ret);
492
493                 ret = sound_manager_acquire_focus(g_stream_info_read_h, SOUND_STREAM_FOCUS_FOR_RECORDING, SOUND_BEHAVIOR_NONE, NULL);
494                 if (ret) {
495                         printf("fail to sound_manager_acquire_focus() for RECORDING, ret(0x%x)\n", ret);
496                         goto EXIT;
497                 }
498
499                 fp_w = fopen("/tmp/pcm_w.raw", "w");
500         }
501
502         if (write_mode) {
503                 printf("before audio_out_create\n");
504                 getchar();
505
506                 printf("audio_out_create\n");
507                 ret = audio_out_create_new(44100, AUDIO_CHANNEL_STEREO, AUDIO_SAMPLE_TYPE_S16_LE, &output);
508                 if (ret != AUDIO_IO_ERROR_NONE) {
509                         printf("audio_out_create failed. \n");
510                         goto EXIT;
511                 }
512                 printf("audio_out_create success!!! [%p]\n", output);
513
514                 ret = audio_out_set_stream_cb(output, _audio_io_stream_write_cb, NULL);
515                 if (ret != AUDIO_IO_ERROR_NONE) {
516                         printf("audio_out_set_stream_cb failed. \n");
517                         goto EXIT;
518                 }
519                 printf("audio_out_set_stream_cb success!!! [%p]\n", output);
520
521                 ret = audio_out_set_state_changed_cb(output, _audio_out_state_cb, NULL);
522                 if (ret != AUDIO_IO_ERROR_NONE) {
523                         printf("audio_out_set_state_changed_cb failed. \n");
524                         goto EXIT;
525                 }
526                 printf("audio_out_set_state_changed_cb success!!! [%p]\n", output);
527
528                 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_write_h);
529                 if (ret) {
530                         printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
531                         goto EXIT;
532                 }
533
534                 ret = audio_out_set_sound_stream_info(output, g_stream_info_write_h);
535                 if (ret)
536                         printf("fail to audio_out_set_sound_stream_info(), ret(0x%x)\n", ret);
537
538                 ret = sound_manager_acquire_focus(g_stream_info_write_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
539                 if (ret) {
540                         printf("fail to sound_manager_acquire_focus() for PLAYBACK, ret(0x%x)\n", ret);
541                         goto EXIT;
542                 }
543
544                 /* generate wave data */
545                 for (i = 0; i < TABLE_SIZE; i++)
546                         test_wav.sine[i] = 0.9 * (float)sin(((double)i / (double)TABLE_SIZE) * M_PI * 2.);
547                 test_wav.left_channel = test_wav.right_channel = 0;
548         }
549
550         if (read_mode) {
551                 printf("before audio_in_prepare\n");
552                 getchar();
553                 printf("audio_in_prepare\n");
554                 ret = audio_in_prepare(input);
555                 if (ret != 0) {
556                         printf("audio_in_prepare failed, err(0x%x)\n", ret);
557                         audio_in_destroy(input);
558                         goto EXIT;
559                 } else {
560                         ret = audio_in_get_buffer_size(input, &size);
561                         if (ret != AUDIO_IO_ERROR_NONE) {
562                                 printf("audio_in_get_buffer_size failed, err(0x%x)\n", ret);
563                                 goto EXIT;
564                         } else {
565                                 printf("size(%d)\n", size);
566                                 buffer = alloca(size);
567                         }
568                 }
569
570                 if (buffer == NULL) {
571                         printf("buffer is null\n");
572                         goto EXIT;
573                 }
574         }
575
576         if (write_mode) {
577                 printf("before audio_out_prepare\n");
578                 getchar();
579                 printf("audio_out_prepare\n");
580                 ret = audio_out_prepare(output);
581                 if (ret != 0) {
582                         printf("audio_out_prepare failed, err(0x%x)\n", ret);
583                         audio_out_destroy(output);
584                         goto EXIT;
585                 }
586         }
587
588         do {
589                 printf("command(q:quit) : ");
590                 ret = getchar();
591                 if (ret == EOF)
592                         goto EXIT;
593                 cmd = (char)ret;
594                 if (cmd != '\n')
595                         getchar();
596                 cmd_ret = _convert_cmd_and_run(cmd, mode);
597                 printf("  - result code : %d\n", cmd_ret);
598         } while (cmd != 'q');
599
600 EXIT:
601         if (read_mode) {
602                 if (input) {
603                         printf("audio_in_unprepare\n");
604                         audio_in_unprepare(input);
605                         printf("audio_in_destroy\n");
606                         audio_in_destroy(input);
607                         input = NULL;
608                 }
609
610                 if (fp_w) {
611                         fclose(fp_w);
612                         fp_w = NULL;
613                 }
614
615                 if (g_stream_info_read_h) {
616                         ret = sound_manager_get_focus_state(g_stream_info_read_h, NULL, &recording_focus_state);
617                         if (recording_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
618                                 ret = sound_manager_release_focus(g_stream_info_read_h, SOUND_STREAM_FOCUS_FOR_RECORDING, SOUND_BEHAVIOR_NONE, NULL);
619                                 if (ret)
620                                         printf("fail to sound_manager_release_focus() for recording, ret(0x%x)\n", ret);
621                         }
622                         ret = sound_manager_destroy_stream_information(g_stream_info_read_h);
623                         if (ret)
624                                 printf("fail to sound_manager_destroy_stream_information(), ret(0x%x)\n", ret);
625                         g_stream_info_read_h = NULL;
626                 }
627         }
628
629         if (write_mode) {
630                 if (output) {
631                         printf("audio_out_unprepare\n");
632                         audio_out_unprepare(output);
633                         printf("audio_out_destroy\n");
634                         audio_out_destroy(output);
635                 }
636
637                 if (g_stream_info_write_h) {
638                         ret = sound_manager_get_focus_state(g_stream_info_write_h, &playback_focus_state, NULL);
639                         if (playback_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
640                                 ret = sound_manager_release_focus(g_stream_info_write_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
641                                 if (ret)
642                                         printf("fail to sound_manager_release_focus() for playback, ret(0x%x)\n", ret);
643                         }
644                         ret = sound_manager_destroy_stream_information(g_stream_info_write_h);
645                         if (ret)
646                                 printf("fail to sound_manager_destroy_stream_information(), ret(0x%x)\n", ret);
647                         g_stream_info_write_h = NULL;
648                 }
649         }
650
651         return 0;
652 }
653
654 int main(int argc, char **argv)
655 {
656         if (argc == 2 && !strcmp(argv[1], "call-forwarding-loop")) {
657                 audio_io_loopback_test();
658         } else if (argc == 2 && !strcmp(argv[1], "call-forwarding-in")) {
659                 audio_io_loopback_in_test();
660         } else if (argc == 3 && !strcmp(argv[1], "async")) {
661                 audio_io_async_test(atoi(argv[2]));
662         } else if (argc == 4) {
663                 int channel_idx = atoi(argv[3]);
664                 if (channel_idx < 0 || channel_idx > 2) {
665                         printf("Invalid channel\n");
666                         return 0;
667                 }
668                 printf("run with [%s][%s][%s]\n", argv[1], argv[2], argv[3]);
669                 audio_io_test(atoi(argv[1]), atoi(argv[2]), channel_idx);
670         } else if (argc == 6) {
671                 play_file_sample(argv[2], atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
672         } else {
673                 printf("1. usage : audio_io_test call-forwarding-loop\n");
674                 printf("2. usage : audio_io_test call-forwarding-in\n");
675                 printf("3. usage : audio_io_test [length to read] [number of iteration] [channels]\n");
676                 printf("4. usage : audio_io_test async [write(1) | read(2)]\n");
677                 printf("5. Uasge : audio_io_test play [filename] [sample rate] [channels] [type(0:U8)]\n");
678         }
679         return 0;
680 }