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