audio-io fixed crash at audio_in_read() of another thread.
[platform/core/api/audio-io.git] / test / audio_io_test.c
index a5a7775..ca89a73 100644 (file)
@@ -22,9 +22,6 @@
 #include <sound_manager.h>
 #include <audio_io.h>
 
-//#define _NEW_SOUND_MANAGER_API_
-#define _SESSION_SOUND_MANAGER_API_
-
 #ifndef M_PI
 #define M_PI  (3.14159265)
 #endif
@@ -56,11 +53,9 @@ void play_file(char *file, int length, int ch)
        }
 
        printf("start to play [%s][%d][%d]\n", file, length, ch);
-       //audio_out_create(44100, ch_table[ch] ,AUDIO_SAMPLE_TYPE_S16_LE, SOUND_TYPE_MEDIA, &output);
        audio_out_create_new(44100, ch_table[ch], AUDIO_SAMPLE_TYPE_S16_LE, &output);
-       if (fread(buf, 1, length, fp) != length) {
+       if (fread(buf, 1, length, fp) != length)
                printf("error!!!!\n");
-       }
 
        audio_out_prepare(output);
        audio_out_write(output, buf, length);
@@ -83,28 +78,25 @@ void play_file_sample(char *file, int frequency, int ch, int type)
        int buffer_size = 0;
        char *buf = NULL;
 
-       if (ch < 0 || ch > 2) {
+       if (ch < 0 || ch > 2)
                ch = 0;
-       }
 
        FILE *fp = fopen(file, "r");
        if (fp == NULL) {
                printf("open failed\n");
                return;
        }
-       /*Get the size */
+       /* Get the size */
        fseek(fp, 0, SEEK_END);
        file_size = ftell(fp);
        fseek(fp, 0, SEEK_SET);
 
        printf("start to play [%s] of size [%d] with [%d][%d][%d]\n", file, file_size, frequency, ch, type);
-       if (type) {
-               //audio_out_create(frequency, ch_table[ch] ,AUDIO_SAMPLE_TYPE_S16_LE, SOUND_TYPE_MEDIA, &output);
+       if (type)
                audio_out_create_new(frequency, ch_table[ch], AUDIO_SAMPLE_TYPE_S16_LE, &output);
-       } else {
-               //audio_out_create(frequency, ch_table[ch] ,AUDIO_SAMPLE_TYPE_U8, SOUND_TYPE_MEDIA, &output);
+       else
                audio_out_create_new(frequency, ch_table[ch], AUDIO_SAMPLE_TYPE_U8, &output);
-       }
+
        audio_out_prepare(output);
        audio_out_get_buffer_size(output, &buffer_size);
 
@@ -116,7 +108,6 @@ void play_file_sample(char *file, int frequency, int ch, int type)
                fclose(fp);
                return;
        }
-       //audio_out_prepare(output);
 
        while (file_size > 0) {
                read_bytes = fread(buf, 1, buffer_size, fp);
@@ -177,6 +168,7 @@ int audio_io_test(int length, int num, int ch)
 
                fclose(fp);
 
+               audio_in_unprepare(input);
                audio_in_destroy(input);
        }
 
@@ -247,7 +239,6 @@ int audio_io_loopback_test()
                printf("audio_in_create_ex failed. \n");
                return 0;
        }
-       //ret = audio_out_create(16000, AUDIO_CHANNEL_MONO , AUDIO_SAMPLE_TYPE_S16_LE, SOUND_TYPE_CALL, &output);
        ret = audio_out_create_new(16000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &output);
        if (ret != AUDIO_IO_ERROR_NONE) {
                printf("audio_out_create failed. \n");
@@ -256,13 +247,13 @@ int audio_io_loopback_test()
 
        ret = audio_in_prepare(input);
        if (ret != 0) {
-               printf("audio_in_prepare failed.\n");
+               printf("audio_in_prepare failed, err(0x%x)\n", ret);
                audio_in_destroy(input);
                return 0;
        } else {
                ret = audio_in_get_buffer_size(input, &size);
                if (ret != AUDIO_IO_ERROR_NONE) {
-                       printf("audio_in_get_buffer_size failed.\n");
+                       printf("audio_in_get_buffer_size failed, err(0x%x)\n", ret);
                        return 0;
                } else {
                        printf("size(%d)\n", size);
@@ -272,7 +263,7 @@ int audio_io_loopback_test()
 
        ret = audio_out_prepare(output);
        if (ret != 0) {
-               printf("audio_out_prepare failed.\n");
+               printf("audio_out_prepare failed, err(0x%x)\n", ret);
                audio_out_destroy(output);
                return 0;
        }
@@ -286,11 +277,10 @@ int audio_io_loopback_test()
                ret = audio_in_read(input, (void *)buffer, size);
                if (ret > AUDIO_IO_ERROR_NONE) {
                        ret = audio_out_write(output, buffer, size);
-                       if (ret > AUDIO_IO_ERROR_NONE) {
+                       if (ret > AUDIO_IO_ERROR_NONE)
                                printf("audio read/write success. buffer(%p), size(%d)\n", buffer, size);
-                       } else {
+                       else
                                printf("audio read success, write failed. buffer(%p), size(%d)\n", buffer, size);
-                       }
                } else
                        printf("audio read/write failed. buffer(%p), size(%d)\n", buffer, size);
        }
@@ -302,73 +292,32 @@ audio_out_h output;
 
 FILE *fp_w = NULL;
 
-#ifdef _NEW_SOUND_MANAGER_API_
 sound_stream_info_h g_stream_info_read_h = NULL;
 sound_stream_info_h g_stream_info_write_h = NULL;
 
-static void focus_callback_read(sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason_for_change, const char *additional_info, void *user_data)
+static void focus_callback(sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason_for_change, const char *additional_info, void *user_data)
 {
        int ret = 0;
        sound_stream_focus_state_e playback_focus_state;
        sound_stream_focus_state_e recording_focus_state;
-       printf("*** focus_callback_read is called, stream_info(%p) ***\n", stream_info);
+       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);
        printf(" - reason_for_change(%d), additional_info(%s), user_data(%p)\n", reason_for_change, additional_info, user_data);
        ret = sound_manager_get_focus_state(stream_info, &playback_focus_state, &recording_focus_state);
        if (!ret)
                printf(" - focus_state(playback_focus:%d, recording_focus:%d)\n", playback_focus_state, recording_focus_state);
-       if (playback_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
-               printf(" -- PLAYBACK_FOCUS acquired\n");
-       }
-       if (recording_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
-               printf(" -- FOCUS_RECORDING acquired\n");
-       }
-       printf("*** focus_callback_read is ended, stream_info(%p) ****\n", stream_info);
-       return;
-}
 
-static void focus_callback_write(sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason_for_change, const char *additional_info, void *user_data)
-{
-       int ret = 0;
-       sound_stream_focus_state_e playback_focus_state;
-       sound_stream_focus_state_e recording_focus_state;
-       printf("*** focus_callback_write is called, stream_info(%p) ***\n", stream_info);
-       printf(" - reason_for_change(%d), additional_info(%s), user_data(%p)\n", reason_for_change, additional_info, user_data);
-       ret = sound_manager_get_focus_state(stream_info, &playback_focus_state, &recording_focus_state);
-       if (!ret)
-               printf(" - focus_state(playback_focus:%d, recording_focus:%d)\n", playback_focus_state, recording_focus_state);
-       if (playback_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
-               printf(" -- PLAYBACK_FOCUS acquired\n");
-       }
-       if (recording_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
-               printf(" -- FOCUS_RECORDING acquired\n");
-       }
-       printf("*** focus_callback_write is ended, stream_info(%p) ****\n", stream_info);
        return;
 }
-#endif
-
-static void interrupted_callback_read(audio_io_interrupted_code_e code, void *user_data)
-{
-       printf("*** interrupted_callback_read is called, code(%d), user_data(%p) ***\n", code, user_data);
-}
-
-static void interrupted_callback_write(audio_io_interrupted_code_e code, void *user_data)
-{
-       printf("*** interrupted_callback_write is called, code(%d), user_data(%p) ***\n", code, user_data);
-}
 
 static void _audio_io_stream_read_cb(audio_in_h handle, size_t nbytes, void *user_data)
 {
        const void *buffer = NULL;
        unsigned int len = (unsigned int)nbytes;
 
-       //printf("_audio_io_stream_read_cb : handle=%p, nbytes=%d, user_data=%p\n", handle, nbytes, user_data);
-
        if (len > 0) {
                audio_in_peek(handle, &buffer, &len);
-               if (fp_w) {
+               if (fp_w)
                        fwrite(buffer, sizeof(char), len, fp_w);
-               }
                audio_in_drop(handle);
        }
 }
@@ -376,11 +325,8 @@ static void _audio_io_stream_read_cb(audio_in_h handle, size_t nbytes, void *use
 static void _audio_io_stream_write_cb(audio_out_h handle, size_t nbytes, void *user_data)
 {
        short *buffer = NULL;
-       int ret = 0;
        int i = 0;
 
-       //printf("_audio_io_stream_write_cb : handle=%p, nbytes=%d, user_data=%p\n", handle, nbytes, user_data);
-
        if (nbytes > 0) {
                buffer = (short *)malloc(nbytes);
                if (buffer == NULL) {
@@ -400,10 +346,7 @@ static void _audio_io_stream_write_cb(audio_out_h handle, size_t nbytes, void *u
                                test_wav.right_channel -= TABLE_SIZE;
                }
 
-               ret = audio_out_write(handle, buffer, nbytes);
-               if (ret > AUDIO_IO_ERROR_NONE) {
-                       //printf("audio write success. buffer(%p), nbytes(%d)\n", buffer, nbytes);
-               }
+               audio_out_write(handle, buffer, nbytes);
 
                free(buffer);
        }
@@ -450,7 +393,6 @@ int _convert_cmd_and_run(char cmd, int mode)
        case 'd':
                if (mode & 0x01)
                        ret = audio_out_drain(output);
-               //if (mode & 0x02)  ret = audio_in_drain(input);
                break;
        case 'f':
                if (mode & 0x01)
@@ -459,22 +401,9 @@ int _convert_cmd_and_run(char cmd, int mode)
                        ret = audio_in_flush(input);
                break;
        case 'i':
-#ifdef _NEW_SOUND_MANAGER_API_
-               ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback_write, NULL, &g_stream_info_write_h);
-               if (ret) {
+               ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_write_h);
+               if (ret)
                        printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
-               }
-#endif
-#ifdef _SESSION_SOUND_MANAGER_API_
-               ret = sound_manager_set_session_type(SOUND_SESSION_TYPE_MEDIA);
-               if (ret) {
-                       printf("fail to sound_manager_set_session_type(), ret(0x%x)\n", ret);
-               }
-               ret = sound_manager_set_media_session_option(SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START, SOUND_SESSION_OPTION_INTERRUPTIBLE_DURING_PLAY);
-               if (ret) {
-                       printf("fail to sound_manager_set_media_session_option(), ret(0x%x)\n", ret);
-               }
-#endif
                break;
        case 'q':                                       /* quit */
                ret = 1;
@@ -498,6 +427,9 @@ int audio_io_async_test(int mode)
        int write_mode = (mode & 0x01);
        int read_mode = (mode & 0x02);
 
+       sound_stream_focus_state_e playback_focus_state;
+       sound_stream_focus_state_e recording_focus_state;
+
        if ((write_mode == 0) && (read_mode == 0)) {
                printf("not vaild mode.\n");
                return 0;
@@ -505,20 +437,6 @@ int audio_io_async_test(int mode)
 
        if (read_mode) {
 
-#ifdef _SESSION_SOUND_MANAGER_API_
-               printf("set session for capture.\n");
-
-               ret = sound_manager_set_session_type(SOUND_SESSION_TYPE_MEDIA);
-               if (ret) {
-                       printf("fail to sound_manager_set_session_type(), ret(0x%x)\n", ret);
-               }
-
-               ret = sound_manager_set_media_session_option(SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START, SOUND_SESSION_OPTION_INTERRUPTIBLE_DURING_PLAY);
-               if (ret) {
-                       printf("fail to sound_manager_set_media_session_option(), ret(0x%x)\n", ret);
-               }
-#endif
-
                printf("audio_in_create\n");
                ret = audio_in_create(44100, AUDIO_CHANNEL_STEREO, AUDIO_SAMPLE_TYPE_S16_LE, &input);
                if (ret != AUDIO_IO_ERROR_NONE) {
@@ -530,87 +448,79 @@ int audio_io_async_test(int mode)
                ret = audio_in_set_stream_cb(input, _audio_io_stream_read_cb, NULL);
                if (ret != AUDIO_IO_ERROR_NONE) {
                        printf("audio_in_set_stream_cb failed. \n");
-                       return 0;
+                       goto EXIT;
                }
                printf("audio_in_set_stream_cb success!!! [%p]\n", input);
 
                ret = audio_in_set_state_changed_cb(input, _audio_in_state_cb, NULL);
                if (ret != AUDIO_IO_ERROR_NONE) {
                        printf("audio_out_set_state_changed_cb failed. \n");
-                       return 0;
+                       goto EXIT;
                }
                printf("audio_out_set_state_changed_cb success!!! [%p]\n", input);
 
-               fp_w = fopen("/tmp/pcm_w.raw", "w");
-
-#ifdef _NEW_SOUND_MANAGER_API_
-               //set stream type as SOUND_STREAM_TYPE_MEDIA
-               ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback_read, NULL, &g_stream_info_read_h);
+               ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_read_h);
                if (ret) {
                        printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
+                       goto EXIT;
                }
                ret = audio_in_set_stream_info(input, g_stream_info_read_h);
-#endif
+               if (ret)
+                       printf("fail to audio_in_set_stream_info(), ret(0x%x)\n", ret);
 
-               ret = audio_in_set_interrupted_cb(input, interrupted_callback_read, NULL);
+               ret = sound_manager_acquire_focus(g_stream_info_read_h, SOUND_STREAM_FOCUS_FOR_RECORDING, NULL);
+               if (ret) {
+                       printf("fail to sound_manager_acquire_focus() for RECORDING, ret(0x%x)\n", ret);
+                       goto EXIT;
+               }
+
+               fp_w = fopen("/tmp/pcm_w.raw", "w");
        }
 
        if (write_mode) {
                printf("before audio_out_create\n");
                getchar();
 
-#ifdef _SESSION_SOUND_MANAGER_API_
-               printf("set session for playback.\n");
-
-               ret = sound_manager_set_session_type(SOUND_SESSION_TYPE_MEDIA);
-               if (ret) {
-                       printf("fail to sound_manager_set_session_type(), ret(0x%x)\n", ret);
-               }
-
-               ret = sound_manager_set_media_session_option(SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START, SOUND_SESSION_OPTION_INTERRUPTIBLE_DURING_PLAY);
-               if (ret) {
-                       printf("fail to sound_manager_set_media_session_option(), ret(0x%x)\n", ret);
-               }
-#endif
-
                printf("audio_out_create\n");
-               //ret = audio_out_create(44100, AUDIO_CHANNEL_STEREO , AUDIO_SAMPLE_TYPE_S16_LE, SOUND_TYPE_MEDIA, &output);
                ret = audio_out_create_new(44100, AUDIO_CHANNEL_STEREO, AUDIO_SAMPLE_TYPE_S16_LE, &output);
                if (ret != AUDIO_IO_ERROR_NONE) {
                        printf("audio_out_create failed. \n");
-                       return 0;
+                       goto EXIT;
                }
                printf("audio_out_create success!!! [%p]\n", output);
 
                ret = audio_out_set_stream_cb(output, _audio_io_stream_write_cb, NULL);
                if (ret != AUDIO_IO_ERROR_NONE) {
                        printf("audio_out_set_stream_cb failed. \n");
-                       return 0;
+                       goto EXIT;
                }
                printf("audio_out_set_stream_cb success!!! [%p]\n", output);
 
                ret = audio_out_set_state_changed_cb(output, _audio_out_state_cb, NULL);
                if (ret != AUDIO_IO_ERROR_NONE) {
                        printf("audio_out_set_state_changed_cb failed. \n");
-                       return 0;
+                       goto EXIT;
                }
                printf("audio_out_set_state_changed_cb success!!! [%p]\n", output);
 
-#ifdef _NEW_SOUND_MANAGER_API_
-               //set stream type as SOUND_STREAM_TYPE_MEDIA
-               ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback_write, NULL, &g_stream_info_write_h);
+               ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, focus_callback, NULL, &g_stream_info_write_h);
                if (ret) {
                        printf("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
+                       goto EXIT;
                }
                ret = audio_out_set_stream_info(output, g_stream_info_write_h);
-#endif
+               if (ret)
+                       printf("fail to audio_out_set_stream_info(), ret(0x%x)\n", ret);
 
-               ret = audio_out_set_interrupted_cb(output, interrupted_callback_write, NULL);
+               ret = sound_manager_acquire_focus(g_stream_info_write_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
+               if (ret) {
+                       printf("fail to sound_manager_acquire_focus() for PLAYBACK, ret(0x%x)\n", ret);
+                       goto EXIT;
+               }
 
-               //generate wave data
-               for (i = 0; i < TABLE_SIZE; i++) {
+               /* generate wave data */
+               for (i = 0; i < TABLE_SIZE; i++)
                        test_wav.sine[i] = 0.9 * (float)sin(((double)i / (double)TABLE_SIZE) * M_PI * 2.);
-               }
                test_wav.left_channel = test_wav.right_channel = 0;
        }
 
@@ -620,14 +530,14 @@ int audio_io_async_test(int mode)
                printf("audio_in_prepare\n");
                ret = audio_in_prepare(input);
                if (ret != 0) {
-                       printf("audio_in_prepare failed.\n");
+                       printf("audio_in_prepare failed, err(0x%x)\n", ret);
                        audio_in_destroy(input);
-                       return 0;
+                       goto EXIT;
                } else {
                        ret = audio_in_get_buffer_size(input, &size);
                        if (ret != AUDIO_IO_ERROR_NONE) {
-                               printf("audio_in_get_buffer_size failed.\n");
-                               return 0;
+                               printf("audio_in_get_buffer_size failed, err(0x%x)\n", ret);
+                               goto EXIT;
                        } else {
                                printf("size(%d)\n", size);
                                buffer = alloca(size);
@@ -636,7 +546,7 @@ int audio_io_async_test(int mode)
 
                if (buffer == NULL) {
                        printf("buffer is null\n");
-                       return 0;
+                       goto EXIT;
                }
        }
 
@@ -646,63 +556,73 @@ int audio_io_async_test(int mode)
                printf("audio_out_prepare\n");
                ret = audio_out_prepare(output);
                if (ret != 0) {
-                       printf("audio_out_prepare failed.\n");
+                       printf("audio_out_prepare failed, err(0x%x)\n", ret);
                        audio_out_destroy(output);
-                       return 0;
+                       goto EXIT;
                }
        }
 
        do {
+               int gotchar;
                printf("command(q:quit) : ");
-               cmd = (char)getchar();
+               gotchar = getchar();
+               if (gotchar == EOF)
+                       goto EXIT;
                if (cmd != '\n')
                        getchar();
                cmd_ret = _convert_cmd_and_run(cmd, mode);
                printf("  - result code : %d\n", cmd_ret);
        } while (cmd != 'q');
 
-       //printf ("loop start\n");
-       //for (i=0; i<10; i++) {
-       //    printf ("-------- %d -------\n",i);
-       //    usleep (1000000);
-       //}
-
-       //getchar();
-
+EXIT:
        if (read_mode) {
-               printf("audio_in_unprepare\n");
-               audio_in_unprepare(input);
-               printf("audio_in_destroy\n");
-               audio_in_destroy(input);
+               if (input) {
+                       printf("audio_in_unprepare\n");
+                       audio_in_unprepare(input);
+                       printf("audio_in_destroy\n");
+                       audio_in_destroy(input);
+                       input = NULL;
+               }
 
-               fclose(fp_w);
-               fp_w = NULL;
+               if (fp_w) {
+                       fclose(fp_w);
+                       fp_w = NULL;
+               }
 
-#ifdef _NEW_SOUND_MANAGER_API_
-               ret = sound_manager_destroy_stream_information(g_stream_info_read_h);
-               if (ret) {
-                       printf("fail to sound_manager_destroy_stream_information(), ret(0x%x)\n", ret);
-               } else {
+               if (g_stream_info_read_h) {
+                       ret = sound_manager_get_focus_state(g_stream_info_read_h, NULL, &recording_focus_state);
+                       if (recording_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
+                               ret = sound_manager_release_focus(g_stream_info_read_h, SOUND_STREAM_FOCUS_FOR_RECORDING, NULL);
+                               if (ret)
+                                       printf("fail to sound_manager_release_focus() for recording, ret(0x%x)\n", ret);
+                       }
+                       ret = sound_manager_destroy_stream_information(g_stream_info_read_h);
+                       if (ret)
+                               printf("fail to sound_manager_destroy_stream_information(), ret(0x%x)\n", ret);
                        g_stream_info_read_h = NULL;
                }
-#endif
        }
-       //getchar();
 
        if (write_mode) {
-               printf("audio_out_unprepare\n");
-               audio_out_unprepare(output);
-               printf("audio_out_destroy\n");
-               audio_out_destroy(output);
+               if (output) {
+                       printf("audio_out_unprepare\n");
+                       audio_out_unprepare(output);
+                       printf("audio_out_destroy\n");
+                       audio_out_destroy(output);
+               }
 
-#ifdef _NEW_SOUND_MANAGER_API_
-               ret = sound_manager_destroy_stream_information(g_stream_info_write_h);
-               if (ret) {
-                       printf("fail to sound_manager_destroy_stream_information(), ret(0x%x)\n", ret);
-               } else {
+               if (g_stream_info_write_h) {
+                       ret = sound_manager_get_focus_state(g_stream_info_write_h, &playback_focus_state, NULL);
+                       if (playback_focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED) {
+                               ret = sound_manager_release_focus(g_stream_info_write_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
+                               if (ret)
+                                       printf("fail to sound_manager_release_focus() for playback, ret(0x%x)\n", ret);
+                       }
+                       ret = sound_manager_destroy_stream_information(g_stream_info_write_h);
+                       if (ret)
+                               printf("fail to sound_manager_destroy_stream_information(), ret(0x%x)\n", ret);
                        g_stream_info_write_h = NULL;
                }
-#endif
        }
 
        return 0;
@@ -717,8 +637,13 @@ int main(int argc, char **argv)
        } else if (argc == 3 && !strcmp(argv[1], "async")) {
                audio_io_async_test(atoi(argv[2]));
        } else if (argc == 4) {
+               int channel_idx = atoi(argv[3]);
+               if (channel_idx < 0 || channel_idx > 2) {
+                       printf("Invalid channel\n");
+                       return 0;
+               }
                printf("run with [%s][%s][%s]\n", argv[1], argv[2], argv[3]);
-               audio_io_test(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
+               audio_io_test(atoi(argv[1]), atoi(argv[2]), channel_idx);
        } else if (argc == 6) {
                play_file_sample(argv[2], atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
        } else {