- 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;
- }
- 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;
- }
- 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;
- }
- 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);
- if (ret) {
- printf ("fail to sound_manager_create_stream_information(), ret(0x%x)\n", ret);
- }
- ret = audio_out_set_stream_info(output, g_stream_info_write_h);
-#endif
+int audio_io_async_test(int mode)
+{
+ int ret, size;
+ char *buffer = NULL;
+ int i = 0;
+
+ char cmd = 0;
+ int cmd_ret;
+
+ 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;
+ }
+
+ if (read_mode) {
+
+ 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) {
+ printf("audio_in_create_ex failed. \n");
+ return 0;
+ }
+ printf("audio_in_create success!!! [%p]\n", input);
+
+ 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");
+ 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");
+ goto EXIT;
+ }
+ printf("audio_out_set_state_changed_cb success!!! [%p]\n", input);
+
+ ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, _focus_cb, 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_sound_stream_info(input, g_stream_info_read_h);
+ if (ret)
+ printf("fail to audio_in_set_sound_stream_info(), ret(0x%x)\n", ret);
+
+ ret = sound_manager_acquire_focus(g_stream_info_read_h, SOUND_STREAM_FOCUS_FOR_RECORDING, SOUND_BEHAVIOR_NONE, 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_new\n");
+ getchar();
+
+ printf("audio_out_create_new\n");
+ 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_new failed. \n");
+ goto EXIT;
+ }
+ printf("audio_out_create_new 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");
+ 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");
+ goto EXIT;
+ }
+ printf("audio_out_set_state_changed_cb success!!! [%p]\n", output);
+
+ ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, _focus_cb, 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_sound_stream_info(output, g_stream_info_write_h);
+ if (ret)
+ printf("fail to audio_out_set_sound_stream_info(), ret(0x%x)\n", ret);
+
+ ret = sound_manager_acquire_focus(g_stream_info_write_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, 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++)
+ 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;
+ }
+
+ if (read_mode) {
+ printf("before audio_in_prepare\n");
+ getchar();
+ printf("audio_in_prepare\n");
+ ret = audio_in_prepare(input);
+ if (ret != 0) {
+ printf("audio_in_prepare failed, err(0x%x)\n", ret);
+ audio_in_destroy(input);
+ goto EXIT;
+ } else {
+ ret = audio_in_get_buffer_size(input, &size);
+ if (ret != AUDIO_IO_ERROR_NONE) {
+ printf("audio_in_get_buffer_size failed, err(0x%x)\n", ret);
+ goto EXIT;
+ } else {
+ printf("size(%d)\n", size);
+ buffer = alloca(size);
+ }
+ }
+
+ if (buffer == NULL) {
+ printf("buffer is null\n");
+ goto EXIT;
+ }
+ }
+
+ if (write_mode) {
+ printf("before audio_out_prepare\n");
+ getchar();
+ printf("audio_out_prepare\n");
+ ret = audio_out_prepare(output);
+ if (ret != 0) {
+ printf("audio_out_prepare failed, err(0x%x)\n", ret);
+ audio_out_destroy(output);
+ goto EXIT;
+ }
+ }
+
+ do {
+ printf("command(q:quit) : ");
+ ret = getchar();
+ if (ret == EOF)
+ goto EXIT;
+ cmd = (char)ret;
+ if (cmd != '\n')
+ getchar();
+ cmd_ret = _convert_cmd_and_run(cmd, mode);
+ printf(" - result code : %d\n", cmd_ret);
+ } while (cmd != 'q');
+
+EXIT:
+ if (read_mode) {
+ if (input) {
+ printf("audio_in_unprepare\n");
+ audio_in_unprepare(input);
+ printf("audio_in_destroy\n");
+ audio_in_destroy(input);
+ input = NULL;
+ }
+
+ if (fp_w) {
+ fclose(fp_w);
+ fp_w = NULL;
+ }
+
+ 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, SOUND_BEHAVIOR_NONE, 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;
+ }
+ }
+
+ if (write_mode) {
+ if (output) {
+ printf("audio_out_unprepare\n");
+ audio_out_unprepare(output);
+ printf("audio_out_destroy\n");
+ audio_out_destroy(output);
+ }
+
+ 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, SOUND_BEHAVIOR_NONE, 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;
+ }
+ }
+
+ return 0;
+}