Skip to content

Commit

Permalink
Go through global_get_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Mar 21, 2015
1 parent 3d140cd commit e6f0d36
Show file tree
Hide file tree
Showing 44 changed files with 1,120 additions and 891 deletions.
122 changes: 77 additions & 45 deletions audio/audio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static void compute_audio_buffer_statistics(void)
unsigned low_water_count = 0, high_water_count = 0;
unsigned samples = 0;
runloop_t *runloop = rarch_main_get_ptr();
global_t *global = global_get_ptr();

samples = min(runloop->measure_data.buffer_free_samples_count,
AUDIO_BUFFER_FREE_SAMPLES_COUNT);
Expand All @@ -116,11 +117,11 @@ static void compute_audio_buffer_statistics(void)
}

stddev = (unsigned)sqrt((double)accum_var / (samples - 2));
avg_filled = 1.0f - (float)avg / g_extern.audio_data.driver_buffer_size;
deviation = (float)stddev / g_extern.audio_data.driver_buffer_size;
avg_filled = 1.0f - (float)avg / global->audio_data.driver_buffer_size;
deviation = (float)stddev / global->audio_data.driver_buffer_size;

low_water_size = g_extern.audio_data.driver_buffer_size * 3 / 4;
high_water_size = g_extern.audio_data.driver_buffer_size / 4;
low_water_size = global->audio_data.driver_buffer_size * 3 / 4;
high_water_size = global->audio_data.driver_buffer_size / 4;

for (i = 1; i < samples; i++)
{
Expand Down Expand Up @@ -240,17 +241,18 @@ void find_audio_driver(void)
void uninit_audio(void)
{
driver_t *driver = driver_get_ptr();
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();

if (driver->audio_data && driver->audio)
driver->audio->free(driver->audio_data);

free(g_extern.audio_data.conv_outsamples);
g_extern.audio_data.conv_outsamples = NULL;
g_extern.audio_data.data_ptr = 0;
free(global->audio_data.conv_outsamples);
global->audio_data.conv_outsamples = NULL;
global->audio_data.data_ptr = 0;

free(g_extern.audio_data.rewind_buf);
g_extern.audio_data.rewind_buf = NULL;
free(global->audio_data.rewind_buf);
global->audio_data.rewind_buf = NULL;

if (!settings->audio.enable)
{
Expand All @@ -261,11 +263,11 @@ void uninit_audio(void)
rarch_resampler_freep(&driver->resampler,
&driver->resampler_data);

free(g_extern.audio_data.data);
g_extern.audio_data.data = NULL;
free(global->audio_data.data);
global->audio_data.data = NULL;

free(g_extern.audio_data.outsamples);
g_extern.audio_data.outsamples = NULL;
free(global->audio_data.outsamples);
global->audio_data.outsamples = NULL;

rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT);

Expand All @@ -277,6 +279,7 @@ 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();
Expand All @@ -290,19 +293,25 @@ void init_audio(void)
settings->slowmotion_ratio;

/* Used for recording even if audio isn't enabled. */
rarch_assert(g_extern.audio_data.conv_outsamples =
rarch_assert(global->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;
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(g_extern.audio_data.rewind_buf = (int16_t*)
rarch_assert(global->audio_data.rewind_buf = (int16_t*)
malloc(max_bufsamples * sizeof(int16_t)));
g_extern.audio_data.rewind_size = max_bufsamples;

if (!global->audio_data.rewind_buf)
goto error;

global->audio_data.rewind_size = max_bufsamples;

if (!settings->audio.enable)
{
Expand All @@ -312,7 +321,7 @@ void init_audio(void)

find_audio_driver();
#ifdef HAVE_THREADS
if (g_extern.system.audio_callback.callback)
if (global->system.audio_callback.callback)
{
RARCH_LOG("Starting threaded audio driver ...\n");
if (!rarch_threaded_audio_init(&driver->audio, &driver->audio_data,
Expand All @@ -338,57 +347,63 @@ void init_audio(void)
driver->audio_active = false;
}

g_extern.audio_data.use_float = false;
global->audio_data.use_float = false;
if (driver->audio_active && driver->audio->use_float(driver->audio_data))
g_extern.audio_data.use_float = true;
global->audio_data.use_float = true;

if (!settings->audio.sync && driver->audio_active)
{
rarch_main_command(RARCH_CMD_AUDIO_SET_NONBLOCKING_STATE);
g_extern.audio_data.chunk_size =
g_extern.audio_data.nonblock_chunk_size;
global->audio_data.chunk_size =
global->audio_data.nonblock_chunk_size;
}

if (g_extern.audio_data.in_rate <= 0.0f)
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",
g_extern.audio_data.in_rate, settings->audio.out_rate);
g_extern.audio_data.in_rate = settings->audio.out_rate;
global->audio_data.in_rate, settings->audio.out_rate);
global->audio_data.in_rate = settings->audio.out_rate;
}

g_extern.audio_data.orig_src_ratio =
g_extern.audio_data.src_ratio =
(double)settings->audio.out_rate / g_extern.audio_data.in_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, g_extern.audio_data.orig_src_ratio))
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(g_extern.audio_data.data = (float*)
rarch_assert(global->audio_data.data = (float*)
malloc(max_bufsamples * sizeof(float)));

g_extern.audio_data.data_ptr = 0;
if (!global->audio_data.data)
goto error;

global->audio_data.data_ptr = 0;

rarch_assert(settings->audio.out_rate <
g_extern.audio_data.in_rate * AUDIO_MAX_RATIO);
rarch_assert(g_extern.audio_data.outsamples = (float*)
global->audio_data.in_rate * AUDIO_MAX_RATIO);
rarch_assert(global->audio_data.outsamples = (float*)
malloc(outsamples_max * sizeof(float)));

g_extern.audio_data.rate_control = false;
if (!g_extern.system.audio_callback.callback && driver->audio_active &&
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)
{
g_extern.audio_data.driver_buffer_size =
global->audio_data.driver_buffer_size =
driver->audio->buffer_size(driver->audio_data);
g_extern.audio_data.rate_control = true;
global->audio_data.rate_control = true;
}
else
RARCH_WARN("Audio rate control was desired, but driver does not support needed features.\n");
Expand All @@ -399,11 +414,27 @@ void init_audio(void)
runloop->measure_data.buffer_free_samples_count = 0;

if (driver->audio_active && !settings->audio.mute_enable &&
g_extern.system.audio_callback.callback)
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;
}

bool audio_driver_mute_toggle(void)
Expand Down Expand Up @@ -440,27 +471,28 @@ void audio_driver_readjust_input_rate(void)
int avail = 0;
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();

avail = driver->audio->write_avail(driver->audio_data);

#if 0
RARCH_LOG_OUTPUT("Audio buffer is %u%% full\n",
(unsigned)(100 - (avail * 100) / g_extern.audio_data.driver_buffer_size));
(unsigned)(100 - (avail * 100) / global->audio_data.driver_buffer_size));
#endif

write_idx = runloop->measure_data.buffer_free_samples_count++ &
(AUDIO_BUFFER_FREE_SAMPLES_COUNT - 1);
half_size = g_extern.audio_data.driver_buffer_size / 2;
half_size = global->audio_data.driver_buffer_size / 2;
delta_mid = avail - half_size;
direction = (double)delta_mid / half_size;
adjust = 1.0 + settings->audio.rate_control_delta * direction;

runloop->measure_data.buffer_free_samples[write_idx] = avail;
g_extern.audio_data.src_ratio = g_extern.audio_data.orig_src_ratio * adjust;
global->audio_data.src_ratio = global->audio_data.orig_src_ratio * adjust;

#if 0
RARCH_LOG_OUTPUT("New rate: %lf, Orig rate: %lf\n",
g_extern.audio_data.src_ratio, g_extern.audio_data.orig_src_ratio);
global->audio_data.src_ratio, global->audio_data.orig_src_ratio);
#endif
}
17 changes: 10 additions & 7 deletions audio/audio_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@
void audio_monitor_adjust_system_rates(void)
{
float timing_skew;
global_t *global = global_get_ptr();
const struct retro_system_timing *info =
(const struct retro_system_timing*)&g_extern.system.av_info.timing;
(const struct retro_system_timing*)&global->system.av_info.timing;
settings_t *settings = config_get_ptr();

if (info->sample_rate <= 0.0)
return;

timing_skew = fabs(1.0f - info->fps /
settings->video.refresh_rate);
g_extern.audio_data.in_rate = info->sample_rate;
global->audio_data.in_rate = info->sample_rate;

if (timing_skew <= settings->audio.max_timing_skew)
g_extern.audio_data.in_rate *= (settings->video.refresh_rate / info->fps);
global->audio_data.in_rate *= (settings->video.refresh_rate / info->fps);

RARCH_LOG("Set audio input rate to: %.2f Hz.\n",
g_extern.audio_data.in_rate);
global->audio_data.in_rate);
}

/**
Expand All @@ -46,9 +47,11 @@ void audio_monitor_adjust_system_rates(void)
void audio_monitor_set_refresh_rate(void)
{
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();

double new_src_ratio = (double)settings->audio.out_rate /
g_extern.audio_data.in_rate;
global->audio_data.in_rate;

g_extern.audio_data.orig_src_ratio = new_src_ratio;
g_extern.audio_data.src_ratio = new_src_ratio;
global->audio_data.orig_src_ratio = new_src_ratio;
global->audio_data.src_ratio = new_src_ratio;
}
10 changes: 7 additions & 3 deletions audio/audio_thread_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ static void audio_thread_loop(void *data)

for (;;)
{
global_t *global = global_get_ptr();

slock_lock(thr->lock);

if (!thr->alive)
Expand All @@ -91,7 +93,7 @@ static void audio_thread_loop(void *data)
}

slock_unlock(thr->lock);
g_extern.system.audio_callback.callback();
global->system.audio_callback.callback();
}

RARCH_LOG("[Audio Thread]: Tearing down driver.\n");
Expand Down Expand Up @@ -163,25 +165,27 @@ 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;
g_extern.system.audio_callback.set_state(false);
global->system.audio_callback.set_state(false);

return true;
}

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;

g_extern.system.audio_callback.set_state(true);
global->system.audio_callback.set_state(true);
thr->is_paused = false;
audio_thread_unblock(thr);

Expand Down
5 changes: 3 additions & 2 deletions audio/drivers/ps3_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ static void *ps3_audio_init(const char *device,
unsigned rate, unsigned latency)
{
CellAudioPortParam params;
ps3_audio_t *data;
ps3_audio_t *data = NULL;
global_t *global = global_get_ptr();

(void)latency;
(void)device;
Expand All @@ -95,7 +96,7 @@ static void *ps3_audio_init(const char *device,
params.numChannels = AUDIO_CHANNELS;
params.numBlocks = AUDIO_BLOCKS;
#ifdef HAVE_HEADSET
if(g_extern.console.sound.mode == SOUND_MODE_HEADSET)
if(global->console.sound.mode == SOUND_MODE_HEADSET)
params.param_attrib = CELL_AUDIO_PORTATTR_OUT_SECONDARY;
else
#endif
Expand Down
3 changes: 2 additions & 1 deletion audio/drivers/pulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ static size_t pulse_write_avail(void *data)
{
size_t length;
pa_t *pa = (pa_t*)data;
global_t *global = global_get_ptr();

pa_threaded_mainloop_lock(pa->mainloop);
length = pa_stream_writable_size(pa->stream);
g_extern.audio_data.driver_buffer_size = pa->buffer_size; /* Can change spuriously. */
global->audio_data.driver_buffer_size = pa->buffer_size; /* Can change spuriously. */
pa_threaded_mainloop_unlock(pa->mainloop);
return length;
}
Expand Down
Loading

0 comments on commit e6f0d36

Please sign in to comment.