adv_error soundb_sdl_init(int sound_id, unsigned* rate, adv_bool stereo_flag, double buffer_time) { char name[64]; log_std(("sound:sdl: soundb_sdl_init(id:%d, rate:%d, stereo:%d, buffer_time:%g)\n", (unsigned)sound_id, (unsigned)*rate, (int)stereo_flag, (double)buffer_time)); if (!os_internal_sdl_get()) { error_set("Unsupported without the SDL library.\n"); return -1; } if (!sdl_option.initialized) { soundb_sdl_default(); } sdl_state.underflow_flag = 0; sdl_state.fifo_pos = 0; sdl_state.fifo_mac = 0; sdl_state.volume = SDL_VOLUME_BASE; if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0) { error_set("Function SDL_InitSubSystem(SDL_INIT_AUDIO) failed, %s.\n", SDL_GetError()); goto err; } if (SDL_AudioDriverName(name, sizeof(name))) { log_std(("sound:sdl: driver %s\n", name)); } sdl_state.info.freq = *rate; sdl_state.info.format = AUDIO_S16LSB; sdl_state.info.channels = stereo_flag ? 2 : 1; sdl_state.info.samples = sdl_option.samples; sdl_state.info.callback = soundb_sdl_callback; sdl_state.info.userdata = &sdl_state; log_std(("sound:sdl: request fragment size %d [samples]\n", sdl_state.info.samples)); if (SDL_OpenAudio(&sdl_state.info, 0) != 0) { error_set("Function SDL_OpenAudio(%d, AUDIO_S16LSB, %d, %d) failed, %s.\n", (unsigned)sdl_state.info.freq, (unsigned)sdl_state.info.channels, (unsigned)sdl_state.info.samples, SDL_GetError()); goto err_quit; } log_std(("sound:sdl: result fragment size %d [samples], buffer size %d [bytes]\n", sdl_state.info.samples, sdl_state.info.size)); *rate = sdl_state.info.freq; sdl_state.active_flag = 1; return 0; err_quit: SDL_QuitSubSystem(SDL_INIT_AUDIO); err: return -1; }
adv_error joystickb_sdl_init(int joystickb_id) { unsigned i; log_std(("josytickb:sdl: joystickb_sdl_init(id:%d)\n", joystickb_id)); if (!os_internal_sdl_get()) { error_set("Unsupported without the SDL library.\n"); return -1; } if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0) { error_set("Function SDL_InitSubSystem(SDL_INIT_JOYSTICK) failed, %s.\n", SDL_GetError()); goto err; } SDL_JoystickEventState(SDL_IGNORE); sdl_state.counter = SDL_NumJoysticks(); if (sdl_state.counter > SDL_JOYSTICK_MAX) sdl_state.counter = SDL_JOYSTICK_MAX; if (sdl_state.counter == 0) { error_set("No joystick found.\n"); goto err_quit; } for (i = 0; i < sdl_state.counter; ++i) { sdl_state.map[i] = SDL_JoystickOpen(i); if (!sdl_state.map[i]) { error_set("Function SDL_JoystickOpen(%d) failed, %s.\n", i, SDL_GetError()); goto err_quit; } } return 0; err_quit: SDL_QuitSubSystem(SDL_INIT_JOYSTICK); err: return -1; }