mirror of
https://github.com/libretro/RetroArch.git
synced 2025-04-02 10:51:52 -04:00
Move audio callback to audio_driver.c
This commit is contained in:
parent
56414034a5
commit
398570f017
6 changed files with 43 additions and 15 deletions
|
@ -55,6 +55,7 @@ typedef struct audio_driver_input_data
|
|||
size_t driver_buffer_size;
|
||||
|
||||
float volume_gain;
|
||||
struct retro_audio_callback audio_callback;
|
||||
} audio_driver_input_data_t;
|
||||
|
||||
static audio_driver_input_data_t audio_data;
|
||||
|
@ -322,7 +323,6 @@ 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();
|
||||
|
@ -364,7 +364,7 @@ void init_audio(void)
|
|||
|
||||
find_audio_driver();
|
||||
#ifdef HAVE_THREADS
|
||||
if (global->system.audio_callback.callback)
|
||||
if (audio_data.audio_callback.callback)
|
||||
{
|
||||
RARCH_LOG("Starting threaded audio driver ...\n");
|
||||
if (!rarch_threaded_audio_init(&driver->audio, &driver->audio_data,
|
||||
|
@ -437,7 +437,7 @@ void init_audio(void)
|
|||
goto error;
|
||||
|
||||
audio_data.rate_control = false;
|
||||
if (!global->system.audio_callback.callback && driver->audio_active &&
|
||||
if (!audio_data.audio_callback.callback && driver->audio_active &&
|
||||
settings->audio.rate_control)
|
||||
{
|
||||
/* Audio rate control requires write_avail
|
||||
|
@ -457,7 +457,7 @@ void init_audio(void)
|
|||
runloop->measure_data.buffer_free_samples_count = 0;
|
||||
|
||||
if (driver->audio_active && !settings->audio.mute_enable &&
|
||||
global->system.audio_callback.callback)
|
||||
audio_data.audio_callback.callback)
|
||||
{
|
||||
/* Threaded driver is initially stopped. */
|
||||
driver->audio->start(driver->audio_data);
|
||||
|
@ -859,3 +859,29 @@ void audio_driver_set_buffer_size(size_t bufsize)
|
|||
{
|
||||
audio_data.driver_buffer_size = bufsize;
|
||||
}
|
||||
|
||||
void audio_driver_set_callback(const void *data)
|
||||
{
|
||||
const struct retro_audio_callback *cb =
|
||||
(const struct retro_audio_callback*)data;
|
||||
|
||||
if (cb)
|
||||
audio_data.audio_callback = *cb;
|
||||
}
|
||||
|
||||
bool audio_driver_has_callback(void)
|
||||
{
|
||||
return audio_data.audio_callback.callback;
|
||||
}
|
||||
|
||||
void audio_driver_callback(void)
|
||||
{
|
||||
if (audio_driver_has_callback())
|
||||
audio_data.audio_callback.callback();
|
||||
}
|
||||
|
||||
void audio_driver_callback_set_state(bool state)
|
||||
{
|
||||
if (audio_driver_has_callback())
|
||||
audio_data.audio_callback.set_state(state);
|
||||
}
|
||||
|
|
|
@ -169,6 +169,14 @@ void audio_driver_frame_is_reverse(void);
|
|||
|
||||
void audio_driver_set_buffer_size(size_t bufsize);
|
||||
|
||||
void audio_driver_set_callback(const void *info);
|
||||
|
||||
bool audio_driver_has_callback(void);
|
||||
|
||||
void audio_driver_callback(void);
|
||||
|
||||
void audio_driver_callback_set_state(bool state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -73,8 +73,6 @@ static void audio_thread_loop(void *data)
|
|||
|
||||
for (;;)
|
||||
{
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
slock_lock(thr->lock);
|
||||
|
||||
if (!thr->alive)
|
||||
|
@ -93,7 +91,7 @@ static void audio_thread_loop(void *data)
|
|||
}
|
||||
|
||||
slock_unlock(thr->lock);
|
||||
global->system.audio_callback.callback();
|
||||
audio_driver_callback();
|
||||
}
|
||||
|
||||
RARCH_LOG("[Audio Thread]: Tearing down driver.\n");
|
||||
|
@ -165,14 +163,13 @@ static bool audio_thread_alive(void *data)
|
|||
static bool audio_thread_stop(void *data)
|
||||
{
|
||||
audio_thread_t *thr = (audio_thread_t*)data;
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
if (!thr)
|
||||
return false;
|
||||
|
||||
audio_thread_block(thr);
|
||||
thr->is_paused = true;
|
||||
global->system.audio_callback.set_state(false);
|
||||
audio_driver_callback_set_state(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -180,12 +177,11 @@ static bool audio_thread_stop(void *data)
|
|||
static bool audio_thread_start(void *data)
|
||||
{
|
||||
audio_thread_t *thr = (audio_thread_t*)data;
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
if (!thr)
|
||||
return false;
|
||||
|
||||
global->system.audio_callback.set_state(true);
|
||||
audio_driver_callback_set_state(true);
|
||||
thr->is_paused = false;
|
||||
audio_thread_unblock(thr);
|
||||
|
||||
|
|
|
@ -910,7 +910,7 @@ bool rarch_environment_cb(unsigned cmd, void *data)
|
|||
return false;
|
||||
#endif
|
||||
|
||||
global->system.audio_callback = *info;
|
||||
audio_driver_set_callback(info);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
|
2
rewind.c
2
rewind.c
|
@ -542,7 +542,7 @@ void init_rewind(void)
|
|||
if (!settings->rewind_enable || global->rewind.state)
|
||||
return;
|
||||
|
||||
if (global->system.audio_callback.callback)
|
||||
if (audio_driver_has_callback())
|
||||
{
|
||||
RARCH_ERR(RETRO_LOG_REWIND_INIT_FAILED_THREADED_AUDIO);
|
||||
return;
|
||||
|
|
|
@ -186,8 +186,6 @@ typedef struct global
|
|||
|
||||
retro_keyboard_event_t key_event;
|
||||
|
||||
struct retro_audio_callback audio_callback;
|
||||
|
||||
struct retro_disk_control_callback disk_control;
|
||||
struct retro_hw_render_callback hw_render_callback;
|
||||
struct retro_camera_callback camera_callback;
|
||||
|
|
Loading…
Add table
Reference in a new issue