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
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "resampler.h"
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../general.h"
|
|
|
|
|
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-23 13:27:31 +00:00
|
|
|
#ifdef HAVE_CC_RESAMPLER
|
2014-03-14 15:53:04 +00:00
|
|
|
&CC_resampler,
|
|
|
|
#endif
|
2014-02-25 08:39:48 +00:00
|
|
|
NULL,
|
2014-02-25 01:55:05 +00:00
|
|
|
};
|
|
|
|
|
2014-02-25 02:23:50 +00:00
|
|
|
static int find_resampler_driver_index(const char *driver)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2014-08-15 16:17:44 +00:00
|
|
|
for (i = 0; resampler_drivers[i]; i++)
|
|
|
|
if (strcasecmp(driver, resampler_drivers[i]->ident) == 0)
|
2014-02-25 02:23:50 +00:00
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-25 08:51:24 +00:00
|
|
|
// Resampler is used by multiple modules so avoid clobbering g_extern.audio_data.resampler here.
|
2014-02-25 08:56:39 +00:00
|
|
|
static const rarch_resampler_t *find_resampler_driver(const char *ident)
|
2014-02-25 02:23:50 +00:00
|
|
|
{
|
2014-07-18 17:17:59 +00:00
|
|
|
int i = find_resampler_driver_index(ident);
|
2014-02-25 02:23:50 +00:00
|
|
|
if (i >= 0)
|
2014-08-15 16:17:44 +00:00
|
|
|
return resampler_drivers[i];
|
2014-02-25 02:23:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned d;
|
2014-02-25 08:56:39 +00:00
|
|
|
RARCH_ERR("Couldn't find any resampler driver named \"%s\"\n", ident);
|
2014-02-25 02:27:17 +00:00
|
|
|
RARCH_LOG_OUTPUT("Available resampler drivers are:\n");
|
2014-08-15 16:17:44 +00:00
|
|
|
for (d = 0; resampler_drivers[d]; d++)
|
|
|
|
RARCH_LOG_OUTPUT("\t%s\n", resampler_drivers[d]->ident);
|
|
|
|
|
2014-07-18 16:39:35 +00:00
|
|
|
RARCH_WARN("Going to default to first resampler driver ...\n");
|
2014-08-15 16:17:44 +00:00
|
|
|
|
|
|
|
return resampler_drivers[0];
|
2014-02-25 02:23:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-23 13:27:31 +00:00
|
|
|
#ifndef RESAMPLER_TEST
|
2014-02-25 02:23:50 +00:00
|
|
|
void find_prev_resampler_driver(void)
|
|
|
|
{
|
|
|
|
int i = find_resampler_driver_index(g_settings.audio.resampler);
|
|
|
|
if (i > 0)
|
2014-08-15 16:17:44 +00:00
|
|
|
strlcpy(g_settings.audio.resampler, resampler_drivers[i - 1]->ident, sizeof(g_settings.audio.resampler));
|
2014-02-25 02:23:50 +00:00
|
|
|
else
|
|
|
|
RARCH_WARN("Couldn't find any previous resampler driver (current one: \"%s\").\n", g_extern.audio_data.resampler->ident);
|
|
|
|
}
|
|
|
|
|
|
|
|
void find_next_resampler_driver(void)
|
|
|
|
{
|
|
|
|
int i = find_resampler_driver_index(g_settings.audio.resampler);
|
2014-08-15 16:17:44 +00:00
|
|
|
if (i >= 0 && resampler_drivers[i + 1])
|
|
|
|
strlcpy(g_settings.audio.resampler, resampler_drivers[i + 1]->ident, sizeof(g_settings.audio.resampler));
|
2014-02-25 02:23:50 +00:00
|
|
|
else
|
|
|
|
RARCH_WARN("Couldn't find any next resampler driver (current one: \"%s\").\n", g_extern.audio_data.resampler->ident);
|
|
|
|
}
|
2014-03-23 13:27:31 +00:00
|
|
|
#endif
|
2014-02-25 08:39:48 +00:00
|
|
|
|
|
|
|
bool rarch_resampler_realloc(void **re, const rarch_resampler_t **backend, const char *ident, double bw_ratio)
|
|
|
|
{
|
|
|
|
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-02-25 08:51:24 +00:00
|
|
|
if (!*backend)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*re = (*backend)->init(bw_ratio);
|
2014-02-25 08:39:48 +00:00
|
|
|
|
|
|
|
if (!*re)
|
|
|
|
{
|
|
|
|
*backend = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|