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