2013-02-08 10:50:45 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2016-01-10 03:06:50 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2013-02-08 10:50:45 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-20 16:34:19 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <string/stdstring.h>
|
2016-05-10 18:31:27 +00:00
|
|
|
#include <features/features_cpu.h>
|
2016-01-20 16:34:19 +00:00
|
|
|
|
2015-01-12 21:11:13 +00:00
|
|
|
#include "audio_resampler_driver.h"
|
2016-03-21 17:49:50 +00:00
|
|
|
#include "../config_file_userdata.h"
|
2016-05-10 06:53:14 +00:00
|
|
|
#include "../performance_counters.h"
|
2016-03-20 16:28:24 +00:00
|
|
|
#include "../list_special.h"
|
2013-02-08 10:50:45 +00:00
|
|
|
|
2014-08-15 16:17:44 +00:00
|
|
|
static const rarch_resampler_t *resampler_drivers[] = {
|
2014-04-20 04:26:48 +00:00
|
|
|
&sinc_resampler,
|
2014-03-14 15:53:04 +00:00
|
|
|
&CC_resampler,
|
2014-09-12 22:10:15 +00:00
|
|
|
&nearest_resampler,
|
2016-03-14 14:42:12 +00:00
|
|
|
&null_resampler,
|
2014-02-25 08:39:48 +00:00
|
|
|
NULL,
|
2014-02-25 01:55:05 +00:00
|
|
|
};
|
|
|
|
|
2014-09-26 15:05:24 +00:00
|
|
|
static const struct resampler_config resampler_config = {
|
|
|
|
config_userdata_get_float,
|
|
|
|
config_userdata_get_int,
|
|
|
|
config_userdata_get_float_array,
|
|
|
|
config_userdata_get_int_array,
|
|
|
|
config_userdata_get_string,
|
|
|
|
config_userdata_free,
|
|
|
|
};
|
|
|
|
|
2015-01-09 22:04:05 +00:00
|
|
|
/**
|
|
|
|
* find_resampler_driver_index:
|
|
|
|
* @ident : Identifier of resampler driver to find.
|
|
|
|
*
|
|
|
|
* Finds resampler driver index by @ident name.
|
|
|
|
*
|
|
|
|
* Returns: resampler driver index if resampler driver was found, otherwise
|
|
|
|
* -1.
|
|
|
|
**/
|
|
|
|
static int find_resampler_driver_index(const char *ident)
|
2014-02-25 02:23:50 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2015-01-09 22:04:05 +00:00
|
|
|
|
2014-08-15 16:17:44 +00:00
|
|
|
for (i = 0; resampler_drivers[i]; i++)
|
2016-01-20 16:34:19 +00:00
|
|
|
if (string_is_equal_noncase(ident, resampler_drivers[i]->ident))
|
2014-02-25 02:23:50 +00:00
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-01-09 22:04:05 +00:00
|
|
|
/**
|
2015-01-12 20:12:48 +00:00
|
|
|
* audio_resampler_driver_find_handle:
|
2015-01-15 20:10:36 +00:00
|
|
|
* @idx : index of driver to get handle to.
|
2015-01-09 22:04:05 +00:00
|
|
|
*
|
2015-01-12 20:12:48 +00:00
|
|
|
* Returns: handle to audio resampler driver at index. Can be NULL
|
|
|
|
* if nothing found.
|
2015-01-09 22:04:05 +00:00
|
|
|
**/
|
2015-01-15 20:10:36 +00:00
|
|
|
const void *audio_resampler_driver_find_handle(int idx)
|
2014-02-25 02:23:50 +00:00
|
|
|
{
|
2015-01-15 20:10:36 +00:00
|
|
|
const void *drv = resampler_drivers[idx];
|
2015-01-12 20:12:48 +00:00
|
|
|
if (!drv)
|
|
|
|
return NULL;
|
|
|
|
return drv;
|
2014-02-25 02:23:50 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 22:04:05 +00:00
|
|
|
/**
|
2015-01-12 20:12:48 +00:00
|
|
|
* audio_resampler_driver_find_ident:
|
2015-01-15 20:10:36 +00:00
|
|
|
* @idx : index of driver to get handle to.
|
2015-01-09 22:04:05 +00:00
|
|
|
*
|
2015-01-12 20:12:48 +00:00
|
|
|
* Returns: Human-readable identifier of audio resampler driver at index.
|
|
|
|
* Can be NULL if nothing found.
|
2015-01-09 22:04:05 +00:00
|
|
|
**/
|
2015-01-15 20:10:36 +00:00
|
|
|
const char *audio_resampler_driver_find_ident(int idx)
|
2014-02-25 02:23:50 +00:00
|
|
|
{
|
2015-01-15 20:10:36 +00:00
|
|
|
const rarch_resampler_t *drv = resampler_drivers[idx];
|
2015-01-12 20:12:48 +00:00
|
|
|
if (!drv)
|
|
|
|
return NULL;
|
|
|
|
return drv->ident;
|
2014-02-25 02:23:50 +00:00
|
|
|
}
|
2014-12-31 19:17:53 +00:00
|
|
|
|
2015-01-09 22:04:05 +00:00
|
|
|
/**
|
|
|
|
* config_get_audio_resampler_driver_options:
|
|
|
|
*
|
|
|
|
* Get an enumerated list of all resampler driver names, separated by '|'.
|
|
|
|
*
|
|
|
|
* Returns: string listing of all resampler driver names, separated by '|'.
|
|
|
|
**/
|
2014-12-31 19:17:53 +00:00
|
|
|
const char* config_get_audio_resampler_driver_options(void)
|
|
|
|
{
|
2015-10-26 18:41:20 +00:00
|
|
|
return char_list_new_special(STRING_LIST_AUDIO_RESAMPLER_DRIVERS, NULL);
|
2014-12-31 19:17:53 +00:00
|
|
|
}
|
2014-02-25 08:39:48 +00:00
|
|
|
|
2015-01-09 22:04:05 +00:00
|
|
|
/**
|
|
|
|
* find_resampler_driver:
|
|
|
|
* @ident : Identifier of resampler driver to find.
|
|
|
|
*
|
|
|
|
* Finds resampler by @ident name.
|
|
|
|
*
|
|
|
|
* Returns: resampler driver if resampler driver was found, otherwise
|
|
|
|
* NULL.
|
|
|
|
**/
|
2014-09-23 05:20:10 +00:00
|
|
|
static const rarch_resampler_t *find_resampler_driver(const char *ident)
|
|
|
|
{
|
|
|
|
int i = find_resampler_driver_index(ident);
|
2015-01-09 22:04:05 +00:00
|
|
|
|
2014-09-23 05:20:10 +00:00
|
|
|
if (i >= 0)
|
|
|
|
return resampler_drivers[i];
|
2015-01-09 22:04:05 +00:00
|
|
|
|
|
|
|
return resampler_drivers[0];
|
2014-09-23 05:20:10 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 14:54:45 +00:00
|
|
|
static resampler_simd_mask_t resampler_get_cpu_features(void)
|
2015-02-05 18:04:46 +00:00
|
|
|
{
|
2016-05-10 07:17:04 +00:00
|
|
|
return cpu_features_get();
|
2015-02-05 18:04:46 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 22:04:05 +00:00
|
|
|
/**
|
|
|
|
* resampler_append_plugs:
|
|
|
|
* @re : Resampler handle
|
|
|
|
* @backend : Resampler backend that is about to be set.
|
|
|
|
* @bw_ratio : Bandwidth ratio.
|
|
|
|
*
|
|
|
|
* Initializes resampler driver based on queried CPU features.
|
|
|
|
*
|
|
|
|
* Returns: true (1) if successfully initialized, otherwise false (0).
|
|
|
|
**/
|
2014-09-26 14:13:10 +00:00
|
|
|
static bool resampler_append_plugs(void **re,
|
|
|
|
const rarch_resampler_t **backend,
|
|
|
|
double bw_ratio)
|
|
|
|
{
|
2015-02-05 18:04:46 +00:00
|
|
|
resampler_simd_mask_t mask = resampler_get_cpu_features();
|
2014-09-26 14:13:10 +00:00
|
|
|
|
2014-09-26 15:05:24 +00:00
|
|
|
*re = (*backend)->init(&resampler_config, bw_ratio, mask);
|
2014-09-26 14:13:10 +00:00
|
|
|
|
|
|
|
if (!*re)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-09 22:04:05 +00:00
|
|
|
/**
|
|
|
|
* rarch_resampler_realloc:
|
|
|
|
* @re : Resampler handle
|
|
|
|
* @backend : Resampler backend that is about to be set.
|
|
|
|
* @ident : Identifier name for resampler we want.
|
|
|
|
* @bw_ratio : Bandwidth ratio.
|
|
|
|
*
|
|
|
|
* Reallocates resampler. Will free previous handle before
|
|
|
|
* allocating a new one. If ident is NULL, first resampler will be used.
|
|
|
|
*
|
|
|
|
* Returns: true (1) if successful, otherwise false (0).
|
|
|
|
**/
|
2014-09-09 03:56:12 +00:00
|
|
|
bool rarch_resampler_realloc(void **re, const rarch_resampler_t **backend,
|
|
|
|
const char *ident, double bw_ratio)
|
2014-02-25 08:39:48 +00:00
|
|
|
{
|
|
|
|
if (*re && *backend)
|
|
|
|
(*backend)->free(*re);
|
|
|
|
|
|
|
|
*re = NULL;
|
2014-02-25 08:56:39 +00:00
|
|
|
*backend = find_resampler_driver(ident);
|
2014-07-18 17:11:53 +00:00
|
|
|
|
2014-09-26 14:13:10 +00:00
|
|
|
if (!resampler_append_plugs(re, backend, bw_ratio))
|
|
|
|
goto error;
|
2014-02-25 08:51:24 +00:00
|
|
|
|
2014-09-26 14:13:10 +00:00
|
|
|
return true;
|
2014-02-25 08:39:48 +00:00
|
|
|
|
2014-09-26 14:13:10 +00:00
|
|
|
error:
|
2014-02-25 08:39:48 +00:00
|
|
|
if (!*re)
|
|
|
|
*backend = NULL;
|
2014-09-26 14:13:10 +00:00
|
|
|
return false;
|
2014-02-25 08:39:48 +00:00
|
|
|
}
|