RetroArch
audio_resampler.h
Go to the documentation of this file.
1 /* Copyright (C) 2010-2018 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (audio_resampler.h).
5  * ---------------------------------------------------------------------------------------
6  *
7  * Permission is hereby granted, free of charge,
8  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __LIBRETRO_SDK_AUDIO_RESAMPLER_DRIVER_H
24 #define __LIBRETRO_SDK_AUDIO_RESAMPLER_DRIVER_H
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 
29 #include <boolean.h>
30 #include <retro_common_api.h>
31 
33 
34 #define RESAMPLER_SIMD_SSE (1 << 0)
35 #define RESAMPLER_SIMD_SSE2 (1 << 1)
36 #define RESAMPLER_SIMD_VMX (1 << 2)
37 #define RESAMPLER_SIMD_VMX128 (1 << 3)
38 #define RESAMPLER_SIMD_AVX (1 << 4)
39 #define RESAMPLER_SIMD_NEON (1 << 5)
40 #define RESAMPLER_SIMD_SSE3 (1 << 6)
41 #define RESAMPLER_SIMD_SSSE3 (1 << 7)
42 #define RESAMPLER_SIMD_MMX (1 << 8)
43 #define RESAMPLER_SIMD_MMXEXT (1 << 9)
44 #define RESAMPLER_SIMD_SSE4 (1 << 10)
45 #define RESAMPLER_SIMD_SSE42 (1 << 11)
46 #define RESAMPLER_SIMD_AVX2 (1 << 12)
47 #define RESAMPLER_SIMD_VFPU (1 << 13)
48 #define RESAMPLER_SIMD_PS (1 << 14)
49 
51 {
58 };
59 
60 /* A bit-mask of all supported SIMD instruction sets.
61  * Allows an implementation to pick different
62  * resampler_implementation structs.
63  */
64 typedef unsigned resampler_simd_mask_t;
65 
66 #define RESAMPLER_API_VERSION 1
67 
69 {
70  const float *data_in;
71  float *data_out;
72 
73  size_t input_frames;
74  size_t output_frames;
75 
76  double ratio;
77 };
78 
79 /* Returns true if config key was found. Otherwise,
80  * returns false, and sets value to default value.
81  */
82 typedef int (*resampler_config_get_float_t)(void *userdata,
83  const char *key, float *value, float default_value);
84 
85 typedef int (*resampler_config_get_int_t)(void *userdata,
86  const char *key, int *value, int default_value);
87 
88 /* Allocates an array with values. free() with resampler_config_free_t. */
89 typedef int (*resampler_config_get_float_array_t)(void *userdata,
90  const char *key, float **values, unsigned *out_num_values,
91  const float *default_values, unsigned num_default_values);
92 
93 typedef int (*resampler_config_get_int_array_t)(void *userdata,
94  const char *key, int **values, unsigned *out_num_values,
95  const int *default_values, unsigned num_default_values);
96 
97 typedef int (*resampler_config_get_string_t)(void *userdata,
98  const char *key, char **output, const char *default_output);
99 
100 /* Calls free() in host runtime. Sometimes needed on Windows.
101  * free() on NULL is fine. */
102 typedef void (*resampler_config_free_t)(void *ptr);
103 
105 {
108 
111 
113  /* Avoid problems where resampler plug and host are
114  * linked against different C runtimes. */
116 };
117 
118 /* Bandwidth factor. Will be < 1.0 for downsampling, > 1.0 for upsampling.
119  * Corresponds to expected resampling ratio. */
120 typedef void *(*resampler_init_t)(const struct resampler_config *config,
121  double bandwidth_mod, enum resampler_quality quality,
123 
124 /* Frees the handle. */
125 typedef void (*resampler_free_t)(void *data);
126 
127 /* Processes input data. */
128 typedef void (*resampler_process_t)(void *_data, struct resampler_data *data);
129 
130 typedef struct retro_resampler
131 {
135 
136  /* Must be RESAMPLER_API_VERSION */
137  unsigned api_version;
138 
139  /* Human readable identifier of implementation. */
140  const char *ident;
141 
142  /* Computer-friendly short version of ident.
143  * Lower case, no spaces and special characters, etc. */
144  const char *short_ident;
146 
147 typedef struct audio_frame_float
148 {
149  float l;
150  float r;
152 
154 #ifdef HAVE_CC_RESAMPLER
156 #endif
159 
168 
177 
190 bool retro_resampler_realloc(void **re, const retro_resampler_t **backend,
191  const char *ident, enum resampler_quality quality, double bw_ratio);
192 
194 
195 #endif
float * data_out
Definition: audio_resampler.h:71
void *(* resampler_init_t)(const struct resampler_config *config, double bandwidth_mod, enum resampler_quality quality, resampler_simd_mask_t mask)
Definition: audio_resampler.h:120
const GLvoid * ptr
Definition: nx_glsym.h:242
retro_resampler_t CC_resampler
Definition: cc_resampler.c:547
Definition: audio_resampler.h:130
struct retro_resampler retro_resampler_t
Definition: audio_resampler.h:55
#define RETRO_BEGIN_DECLS
Definition: retro_common_api.h:41
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:6318
unsigned resampler_simd_mask_t
Definition: audio_resampler.h:64
Definition: audio_resampler.h:54
resampler_config_free_t free
Definition: audio_resampler.h:115
int(* resampler_config_get_int_t)(void *userdata, const char *key, int *value, int default_value)
Definition: audio_resampler.h:85
unsigned api_version
Definition: audio_resampler.h:137
float r
Definition: audio_resampler.h:150
int(* resampler_config_get_float_t)(void *userdata, const char *key, float *value, float default_value)
Definition: audio_resampler.h:82
retro_resampler_t nearest_resampler
Definition: nearest_resampler.c:83
double ratio
Definition: audio_resampler.h:76
resampler_process_t process
Definition: audio_resampler.h:133
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
retro_resampler_t null_resampler
Definition: null_resampler.c:51
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
resampler_config_get_float_t get_float
Definition: audio_resampler.h:106
struct audio_frame_float audio_frame_float_t
Definition: audio_resampler.h:104
float l
Definition: audio_resampler.h:149
void(* resampler_config_free_t)(void *ptr)
Definition: audio_resampler.h:102
Definition: audio_resampler.h:57
bool retro_resampler_realloc(void **re, const retro_resampler_t **backend, const char *ident, enum resampler_quality quality, double bw_ratio)
Definition: audio_resampler.c:155
string backend
Definition: test_shaders.py:19
Definition: audio_resampler.h:147
Definition: audio_resampler.h:68
resampler_config_get_int_t get_int
Definition: audio_resampler.h:107
resampler_config_get_float_array_t get_float_array
Definition: audio_resampler.h:109
const char * audio_resampler_driver_find_ident(int index)
Definition: audio_resampler.c:91
GLenum GLint GLuint mask
Definition: glext.h:6668
int(* resampler_config_get_string_t)(void *userdata, const char *key, char **output, const char *default_output)
Definition: audio_resampler.h:97
size_t output_frames
Definition: audio_resampler.h:74
struct config_s config
int(* resampler_config_get_int_array_t)(void *userdata, const char *key, int **values, unsigned *out_num_values, const int *default_values, unsigned num_default_values)
Definition: audio_resampler.h:93
Definition: audio_resampler.h:56
#define RETRO_END_DECLS
Definition: retro_common_api.h:42
resampler_config_get_int_array_t get_int_array
Definition: audio_resampler.h:110
retro_resampler_t sinc_resampler
Definition: sinc_resampler.c:711
GLuint index
Definition: glext.h:6671
#define quality
Definition: ps3_defines.h:300
std::string output
Definition: Config.FromFile.cpp:44
void(* resampler_process_t)(void *_data, struct resampler_data *data)
Definition: audio_resampler.h:128
void(* resampler_free_t)(void *data)
Definition: audio_resampler.h:125
const char * short_ident
Definition: audio_resampler.h:144
resampler_config_get_string_t get_string
Definition: audio_resampler.h:112
GLsizei const GLfloat * value
Definition: glext.h:6709
const float * data_in
Definition: audio_resampler.h:70
size_t input_frames
Definition: audio_resampler.h:73
const char * ident
Definition: audio_resampler.h:140
resampler_init_t init
Definition: audio_resampler.h:132
Definition: audio_resampler.h:53
resampler_free_t free
Definition: audio_resampler.h:134
resampler_quality
Definition: audio_resampler.h:50
int(* resampler_config_get_float_array_t)(void *userdata, const char *key, float **values, unsigned *out_num_values, const float *default_values, unsigned num_default_values)
Definition: audio_resampler.h:89
const void * audio_resampler_driver_find_handle(int index)
Definition: audio_resampler.c:76
Definition: audio_resampler.h:52