forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaudio_resampler_driver.c
184 lines (162 loc) · 4.94 KB
/
audio_resampler_driver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2016 - 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/stdstring.h>
#include <features/features_cpu.h>
#include "audio_resampler_driver.h"
#include "../config_file_userdata.h"
#ifdef RARCH_INTERNAL
#include "../performance_counters.h"
#endif
#include "../list_special.h"
static const rarch_resampler_t *resampler_drivers[] = {
&sinc_resampler,
&CC_resampler,
&nearest_resampler,
&null_resampler,
NULL,
};
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,
};
/**
* 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)
{
unsigned i;
for (i = 0; resampler_drivers[i]; i++)
if (string_is_equal_noncase(ident, resampler_drivers[i]->ident))
return i;
return -1;
}
/**
* audio_resampler_driver_find_handle:
* @idx : index of driver to get handle to.
*
* Returns: handle to audio resampler driver at index. Can be NULL
* if nothing found.
**/
const void *audio_resampler_driver_find_handle(int idx)
{
const void *drv = resampler_drivers[idx];
if (!drv)
return NULL;
return drv;
}
/**
* audio_resampler_driver_find_ident:
* @idx : index of driver to get handle to.
*
* Returns: Human-readable identifier of audio resampler driver at index.
* Can be NULL if nothing found.
**/
const char *audio_resampler_driver_find_ident(int idx)
{
const rarch_resampler_t *drv = resampler_drivers[idx];
if (!drv)
return NULL;
return drv->ident;
}
/**
* 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 '|'.
**/
const char* config_get_audio_resampler_driver_options(void)
{
return char_list_new_special(STRING_LIST_AUDIO_RESAMPLER_DRIVERS, NULL);
}
/**
* 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.
**/
static const rarch_resampler_t *find_resampler_driver(const char *ident)
{
int i = find_resampler_driver_index(ident);
if (i >= 0)
return resampler_drivers[i];
return resampler_drivers[0];
}
static resampler_simd_mask_t resampler_get_cpu_features(void)
{
return cpu_features_get();
}
/**
* 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).
**/
static bool resampler_append_plugs(void **re,
const rarch_resampler_t **backend,
double bw_ratio)
{
resampler_simd_mask_t mask = resampler_get_cpu_features();
*re = (*backend)->init(&resampler_config, bw_ratio, mask);
if (!*re)
return false;
return true;
}
/**
* 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).
**/
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;
*backend = find_resampler_driver(ident);
if (!resampler_append_plugs(re, backend, bw_ratio))
goto error;
return true;
error:
if (!*re)
*backend = NULL;
return false;
}