/** * init_drivers_pre: * * Attempts to find a default driver for * all driver types. * * Should be run before init_drivers(). **/ void init_drivers_pre(void) { find_audio_driver(); find_video_driver(); find_input_driver(); find_camera_driver(); find_location_driver(); #ifdef HAVE_MENU find_menu_driver(); #endif }
void init_drivers_pre(void) { find_audio_driver(); find_video_driver(); find_input_driver(); #ifdef HAVE_CAMERA find_camera_driver(); #endif #ifdef HAVE_LOCATION find_location_driver(); #endif #ifdef HAVE_OSK find_osk_driver(); #endif }
void init_audio(void) { size_t outsamples_max, max_bufsamples = AUDIO_CHUNK_SIZE_NONBLOCKING * 2; runloop_t *runloop = rarch_main_get_ptr(); driver_t *driver = driver_get_ptr(); global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); audio_convert_init_simd(); /* Resource leaks will follow if audio is initialized twice. */ if (driver->audio_data) return; /* Accomodate rewind since at some point we might have two full buffers. */ outsamples_max = max_bufsamples * AUDIO_MAX_RATIO * settings->slowmotion_ratio; /* Used for recording even if audio isn't enabled. */ rarch_assert(global->audio_data.conv_outsamples = (int16_t*)malloc(outsamples_max * sizeof(int16_t))); if (!global->audio_data.conv_outsamples) goto error; global->audio_data.block_chunk_size = AUDIO_CHUNK_SIZE_BLOCKING; global->audio_data.nonblock_chunk_size = AUDIO_CHUNK_SIZE_NONBLOCKING; global->audio_data.chunk_size = global->audio_data.block_chunk_size; /* Needs to be able to hold full content of a full max_bufsamples * in addition to its own. */ rarch_assert(global->audio_data.rewind_buf = (int16_t*) malloc(max_bufsamples * sizeof(int16_t))); if (!global->audio_data.rewind_buf) goto error; global->audio_data.rewind_size = max_bufsamples; if (!settings->audio.enable) { driver->audio_active = false; return; } find_audio_driver(); #ifdef HAVE_THREADS if (global->system.audio_callback.callback) { RARCH_LOG("Starting threaded audio driver ...\n"); if (!rarch_threaded_audio_init(&driver->audio, &driver->audio_data, *settings->audio.device ? settings->audio.device : NULL, settings->audio.out_rate, settings->audio.latency, driver->audio)) { RARCH_ERR("Cannot open threaded audio driver ... Exiting ...\n"); rarch_fail(1, "init_audio()"); } } else #endif { driver->audio_data = driver->audio->init(*settings->audio.device ? settings->audio.device : NULL, settings->audio.out_rate, settings->audio.latency); } if (!driver->audio_data) { RARCH_ERR("Failed to initialize audio driver. Will continue without audio.\n"); driver->audio_active = false; } global->audio_data.use_float = false; if (driver->audio_active && driver->audio->use_float(driver->audio_data)) global->audio_data.use_float = true; if (!settings->audio.sync && driver->audio_active) { rarch_main_command(RARCH_CMD_AUDIO_SET_NONBLOCKING_STATE); global->audio_data.chunk_size = global->audio_data.nonblock_chunk_size; } if (global->audio_data.in_rate <= 0.0f) { /* Should never happen. */ RARCH_WARN("Input rate is invalid (%.3f Hz). Using output rate (%u Hz).\n", global->audio_data.in_rate, settings->audio.out_rate); global->audio_data.in_rate = settings->audio.out_rate; } global->audio_data.orig_src_ratio = global->audio_data.src_ratio = (double)settings->audio.out_rate / global->audio_data.in_rate; if (!rarch_resampler_realloc(&driver->resampler_data, &driver->resampler, settings->audio.resampler, global->audio_data.orig_src_ratio)) { RARCH_ERR("Failed to initialize resampler \"%s\".\n", settings->audio.resampler); driver->audio_active = false; } rarch_assert(global->audio_data.data = (float*) malloc(max_bufsamples * sizeof(float))); if (!global->audio_data.data) goto error; global->audio_data.data_ptr = 0; rarch_assert(settings->audio.out_rate < global->audio_data.in_rate * AUDIO_MAX_RATIO); rarch_assert(global->audio_data.outsamples = (float*) malloc(outsamples_max * sizeof(float))); if (!global->audio_data.outsamples) goto error; global->audio_data.rate_control = false; if (!global->system.audio_callback.callback && driver->audio_active && settings->audio.rate_control) { if (driver->audio->buffer_size && driver->audio->write_avail) { global->audio_data.driver_buffer_size = driver->audio->buffer_size(driver->audio_data); global->audio_data.rate_control = true; } else RARCH_WARN("Audio rate control was desired, but driver does not support needed features.\n"); } rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT); runloop->measure_data.buffer_free_samples_count = 0; if (driver->audio_active && !settings->audio.mute_enable && global->system.audio_callback.callback) { /* Threaded driver is initially stopped. */ driver->audio->start(driver->audio_data); } return; error: if (global->audio_data.conv_outsamples) free(global->audio_data.conv_outsamples); global->audio_data.conv_outsamples = NULL; if (global->audio_data.data) free(global->audio_data.data); global->audio_data.data = NULL; if (global->audio_data.rewind_buf) free(global->audio_data.rewind_buf); global->audio_data.rewind_buf = NULL; if (global->audio_data.outsamples) free(global->audio_data.outsamples); global->audio_data.outsamples = NULL; }
void init_audio(void) { audio_convert_init_simd(); // Resource leaks will follow if audio is initialized twice. if (driver.audio_data) return; // Accomodate rewind since at some point we might have two full buffers. size_t max_bufsamples = AUDIO_CHUNK_SIZE_NONBLOCKING * 2; size_t outsamples_max = max_bufsamples * AUDIO_MAX_RATIO * g_settings.slowmotion_ratio; // Used for recording even if audio isn't enabled. rarch_assert(g_extern.audio_data.conv_outsamples = (int16_t*)malloc(outsamples_max * sizeof(int16_t))); g_extern.audio_data.block_chunk_size = AUDIO_CHUNK_SIZE_BLOCKING; g_extern.audio_data.nonblock_chunk_size = AUDIO_CHUNK_SIZE_NONBLOCKING; g_extern.audio_data.chunk_size = g_extern.audio_data.block_chunk_size; // Needs to be able to hold full content of a full max_bufsamples in addition to its own. rarch_assert(g_extern.audio_data.rewind_buf = (int16_t*)malloc(max_bufsamples * sizeof(int16_t))); g_extern.audio_data.rewind_size = max_bufsamples; if (!g_settings.audio.enable) { g_extern.audio_active = false; return; } find_audio_driver(); #ifdef HAVE_THREADS if (g_extern.system.audio_callback.callback) { RARCH_LOG("Starting threaded audio driver ...\n"); if (!rarch_threaded_audio_init(&driver.audio, &driver.audio_data, *g_settings.audio.device ? g_settings.audio.device : NULL, g_settings.audio.out_rate, g_settings.audio.latency, driver.audio)) { RARCH_ERR("Cannot open threaded audio driver ... Exiting ...\n"); rarch_fail(1, "init_audio()"); } } else #endif { driver.audio_data = driver.audio->init(*g_settings.audio.device ? g_settings.audio.device : NULL, g_settings.audio.out_rate, g_settings.audio.latency); } if (!driver.audio_data) { RARCH_ERR("Failed to initialize audio driver. Will continue without audio.\n"); g_extern.audio_active = false; } g_extern.audio_data.use_float = false; if (g_extern.audio_active && driver.audio->use_float && driver.audio->use_float(driver.audio_data)) g_extern.audio_data.use_float = true; if (!g_settings.audio.sync && g_extern.audio_active) { rarch_main_command(RARCH_CMD_AUDIO_SET_NONBLOCKING_STATE); g_extern.audio_data.chunk_size = g_extern.audio_data.nonblock_chunk_size; } // Should never happen. if (g_extern.audio_data.in_rate <= 0.0f) { RARCH_WARN("Input rate is invalid (%.3f Hz). Using output rate (%u Hz).\n", g_extern.audio_data.in_rate, g_settings.audio.out_rate); g_extern.audio_data.in_rate = g_settings.audio.out_rate; } g_extern.audio_data.orig_src_ratio = g_extern.audio_data.src_ratio = (double)g_settings.audio.out_rate / g_extern.audio_data.in_rate; if (!rarch_resampler_realloc(&g_extern.audio_data.resampler_data, &g_extern.audio_data.resampler, g_settings.audio.resampler, g_extern.audio_data.orig_src_ratio)) { RARCH_ERR("Failed to initialize resampler \"%s\".\n", g_settings.audio.resampler); g_extern.audio_active = false; } rarch_assert(g_extern.audio_data.data = (float*)malloc(max_bufsamples * sizeof(float))); g_extern.audio_data.data_ptr = 0; rarch_assert(g_settings.audio.out_rate < g_extern.audio_data.in_rate * AUDIO_MAX_RATIO); rarch_assert(g_extern.audio_data.outsamples = (float*)malloc(outsamples_max * sizeof(float))); g_extern.audio_data.rate_control = false; if (!g_extern.system.audio_callback.callback && g_extern.audio_active && g_settings.audio.rate_control) { if (driver.audio->buffer_size && driver.audio->write_avail) { g_extern.audio_data.driver_buffer_size = driver.audio->buffer_size(driver.audio_data); g_extern.audio_data.rate_control = true; } else RARCH_WARN("Audio rate control was desired, but driver does not support needed features.\n"); } rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT); g_extern.measure_data.buffer_free_samples_count = 0; if (g_extern.audio_active && !g_extern.audio_data.mute && g_extern.system.audio_callback.callback) // Threaded driver is initially stopped. driver.audio->start(driver.audio_data); }
void global_init_drivers(void) { find_audio_driver(); find_input_driver(); init_video_input(); }