2015-01-12 17:06:38 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <string/string_list.h>
|
|
|
|
#include "audio_driver.h"
|
2015-05-19 19:18:07 +00:00
|
|
|
#include "audio_monitor.h"
|
2015-01-12 23:19:46 +00:00
|
|
|
#include "audio_utils.h"
|
2015-01-12 17:09:31 +00:00
|
|
|
#include "audio_thread_wrapper.h"
|
|
|
|
#include "../driver.h"
|
|
|
|
#include "../general.h"
|
|
|
|
#include "../retroarch.h"
|
2015-03-15 01:47:23 +00:00
|
|
|
#include "../runloop.h"
|
2015-05-19 19:18:07 +00:00
|
|
|
#include "../performance.h"
|
|
|
|
#include "../intl/intl.h"
|
|
|
|
|
2015-05-20 03:27:53 +00:00
|
|
|
#ifndef AUDIO_BUFFER_FREE_SAMPLES_COUNT
|
|
|
|
#define AUDIO_BUFFER_FREE_SAMPLES_COUNT (8 * 1024)
|
|
|
|
#endif
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
typedef struct audio_driver_input_data
|
|
|
|
{
|
|
|
|
float *data;
|
|
|
|
|
|
|
|
size_t data_ptr;
|
|
|
|
size_t chunk_size;
|
|
|
|
size_t nonblock_chunk_size;
|
|
|
|
size_t block_chunk_size;
|
|
|
|
|
|
|
|
double src_ratio;
|
|
|
|
float in_rate;
|
|
|
|
|
|
|
|
bool use_float;
|
|
|
|
|
|
|
|
float *outsamples;
|
|
|
|
int16_t *conv_outsamples;
|
|
|
|
|
|
|
|
int16_t *rewind_buf;
|
|
|
|
size_t rewind_ptr;
|
|
|
|
size_t rewind_size;
|
|
|
|
|
|
|
|
rarch_dsp_filter_t *dsp;
|
|
|
|
|
|
|
|
bool rate_control;
|
|
|
|
double orig_src_ratio;
|
|
|
|
size_t driver_buffer_size;
|
|
|
|
|
|
|
|
float volume_gain;
|
2015-05-19 19:35:40 +00:00
|
|
|
struct retro_audio_callback audio_callback;
|
2015-05-20 03:27:53 +00:00
|
|
|
|
|
|
|
unsigned buffer_free_samples[AUDIO_BUFFER_FREE_SAMPLES_COUNT];
|
|
|
|
uint64_t buffer_free_samples_count;
|
2015-05-19 19:18:07 +00:00
|
|
|
} audio_driver_input_data_t;
|
|
|
|
|
|
|
|
static audio_driver_input_data_t audio_data;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
|
|
|
static const audio_driver_t *audio_drivers[] = {
|
|
|
|
#ifdef HAVE_ALSA
|
|
|
|
&audio_alsa,
|
|
|
|
#ifndef __QNX__
|
|
|
|
&audio_alsathread,
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_OSS) || defined(HAVE_OSS_BSD)
|
|
|
|
&audio_oss,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_RSOUND
|
|
|
|
&audio_rsound,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_COREAUDIO
|
|
|
|
&audio_coreaudio,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_AL
|
|
|
|
&audio_openal,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SL
|
|
|
|
&audio_opensl,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ROAR
|
|
|
|
&audio_roar,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_JACK
|
|
|
|
&audio_jack,
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_SDL) || defined(HAVE_SDL2)
|
|
|
|
&audio_sdl,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_XAUDIO
|
|
|
|
&audio_xa,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_DSOUND
|
|
|
|
&audio_dsound,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PULSE
|
|
|
|
&audio_pulse,
|
|
|
|
#endif
|
|
|
|
#ifdef __CELLOS_LV2__
|
|
|
|
&audio_ps3,
|
|
|
|
#endif
|
|
|
|
#ifdef XENON
|
|
|
|
&audio_xenon360,
|
|
|
|
#endif
|
|
|
|
#ifdef GEKKO
|
|
|
|
&audio_gx,
|
|
|
|
#endif
|
|
|
|
#ifdef EMSCRIPTEN
|
|
|
|
&audio_rwebaudio,
|
|
|
|
#endif
|
|
|
|
#ifdef PSP
|
|
|
|
&audio_psp1,
|
|
|
|
#endif
|
2015-04-01 21:14:13 +00:00
|
|
|
#ifdef _3DS
|
|
|
|
&audio_ctr,
|
|
|
|
#endif
|
2015-01-12 17:06:38 +00:00
|
|
|
&audio_null,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2015-04-11 04:48:30 +00:00
|
|
|
static const audio_driver_t * audio_get_ptr(const driver_t *driver)
|
|
|
|
{
|
|
|
|
if (driver->audio)
|
|
|
|
return driver->audio;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-01-12 17:06:38 +00:00
|
|
|
/**
|
|
|
|
* compute_audio_buffer_statistics:
|
|
|
|
*
|
|
|
|
* Computes audio buffer statistics.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
static void compute_audio_buffer_statistics(void)
|
|
|
|
{
|
|
|
|
unsigned i, low_water_size, high_water_size, avg, stddev;
|
|
|
|
float avg_filled, deviation;
|
|
|
|
uint64_t accum = 0, accum_var = 0;
|
|
|
|
unsigned low_water_count = 0, high_water_count = 0;
|
2015-03-18 05:47:22 +00:00
|
|
|
unsigned samples = 0;
|
|
|
|
|
2015-05-20 03:27:53 +00:00
|
|
|
samples = min(audio_data.buffer_free_samples_count,
|
2015-01-12 17:06:38 +00:00
|
|
|
AUDIO_BUFFER_FREE_SAMPLES_COUNT);
|
|
|
|
|
|
|
|
if (samples < 3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 1; i < samples; i++)
|
2015-05-20 03:27:53 +00:00
|
|
|
accum += audio_data.buffer_free_samples[i];
|
2015-01-12 17:06:38 +00:00
|
|
|
|
|
|
|
avg = accum / (samples - 1);
|
|
|
|
|
|
|
|
for (i = 1; i < samples; i++)
|
|
|
|
{
|
2015-05-20 03:27:53 +00:00
|
|
|
int diff = avg - audio_data.buffer_free_samples[i];
|
2015-01-12 17:06:38 +00:00
|
|
|
accum_var += diff * diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
stddev = (unsigned)sqrt((double)accum_var / (samples - 2));
|
2015-05-19 19:18:07 +00:00
|
|
|
avg_filled = 1.0f - (float)avg / audio_data.driver_buffer_size;
|
|
|
|
deviation = (float)stddev / audio_data.driver_buffer_size;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
low_water_size = audio_data.driver_buffer_size * 3 / 4;
|
|
|
|
high_water_size = audio_data.driver_buffer_size / 4;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
|
|
|
for (i = 1; i < samples; i++)
|
|
|
|
{
|
2015-05-20 03:27:53 +00:00
|
|
|
if (audio_data.buffer_free_samples[i] >= low_water_size)
|
2015-01-12 17:06:38 +00:00
|
|
|
low_water_count++;
|
2015-05-20 03:27:53 +00:00
|
|
|
else if (audio_data.buffer_free_samples[i] <= high_water_size)
|
2015-01-12 17:06:38 +00:00
|
|
|
high_water_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
RARCH_LOG("Average audio buffer saturation: %.2f %%, standard deviation (percentage points): %.2f %%.\n",
|
|
|
|
avg_filled * 100.0, deviation * 100.0);
|
|
|
|
RARCH_LOG("Amount of time spent close to underrun: %.2f %%. Close to blocking: %.2f %%.\n",
|
|
|
|
(100.0 * low_water_count) / (samples - 1),
|
|
|
|
(100.0 * high_water_count) / (samples - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* audio_driver_find_handle:
|
2015-01-15 20:10:36 +00:00
|
|
|
* @idx : index of driver to get handle to.
|
2015-01-12 17:06:38 +00:00
|
|
|
*
|
|
|
|
* Returns: handle to audio driver at index. Can be NULL
|
|
|
|
* if nothing found.
|
|
|
|
**/
|
2015-01-15 20:10:36 +00:00
|
|
|
const void *audio_driver_find_handle(int idx)
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
2015-01-15 20:10:36 +00:00
|
|
|
const void *drv = audio_drivers[idx];
|
2015-01-12 17:06:38 +00:00
|
|
|
if (!drv)
|
|
|
|
return NULL;
|
|
|
|
return drv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* audio_driver_find_ident:
|
2015-01-15 20:10:36 +00:00
|
|
|
* @idx : index of driver to get handle to.
|
2015-01-12 17:06:38 +00:00
|
|
|
*
|
|
|
|
* Returns: Human-readable identifier of audio driver at index. Can be NULL
|
|
|
|
* if nothing found.
|
|
|
|
**/
|
2015-01-15 20:10:36 +00:00
|
|
|
const char *audio_driver_find_ident(int idx)
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
2015-01-15 20:10:36 +00:00
|
|
|
const audio_driver_t *drv = audio_drivers[idx];
|
2015-01-12 17:06:38 +00:00
|
|
|
if (!drv)
|
|
|
|
return NULL;
|
|
|
|
return drv->ident;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* config_get_audio_driver_options:
|
|
|
|
*
|
|
|
|
* Get an enumerated list of all audio driver names, separated by '|'.
|
|
|
|
*
|
|
|
|
* Returns: string listing of all audio driver names, separated by '|'.
|
|
|
|
**/
|
|
|
|
const char* config_get_audio_driver_options(void)
|
|
|
|
{
|
|
|
|
union string_list_elem_attr attr;
|
|
|
|
unsigned i;
|
|
|
|
char *options = NULL;
|
|
|
|
int options_len = 0;
|
|
|
|
struct string_list *options_l = string_list_new();
|
|
|
|
|
|
|
|
attr.i = 0;
|
|
|
|
|
2015-01-30 06:48:05 +00:00
|
|
|
if (!options_l)
|
|
|
|
return NULL;
|
|
|
|
|
2015-01-12 17:06:38 +00:00
|
|
|
for (i = 0; audio_driver_find_handle(i); i++)
|
|
|
|
{
|
|
|
|
const char *opt = audio_driver_find_ident(i);
|
|
|
|
options_len += strlen(opt) + 1;
|
|
|
|
string_list_append(options_l, opt, attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
options = (char*)calloc(options_len, sizeof(char));
|
|
|
|
|
2015-01-29 19:33:27 +00:00
|
|
|
if (!options)
|
|
|
|
{
|
|
|
|
string_list_free(options_l);
|
2015-01-30 06:48:05 +00:00
|
|
|
options_l = NULL;
|
2015-01-29 19:33:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-01-12 17:06:38 +00:00
|
|
|
string_list_join_concat(options, options_len, options_l, "|");
|
|
|
|
|
|
|
|
string_list_free(options_l);
|
|
|
|
options_l = NULL;
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
void find_audio_driver(void)
|
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
|
|
|
int i = find_driver_index("audio_driver", settings->audio.driver);
|
2015-03-18 18:40:00 +00:00
|
|
|
|
2015-01-12 17:06:38 +00:00
|
|
|
if (i >= 0)
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->audio = (const audio_driver_t*)audio_driver_find_handle(i);
|
2015-01-12 17:06:38 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned d;
|
|
|
|
RARCH_ERR("Couldn't find any audio driver named \"%s\"\n",
|
2015-03-20 18:48:23 +00:00
|
|
|
settings->audio.driver);
|
2015-01-12 17:06:38 +00:00
|
|
|
RARCH_LOG_OUTPUT("Available audio drivers are:\n");
|
|
|
|
for (d = 0; audio_driver_find_handle(d); d++)
|
|
|
|
RARCH_LOG_OUTPUT("\t%s\n", audio_driver_find_ident(d));
|
|
|
|
RARCH_WARN("Going to default to first audio driver...\n");
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->audio = (const audio_driver_t*)audio_driver_find_handle(0);
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!driver->audio)
|
2015-01-12 17:06:38 +00:00
|
|
|
rarch_fail(1, "find_audio_driver()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void uninit_audio(void)
|
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-03-18 18:40:00 +00:00
|
|
|
|
|
|
|
if (driver->audio_data && driver->audio)
|
|
|
|
driver->audio->free(driver->audio_data);
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
free(audio_data.conv_outsamples);
|
|
|
|
audio_data.conv_outsamples = NULL;
|
|
|
|
audio_data.data_ptr = 0;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
free(audio_data.rewind_buf);
|
|
|
|
audio_data.rewind_buf = NULL;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
if (!settings->audio.enable)
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->audio_active = false;
|
2015-01-12 17:06:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
rarch_resampler_freep(&driver->resampler,
|
|
|
|
&driver->resampler_data);
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
free(audio_data.data);
|
|
|
|
audio_data.data = NULL;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
free(audio_data.outsamples);
|
|
|
|
audio_data.outsamples = NULL;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_DSP_FILTER_DEINIT);
|
2015-01-12 17:06:38 +00:00
|
|
|
|
|
|
|
compute_audio_buffer_statistics();
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_audio(void)
|
|
|
|
{
|
|
|
|
size_t outsamples_max, max_bufsamples = AUDIO_CHUNK_SIZE_NONBLOCKING * 2;
|
2015-03-20 18:48:23 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-01-12 17:06:38 +00:00
|
|
|
|
|
|
|
audio_convert_init_simd();
|
|
|
|
|
|
|
|
/* Resource leaks will follow if audio is initialized twice. */
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->audio_data)
|
2015-01-12 17:06:38 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Accomodate rewind since at some point we might have two full buffers. */
|
|
|
|
outsamples_max = max_bufsamples * AUDIO_MAX_RATIO *
|
2015-03-20 18:48:23 +00:00
|
|
|
settings->slowmotion_ratio;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
|
|
|
/* Used for recording even if audio isn't enabled. */
|
2015-05-19 19:18:07 +00:00
|
|
|
rarch_assert(audio_data.conv_outsamples =
|
2015-01-12 17:06:38 +00:00
|
|
|
(int16_t*)malloc(outsamples_max * sizeof(int16_t)));
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
if (!audio_data.conv_outsamples)
|
2015-03-21 03:43:18 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.block_chunk_size = AUDIO_CHUNK_SIZE_BLOCKING;
|
|
|
|
audio_data.nonblock_chunk_size = AUDIO_CHUNK_SIZE_NONBLOCKING;
|
|
|
|
audio_data.chunk_size = audio_data.block_chunk_size;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
|
|
|
/* Needs to be able to hold full content of a full max_bufsamples
|
|
|
|
* in addition to its own. */
|
2015-05-19 19:18:07 +00:00
|
|
|
rarch_assert(audio_data.rewind_buf = (int16_t*)
|
2015-01-12 17:06:38 +00:00
|
|
|
malloc(max_bufsamples * sizeof(int16_t)));
|
2015-03-21 03:43:18 +00:00
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
if (!audio_data.rewind_buf)
|
2015-03-21 03:43:18 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.rewind_size = max_bufsamples;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
if (!settings->audio.enable)
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->audio_active = false;
|
2015-01-12 17:06:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
find_audio_driver();
|
|
|
|
#ifdef HAVE_THREADS
|
2015-05-19 19:35:40 +00:00
|
|
|
if (audio_data.audio_callback.callback)
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
|
|
|
RARCH_LOG("Starting threaded audio driver ...\n");
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!rarch_threaded_audio_init(&driver->audio, &driver->audio_data,
|
2015-03-20 18:48:23 +00:00
|
|
|
*settings->audio.device ? settings->audio.device : NULL,
|
|
|
|
settings->audio.out_rate, settings->audio.latency,
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->audio))
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("Cannot open threaded audio driver ... Exiting ...\n");
|
|
|
|
rarch_fail(1, "init_audio()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
driver->audio_data = driver->audio->init(*settings->audio.device ?
|
|
|
|
settings->audio.device : NULL,
|
|
|
|
settings->audio.out_rate, settings->audio.latency);
|
2015-01-12 17:06:38 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!driver->audio_data)
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to initialize audio driver. Will continue without audio.\n");
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->audio_active = false;
|
2015-01-12 17:06:38 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.use_float = false;
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->audio_active && driver->audio->use_float(driver->audio_data))
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.use_float = true;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
if (!settings->audio.sync && driver->audio_active)
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_AUDIO_SET_NONBLOCKING_STATE);
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.chunk_size = audio_data.nonblock_chunk_size;
|
2015-01-12 17:06:38 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
if (audio_data.in_rate <= 0.0f)
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
|
|
|
/* Should never happen. */
|
|
|
|
RARCH_WARN("Input rate is invalid (%.3f Hz). Using output rate (%u Hz).\n",
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.in_rate, settings->audio.out_rate);
|
|
|
|
audio_data.in_rate = settings->audio.out_rate;
|
2015-01-12 17:06:38 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.orig_src_ratio = audio_data.src_ratio =
|
|
|
|
(double)settings->audio.out_rate / audio_data.in_rate;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!rarch_resampler_realloc(&driver->resampler_data,
|
|
|
|
&driver->resampler,
|
2015-05-19 19:18:07 +00:00
|
|
|
settings->audio.resampler, audio_data.orig_src_ratio))
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to initialize resampler \"%s\".\n",
|
2015-03-20 18:48:23 +00:00
|
|
|
settings->audio.resampler);
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->audio_active = false;
|
2015-01-12 17:06:38 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
rarch_assert(audio_data.data = (float*)
|
2015-01-12 17:06:38 +00:00
|
|
|
malloc(max_bufsamples * sizeof(float)));
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
if (!audio_data.data)
|
2015-03-21 03:43:18 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.data_ptr = 0;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
rarch_assert(settings->audio.out_rate <
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.in_rate * AUDIO_MAX_RATIO);
|
|
|
|
rarch_assert(audio_data.outsamples = (float*)
|
2015-01-12 17:06:38 +00:00
|
|
|
malloc(outsamples_max * sizeof(float)));
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
if (!audio_data.outsamples)
|
2015-03-21 03:43:18 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.rate_control = false;
|
2015-05-19 19:35:40 +00:00
|
|
|
if (!audio_data.audio_callback.callback && driver->audio_active &&
|
2015-03-20 18:48:23 +00:00
|
|
|
settings->audio.rate_control)
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
2015-04-11 04:56:02 +00:00
|
|
|
/* Audio rate control requires write_avail
|
|
|
|
* and buffer_size to be implemented. */
|
|
|
|
if (driver->audio->buffer_size)
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.driver_buffer_size =
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->audio->buffer_size(driver->audio_data);
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.rate_control = true;
|
2015-01-12 17:06:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
RARCH_WARN("Audio rate control was desired, but driver does not support needed features.\n");
|
|
|
|
}
|
|
|
|
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_DSP_FILTER_INIT);
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-05-20 03:27:53 +00:00
|
|
|
audio_data.buffer_free_samples_count = 0;
|
2015-01-12 17:06:38 +00:00
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
if (driver->audio_active && !settings->audio.mute_enable &&
|
2015-05-19 19:35:40 +00:00
|
|
|
audio_data.audio_callback.callback)
|
2015-01-12 17:06:38 +00:00
|
|
|
{
|
|
|
|
/* Threaded driver is initially stopped. */
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->audio->start(driver->audio_data);
|
2015-01-12 17:06:38 +00:00
|
|
|
}
|
2015-03-21 03:43:18 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2015-05-19 19:18:07 +00:00
|
|
|
if (audio_data.conv_outsamples)
|
|
|
|
free(audio_data.conv_outsamples);
|
|
|
|
audio_data.conv_outsamples = NULL;
|
|
|
|
if (audio_data.data)
|
|
|
|
free(audio_data.data);
|
|
|
|
audio_data.data = NULL;
|
|
|
|
if (audio_data.rewind_buf)
|
|
|
|
free(audio_data.rewind_buf);
|
|
|
|
audio_data.rewind_buf = NULL;
|
|
|
|
if (audio_data.outsamples)
|
|
|
|
free(audio_data.outsamples);
|
|
|
|
audio_data.outsamples = NULL;
|
2015-01-12 17:06:38 +00:00
|
|
|
}
|
2015-02-10 20:16:26 +00:00
|
|
|
|
|
|
|
bool audio_driver_mute_toggle(void)
|
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!driver->audio_data || !driver->audio_active)
|
2015-02-10 20:16:26 +00:00
|
|
|
return false;
|
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
settings->audio.mute_enable = !settings->audio.mute_enable;
|
2015-02-10 20:16:26 +00:00
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
if (settings->audio.mute_enable)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_AUDIO_STOP);
|
|
|
|
else if (!event_command(EVENT_CMD_AUDIO_START))
|
2015-02-10 20:16:26 +00:00
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->audio_active = false;
|
2015-02-10 20:16:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-11 16:36:31 +00:00
|
|
|
|
2015-03-23 01:31:16 +00:00
|
|
|
static int audio_driver_write_avail(void)
|
|
|
|
{
|
|
|
|
driver_t *driver = driver_get_ptr();
|
2015-04-11 04:48:30 +00:00
|
|
|
const audio_driver_t *audio = audio_get_ptr(driver);
|
|
|
|
|
2015-04-11 04:56:02 +00:00
|
|
|
return audio->write_avail(driver->audio_data);
|
2015-03-23 01:31:16 +00:00
|
|
|
}
|
|
|
|
|
2015-02-11 16:36:31 +00:00
|
|
|
/*
|
|
|
|
* audio_driver_readjust_input_rate:
|
|
|
|
*
|
|
|
|
* Readjust the audio input rate.
|
|
|
|
*/
|
|
|
|
void audio_driver_readjust_input_rate(void)
|
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-05-20 03:27:53 +00:00
|
|
|
unsigned write_idx = audio_data.buffer_free_samples_count++ &
|
2015-03-23 01:31:16 +00:00
|
|
|
(AUDIO_BUFFER_FREE_SAMPLES_COUNT - 1);
|
2015-05-19 19:18:07 +00:00
|
|
|
int half_size = audio_data.driver_buffer_size / 2;
|
2015-03-23 01:31:16 +00:00
|
|
|
int avail = audio_driver_write_avail();
|
|
|
|
int delta_mid = avail - half_size;
|
|
|
|
double direction = (double)delta_mid / half_size;
|
|
|
|
double adjust = 1.0 + settings->audio.rate_control_delta * direction;
|
2015-02-11 16:36:31 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
RARCH_LOG_OUTPUT("Audio buffer is %u%% full\n",
|
2015-05-19 19:18:07 +00:00
|
|
|
(unsigned)(100 - (avail * 100) / audio_data.driver_buffer_size));
|
2015-02-11 16:36:31 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-20 03:27:53 +00:00
|
|
|
audio_data.buffer_free_samples[write_idx] = avail;
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.src_ratio = audio_data.orig_src_ratio * adjust;
|
2015-02-11 16:36:31 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
RARCH_LOG_OUTPUT("New rate: %lf, Orig rate: %lf\n",
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_data.src_ratio, audio_data.orig_src_ratio);
|
2015-02-11 16:36:31 +00:00
|
|
|
#endif
|
|
|
|
}
|
2015-03-23 01:36:13 +00:00
|
|
|
|
|
|
|
bool audio_driver_alive(void)
|
|
|
|
{
|
|
|
|
driver_t *driver = driver_get_ptr();
|
2015-04-11 04:48:30 +00:00
|
|
|
const audio_driver_t *audio = audio_get_ptr(driver);
|
|
|
|
|
|
|
|
return audio->alive(driver->audio_data);
|
2015-03-23 01:36:13 +00:00
|
|
|
}
|
2015-03-23 01:44:49 +00:00
|
|
|
|
2015-04-11 04:48:30 +00:00
|
|
|
|
2015-03-23 01:44:49 +00:00
|
|
|
bool audio_driver_start(void)
|
|
|
|
{
|
2015-04-11 04:48:30 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
const audio_driver_t *audio = audio_get_ptr(driver);
|
|
|
|
|
2015-04-11 06:08:57 +00:00
|
|
|
return audio->start(driver->audio_data);
|
2015-03-23 01:44:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool audio_driver_stop(void)
|
|
|
|
{
|
2015-04-11 04:48:30 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
const audio_driver_t *audio = audio_get_ptr(driver);
|
|
|
|
|
2015-04-11 06:08:57 +00:00
|
|
|
return audio->stop(driver->audio_data);
|
2015-03-23 01:44:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void audio_driver_set_nonblock_state(bool toggle)
|
|
|
|
{
|
|
|
|
driver_t *driver = driver_get_ptr();
|
2015-04-11 06:08:57 +00:00
|
|
|
const audio_driver_t *audio = audio_get_ptr(driver);
|
|
|
|
|
|
|
|
audio->set_nonblock_state(driver->audio_data, toggle);
|
2015-03-23 01:44:49 +00:00
|
|
|
}
|
2015-03-23 01:51:46 +00:00
|
|
|
|
2015-05-19 19:18:07 +00:00
|
|
|
void audio_driver_set_nonblocking_state(bool enable)
|
|
|
|
{
|
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
if (driver->audio_active && driver->audio_data)
|
|
|
|
audio_driver_set_nonblock_state(settings->audio.sync ? enable : true);
|
|
|
|
|
|
|
|
audio_data.chunk_size = enable ? audio_data.nonblock_chunk_size :
|
|
|
|
audio_data.block_chunk_size;
|
|
|
|
}
|
|
|
|
|
2015-03-23 01:51:46 +00:00
|
|
|
ssize_t audio_driver_write(const void *buf, size_t size)
|
|
|
|
{
|
2015-04-11 04:48:30 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
const audio_driver_t *audio = audio_get_ptr(driver);
|
|
|
|
|
|
|
|
return audio->write(driver->audio_data, buf, size);
|
2015-03-23 01:51:46 +00:00
|
|
|
}
|
2015-05-19 19:18:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* audio_driver_flush:
|
|
|
|
* @data : pointer to audio buffer.
|
|
|
|
* @right : amount of samples to write.
|
|
|
|
*
|
|
|
|
* Writes audio samples to audio driver. Will first
|
|
|
|
* perform DSP processing (if enabled) and resampling.
|
|
|
|
*
|
|
|
|
* Returns: true (1) if audio samples were written to the audio
|
|
|
|
* driver, false (0) in case of an error.
|
|
|
|
**/
|
|
|
|
bool audio_driver_flush(const int16_t *data, size_t samples)
|
|
|
|
{
|
|
|
|
const void *output_data = NULL;
|
|
|
|
unsigned output_frames = 0;
|
|
|
|
size_t output_size = sizeof(float);
|
|
|
|
struct resampler_data src_data = {0};
|
|
|
|
struct rarch_dsp_data dsp_data = {0};
|
|
|
|
runloop_t *runloop = rarch_main_get_ptr();
|
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
|
|
|
if (driver->recording_data)
|
|
|
|
{
|
|
|
|
struct ffemu_audio_data ffemu_data = {0};
|
|
|
|
ffemu_data.data = data;
|
|
|
|
ffemu_data.frames = samples / 2;
|
|
|
|
|
|
|
|
if (driver->recording && driver->recording->push_audio)
|
|
|
|
driver->recording->push_audio(driver->recording_data, &ffemu_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (runloop->is_paused || settings->audio.mute_enable)
|
|
|
|
return true;
|
|
|
|
if (!driver->audio_active || !audio_data.data)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
RARCH_PERFORMANCE_INIT(audio_convert_s16);
|
|
|
|
RARCH_PERFORMANCE_START(audio_convert_s16);
|
|
|
|
audio_convert_s16_to_float(audio_data.data, data, samples,
|
|
|
|
audio_data.volume_gain);
|
|
|
|
RARCH_PERFORMANCE_STOP(audio_convert_s16);
|
|
|
|
|
|
|
|
src_data.data_in = audio_data.data;
|
|
|
|
src_data.input_frames = samples >> 1;
|
|
|
|
|
|
|
|
dsp_data.input = audio_data.data;
|
|
|
|
dsp_data.input_frames = samples >> 1;
|
|
|
|
|
|
|
|
if (audio_data.dsp)
|
|
|
|
{
|
|
|
|
RARCH_PERFORMANCE_INIT(audio_dsp);
|
|
|
|
RARCH_PERFORMANCE_START(audio_dsp);
|
|
|
|
rarch_dsp_filter_process(audio_data.dsp, &dsp_data);
|
|
|
|
RARCH_PERFORMANCE_STOP(audio_dsp);
|
|
|
|
|
|
|
|
if (dsp_data.output)
|
|
|
|
{
|
|
|
|
src_data.data_in = dsp_data.output;
|
|
|
|
src_data.input_frames = dsp_data.output_frames;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src_data.data_out = audio_data.outsamples;
|
|
|
|
|
|
|
|
if (audio_data.rate_control)
|
|
|
|
audio_driver_readjust_input_rate();
|
|
|
|
|
|
|
|
src_data.ratio = audio_data.src_ratio;
|
|
|
|
if (runloop->is_slowmotion)
|
|
|
|
src_data.ratio *= settings->slowmotion_ratio;
|
|
|
|
|
|
|
|
RARCH_PERFORMANCE_INIT(resampler_proc);
|
|
|
|
RARCH_PERFORMANCE_START(resampler_proc);
|
|
|
|
rarch_resampler_process(driver->resampler,
|
|
|
|
driver->resampler_data, &src_data);
|
|
|
|
RARCH_PERFORMANCE_STOP(resampler_proc);
|
|
|
|
|
|
|
|
output_data = audio_data.outsamples;
|
|
|
|
output_frames = src_data.output_frames;
|
|
|
|
|
|
|
|
if (!audio_data.use_float)
|
|
|
|
{
|
|
|
|
RARCH_PERFORMANCE_INIT(audio_convert_float);
|
|
|
|
RARCH_PERFORMANCE_START(audio_convert_float);
|
|
|
|
audio_convert_float_to_s16(audio_data.conv_outsamples,
|
|
|
|
(const float*)output_data, output_frames * 2);
|
|
|
|
RARCH_PERFORMANCE_STOP(audio_convert_float);
|
|
|
|
|
|
|
|
output_data = audio_data.conv_outsamples;
|
|
|
|
output_size = sizeof(int16_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (audio_driver_write(output_data, output_frames * output_size * 2) < 0)
|
|
|
|
{
|
|
|
|
RARCH_ERR(RETRO_LOG_AUDIO_WRITE_FAILED);
|
|
|
|
|
|
|
|
driver->audio_active = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* audio_driver_sample:
|
|
|
|
* @left : value of the left audio channel.
|
|
|
|
* @right : value of the right audio channel.
|
|
|
|
*
|
|
|
|
* Audio sample render callback function.
|
|
|
|
**/
|
|
|
|
void audio_driver_sample(int16_t left, int16_t right)
|
|
|
|
{
|
|
|
|
audio_data.conv_outsamples[audio_data.data_ptr++] = left;
|
|
|
|
audio_data.conv_outsamples[audio_data.data_ptr++] = right;
|
|
|
|
|
|
|
|
if (audio_data.data_ptr < audio_data.chunk_size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
audio_driver_flush(audio_data.conv_outsamples, audio_data.data_ptr);
|
|
|
|
|
|
|
|
audio_data.data_ptr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* audio_driver_sample_batch:
|
|
|
|
* @data : pointer to audio buffer.
|
|
|
|
* @frames : amount of audio frames to push.
|
|
|
|
*
|
|
|
|
* Batched audio sample render callback function.
|
|
|
|
*
|
|
|
|
* Returns: amount of frames sampled. Will be equal to @frames
|
|
|
|
* unless @frames exceeds (AUDIO_CHUNK_SIZE_NONBLOCKING / 2).
|
|
|
|
**/
|
|
|
|
size_t audio_driver_sample_batch(const int16_t *data, size_t frames)
|
|
|
|
{
|
|
|
|
if (frames > (AUDIO_CHUNK_SIZE_NONBLOCKING >> 1))
|
|
|
|
frames = AUDIO_CHUNK_SIZE_NONBLOCKING >> 1;
|
|
|
|
|
|
|
|
audio_driver_flush(data, frames << 1);
|
|
|
|
|
|
|
|
return frames;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* audio_driver_sample_rewind:
|
|
|
|
* @left : value of the left audio channel.
|
|
|
|
* @right : value of the right audio channel.
|
|
|
|
*
|
|
|
|
* Audio sample render callback function (rewind version). This callback
|
|
|
|
* function will be used instead of audio_driver_sample when rewinding is activated.
|
|
|
|
**/
|
|
|
|
void audio_driver_sample_rewind(int16_t left, int16_t right)
|
|
|
|
{
|
|
|
|
audio_data.rewind_buf[--audio_data.rewind_ptr] = right;
|
|
|
|
audio_data.rewind_buf[--audio_data.rewind_ptr] = left;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* audio_driver_sample_batch_rewind:
|
|
|
|
* @data : pointer to audio buffer.
|
|
|
|
* @frames : amount of audio frames to push.
|
|
|
|
*
|
|
|
|
* Batched audio sample render callback function (rewind version). This callback
|
|
|
|
* function will be used instead of audio_driver_sample_batch when rewinding is activated.
|
|
|
|
*
|
|
|
|
* Returns: amount of frames sampled. Will be equal to @frames
|
|
|
|
* unless @frames exceeds (AUDIO_CHUNK_SIZE_NONBLOCKING / 2).
|
|
|
|
**/
|
|
|
|
size_t audio_driver_sample_batch_rewind(const int16_t *data, size_t frames)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
size_t samples = frames << 1;
|
|
|
|
|
|
|
|
for (i = 0; i < samples; i++)
|
|
|
|
audio_data.rewind_buf[--audio_data.rewind_ptr] = data[i];
|
|
|
|
|
|
|
|
return frames;
|
|
|
|
}
|
|
|
|
|
|
|
|
void audio_driver_set_volume_gain(float gain)
|
|
|
|
{
|
|
|
|
audio_data.volume_gain = gain;
|
|
|
|
}
|
|
|
|
|
|
|
|
void audio_driver_dsp_filter_free(void)
|
|
|
|
{
|
|
|
|
if (audio_data.dsp)
|
|
|
|
rarch_dsp_filter_free(audio_data.dsp);
|
|
|
|
audio_data.dsp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void audio_driver_dsp_filter_init(const char *device)
|
|
|
|
{
|
|
|
|
audio_data.dsp = rarch_dsp_filter_new(device, audio_data.in_rate);
|
|
|
|
if (!audio_data.dsp)
|
|
|
|
RARCH_ERR("[DSP]: Failed to initialize DSP filter \"%s\".\n", device);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audio_driver_setup_rewind(void)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* Push audio ready to be played. */
|
|
|
|
audio_data.rewind_ptr = audio_data.rewind_size;
|
|
|
|
|
|
|
|
for (i = 0; i < audio_data.data_ptr; i += 2)
|
|
|
|
{
|
|
|
|
audio_data.rewind_buf[--audio_data.rewind_ptr] =
|
|
|
|
audio_data.conv_outsamples[i + 1];
|
|
|
|
|
|
|
|
audio_data.rewind_buf[--audio_data.rewind_ptr] =
|
|
|
|
audio_data.conv_outsamples[i + 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
audio_data.data_ptr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void audio_driver_frame_is_reverse(void)
|
|
|
|
{
|
|
|
|
/* We just rewound. Flush rewind audio buffer. */
|
|
|
|
audio_driver_flush(audio_data.rewind_buf + audio_data.rewind_ptr,
|
|
|
|
audio_data.rewind_size - audio_data.rewind_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
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*)&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);
|
|
|
|
audio_data.in_rate = info->sample_rate;
|
|
|
|
|
|
|
|
if (timing_skew <= settings->audio.max_timing_skew)
|
|
|
|
audio_data.in_rate *= (settings->video.refresh_rate / info->fps);
|
|
|
|
|
|
|
|
RARCH_LOG("Set audio input rate to: %.2f Hz.\n",
|
|
|
|
audio_data.in_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* audio_monitor_set_refresh_rate:
|
|
|
|
*
|
|
|
|
* Sets audio monitor refresh rate to new value.
|
|
|
|
**/
|
|
|
|
void audio_monitor_set_refresh_rate(void)
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
|
|
|
double new_src_ratio = (double)settings->audio.out_rate /
|
|
|
|
audio_data.in_rate;
|
|
|
|
|
|
|
|
audio_data.orig_src_ratio = new_src_ratio;
|
|
|
|
audio_data.src_ratio = new_src_ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
void audio_driver_set_buffer_size(size_t bufsize)
|
|
|
|
{
|
|
|
|
audio_data.driver_buffer_size = bufsize;
|
|
|
|
}
|
2015-05-19 19:35:40 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|