SDL 2.0
SDL_audiotypecvt.c File Reference
#include "../SDL_internal.h"
#include "SDL_audio.h"
#include "SDL_audio_c.h"
#include "SDL_cpuinfo.h"
#include "SDL_assert.h"
+ Include dependency graph for SDL_audiotypecvt.c:

Go to the source code of this file.

Macros

#define NEED_SCALAR_CONVERTER_FALLBACKS   1
 
#define DIVBY128   0.0078125f
 
#define DIVBY32768   0.000030517578125f
 
#define DIVBY8388607   0.00000011920930376163766f
 
#define SET_CONVERTER_FUNCS(fntype)
 

Functions

static void SDL_Convert_S8_to_F32_Scalar (SDL_AudioCVT *cvt, SDL_AudioFormat format)
 
static void SDL_Convert_U8_to_F32_Scalar (SDL_AudioCVT *cvt, SDL_AudioFormat format)
 
static void SDL_Convert_S16_to_F32_Scalar (SDL_AudioCVT *cvt, SDL_AudioFormat format)
 
static void SDL_Convert_U16_to_F32_Scalar (SDL_AudioCVT *cvt, SDL_AudioFormat format)
 
static void SDL_Convert_S32_to_F32_Scalar (SDL_AudioCVT *cvt, SDL_AudioFormat format)
 
static void SDL_Convert_F32_to_S8_Scalar (SDL_AudioCVT *cvt, SDL_AudioFormat format)
 
static void SDL_Convert_F32_to_U8_Scalar (SDL_AudioCVT *cvt, SDL_AudioFormat format)
 
static void SDL_Convert_F32_to_S16_Scalar (SDL_AudioCVT *cvt, SDL_AudioFormat format)
 
static void SDL_Convert_F32_to_U16_Scalar (SDL_AudioCVT *cvt, SDL_AudioFormat format)
 
static void SDL_Convert_F32_to_S32_Scalar (SDL_AudioCVT *cvt, SDL_AudioFormat format)
 
void SDL_ChooseAudioConverters (void)
 

Variables

SDL_AudioFilter SDL_Convert_S8_to_F32 = NULL
 
SDL_AudioFilter SDL_Convert_U8_to_F32 = NULL
 
SDL_AudioFilter SDL_Convert_S16_to_F32 = NULL
 
SDL_AudioFilter SDL_Convert_U16_to_F32 = NULL
 
SDL_AudioFilter SDL_Convert_S32_to_F32 = NULL
 
SDL_AudioFilter SDL_Convert_F32_to_S8 = NULL
 
SDL_AudioFilter SDL_Convert_F32_to_U8 = NULL
 
SDL_AudioFilter SDL_Convert_F32_to_S16 = NULL
 
SDL_AudioFilter SDL_Convert_F32_to_U16 = NULL
 
SDL_AudioFilter SDL_Convert_F32_to_S32 = NULL
 

Macro Definition Documentation

◆ DIVBY128

#define DIVBY128   0.0078125f

Definition at line 64 of file SDL_audiotypecvt.c.

◆ DIVBY32768

#define DIVBY32768   0.000030517578125f

Definition at line 65 of file SDL_audiotypecvt.c.

◆ DIVBY8388607

#define DIVBY8388607   0.00000011920930376163766f

Definition at line 66 of file SDL_audiotypecvt.c.

◆ NEED_SCALAR_CONVERTER_FALLBACKS

#define NEED_SCALAR_CONVERTER_FALLBACKS   1

Definition at line 48 of file SDL_audiotypecvt.c.

◆ SET_CONVERTER_FUNCS

#define SET_CONVERTER_FUNCS (   fntype)
Value:
SDL_Convert_S8_to_F32 = SDL_Convert_S8_to_F32_##fntype; \
SDL_Convert_U8_to_F32 = SDL_Convert_U8_to_F32_##fntype; \
SDL_Convert_S16_to_F32 = SDL_Convert_S16_to_F32_##fntype; \
SDL_Convert_U16_to_F32 = SDL_Convert_U16_to_F32_##fntype; \
SDL_Convert_S32_to_F32 = SDL_Convert_S32_to_F32_##fntype; \
SDL_Convert_F32_to_S8 = SDL_Convert_F32_to_S8_##fntype; \
SDL_Convert_F32_to_U8 = SDL_Convert_F32_to_U8_##fntype; \
SDL_Convert_F32_to_S16 = SDL_Convert_F32_to_S16_##fntype; \
SDL_Convert_F32_to_U16 = SDL_Convert_F32_to_U16_##fntype; \
SDL_Convert_F32_to_S32 = SDL_Convert_F32_to_S32_##fntype; \
converters_chosen = SDL_TRUE
SDL_AudioFilter SDL_Convert_S8_to_F32
@ SDL_TRUE
Definition: SDL_stdinc.h:164
int(* fntype)(const char *)
Definition: testloadso.c:22

Function Documentation

◆ SDL_ChooseAudioConverters()

void SDL_ChooseAudioConverters ( void  )

Definition at line 1386 of file SDL_audiotypecvt.c.

1387{
1388 static SDL_bool converters_chosen = SDL_FALSE;
1389
1390 if (converters_chosen) {
1391 return;
1392 }
1393
1394#define SET_CONVERTER_FUNCS(fntype) \
1395 SDL_Convert_S8_to_F32 = SDL_Convert_S8_to_F32_##fntype; \
1396 SDL_Convert_U8_to_F32 = SDL_Convert_U8_to_F32_##fntype; \
1397 SDL_Convert_S16_to_F32 = SDL_Convert_S16_to_F32_##fntype; \
1398 SDL_Convert_U16_to_F32 = SDL_Convert_U16_to_F32_##fntype; \
1399 SDL_Convert_S32_to_F32 = SDL_Convert_S32_to_F32_##fntype; \
1400 SDL_Convert_F32_to_S8 = SDL_Convert_F32_to_S8_##fntype; \
1401 SDL_Convert_F32_to_U8 = SDL_Convert_F32_to_U8_##fntype; \
1402 SDL_Convert_F32_to_S16 = SDL_Convert_F32_to_S16_##fntype; \
1403 SDL_Convert_F32_to_U16 = SDL_Convert_F32_to_U16_##fntype; \
1404 SDL_Convert_F32_to_S32 = SDL_Convert_F32_to_S32_##fntype; \
1405 converters_chosen = SDL_TRUE
1406
1407#if HAVE_SSE2_INTRINSICS
1408 if (SDL_HasSSE2()) {
1409 SET_CONVERTER_FUNCS(SSE2);
1410 return;
1411 }
1412#endif
1413
1414#if HAVE_NEON_INTRINSICS
1415 if (SDL_HasNEON()) {
1416 SET_CONVERTER_FUNCS(NEON);
1417 return;
1418 }
1419#endif
1420
1421#if NEED_SCALAR_CONVERTER_FALLBACKS
1422 SET_CONVERTER_FUNCS(Scalar);
1423#endif
1424
1425#undef SET_CONVERTER_FUNCS
1426
1427 SDL_assert(converters_chosen == SDL_TRUE);
1428}
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define SET_CONVERTER_FUNCS(fntype)
#define SDL_HasNEON
#define SDL_HasSSE2
SDL_bool
Definition: SDL_stdinc.h:162
@ SDL_FALSE
Definition: SDL_stdinc.h:163

References SDL_assert, SDL_FALSE, SDL_HasNEON, SDL_HasSSE2, SDL_TRUE, and SET_CONVERTER_FUNCS.

Referenced by SDL_BuildAudioCVT().

◆ SDL_Convert_F32_to_S16_Scalar()

static void SDL_Convert_F32_to_S16_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 217 of file SDL_audiotypecvt.c.

218{
219 const float *src = (const float *) cvt->buf;
220 Sint16 *dst = (Sint16 *) cvt->buf;
221 int i;
222
223 LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S16");
224
225 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
226 const float sample = *src;
227 if (sample >= 1.0f) {
228 *dst = 32767;
229 } else if (sample <= -1.0f) {
230 *dst = -32768;
231 } else {
232 *dst = (Sint16)(sample * 32767.0f);
233 }
234 }
235
236 cvt->len_cvt /= 2;
237 if (cvt->filters[++cvt->filter_index]) {
238 cvt->filters[cvt->filter_index](cvt, AUDIO_S16SYS);
239 }
240}
#define AUDIO_S16SYS
Definition: SDL_audio.h:123
#define LOG_DEBUG_CONVERT(from, to)
Definition: SDL_audio_c.h:34
GLenum src
GLenum GLenum dst
int16_t Sint16
Definition: SDL_stdinc.h:185
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
Uint8 * buf
Definition: SDL_audio.h:232
int filter_index
Definition: SDL_audio.h:238
SDL_AudioFilter filters[SDL_AUDIOCVT_MAX_FILTERS+1]
Definition: SDL_audio.h:237

References AUDIO_S16SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, and LOG_DEBUG_CONVERT.

◆ SDL_Convert_F32_to_S32_Scalar()

static void SDL_Convert_F32_to_S32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 269 of file SDL_audiotypecvt.c.

270{
271 const float *src = (const float *) cvt->buf;
272 Sint32 *dst = (Sint32 *) cvt->buf;
273 int i;
274
275 LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S32");
276
277 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
278 const float sample = *src;
279 if (sample >= 1.0f) {
280 *dst = 2147483647;
281 } else if (sample <= -1.0f) {
282 *dst = (Sint32) -2147483648LL;
283 } else {
284 *dst = ((Sint32)(sample * 8388607.0f)) << 8;
285 }
286 }
287
288 if (cvt->filters[++cvt->filter_index]) {
289 cvt->filters[cvt->filter_index](cvt, AUDIO_S32SYS);
290 }
291}
#define AUDIO_S32SYS
Definition: SDL_audio.h:124
int32_t Sint32
Definition: SDL_stdinc.h:197

References AUDIO_S32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, and LOG_DEBUG_CONVERT.

◆ SDL_Convert_F32_to_S8_Scalar()

static void SDL_Convert_F32_to_S8_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 165 of file SDL_audiotypecvt.c.

166{
167 const float *src = (const float *) cvt->buf;
168 Sint8 *dst = (Sint8 *) cvt->buf;
169 int i;
170
171 LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S8");
172
173 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
174 const float sample = *src;
175 if (sample >= 1.0f) {
176 *dst = 127;
177 } else if (sample <= -1.0f) {
178 *dst = -128;
179 } else {
180 *dst = (Sint8)(sample * 127.0f);
181 }
182 }
183
184 cvt->len_cvt /= 4;
185 if (cvt->filters[++cvt->filter_index]) {
186 cvt->filters[cvt->filter_index](cvt, AUDIO_S8);
187 }
188}
#define AUDIO_S8
Definition: SDL_audio.h:90
int8_t Sint8
Definition: SDL_stdinc.h:173

References AUDIO_S8, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, and LOG_DEBUG_CONVERT.

◆ SDL_Convert_F32_to_U16_Scalar()

static void SDL_Convert_F32_to_U16_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 243 of file SDL_audiotypecvt.c.

244{
245 const float *src = (const float *) cvt->buf;
246 Uint16 *dst = (Uint16 *) cvt->buf;
247 int i;
248
249 LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U16");
250
251 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
252 const float sample = *src;
253 if (sample >= 1.0f) {
254 *dst = 65535;
255 } else if (sample <= -1.0f) {
256 *dst = 0;
257 } else {
258 *dst = (Uint16)((sample + 1.0f) * 32767.0f);
259 }
260 }
261
262 cvt->len_cvt /= 2;
263 if (cvt->filters[++cvt->filter_index]) {
264 cvt->filters[cvt->filter_index](cvt, AUDIO_U16SYS);
265 }
266}
#define AUDIO_U16SYS
Definition: SDL_audio.h:122
uint16_t Uint16
Definition: SDL_stdinc.h:191

References AUDIO_U16SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, and LOG_DEBUG_CONVERT.

◆ SDL_Convert_F32_to_U8_Scalar()

static void SDL_Convert_F32_to_U8_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 191 of file SDL_audiotypecvt.c.

192{
193 const float *src = (const float *) cvt->buf;
194 Uint8 *dst = (Uint8 *) cvt->buf;
195 int i;
196
197 LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U8");
198
199 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
200 const float sample = *src;
201 if (sample >= 1.0f) {
202 *dst = 255;
203 } else if (sample <= -1.0f) {
204 *dst = 0;
205 } else {
206 *dst = (Uint8)((sample + 1.0f) * 127.0f);
207 }
208 }
209
210 cvt->len_cvt /= 4;
211 if (cvt->filters[++cvt->filter_index]) {
212 cvt->filters[cvt->filter_index](cvt, AUDIO_U8);
213 }
214}
#define AUDIO_U8
Definition: SDL_audio.h:89
uint8_t Uint8
Definition: SDL_stdinc.h:179

References AUDIO_U8, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, and LOG_DEBUG_CONVERT.

◆ SDL_Convert_S16_to_F32_Scalar()

static void SDL_Convert_S16_to_F32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 109 of file SDL_audiotypecvt.c.

110{
111 const Sint16 *src = ((const Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
112 float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
113 int i;
114
115 LOG_DEBUG_CONVERT("AUDIO_S16", "AUDIO_F32");
116
117 for (i = cvt->len_cvt / sizeof (Sint16); i; --i, --src, --dst) {
118 *dst = ((float) *src) * DIVBY32768;
119 }
120
121 cvt->len_cvt *= 2;
122 if (cvt->filters[++cvt->filter_index]) {
123 cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
124 }
125}
#define AUDIO_F32SYS
Definition: SDL_audio.h:125
#define DIVBY32768

References AUDIO_F32SYS, SDL_AudioCVT::buf, DIVBY32768, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, and LOG_DEBUG_CONVERT.

◆ SDL_Convert_S32_to_F32_Scalar()

static void SDL_Convert_S32_to_F32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 147 of file SDL_audiotypecvt.c.

148{
149 const Sint32 *src = (const Sint32 *) cvt->buf;
150 float *dst = (float *) cvt->buf;
151 int i;
152
153 LOG_DEBUG_CONVERT("AUDIO_S32", "AUDIO_F32");
154
155 for (i = cvt->len_cvt / sizeof (Sint32); i; --i, ++src, ++dst) {
156 *dst = ((float) (*src>>8)) * DIVBY8388607;
157 }
158
159 if (cvt->filters[++cvt->filter_index]) {
160 cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
161 }
162}
#define DIVBY8388607

References AUDIO_F32SYS, SDL_AudioCVT::buf, DIVBY8388607, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, and LOG_DEBUG_CONVERT.

◆ SDL_Convert_S8_to_F32_Scalar()

static void SDL_Convert_S8_to_F32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 71 of file SDL_audiotypecvt.c.

72{
73 const Sint8 *src = ((const Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
74 float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
75 int i;
76
77 LOG_DEBUG_CONVERT("AUDIO_S8", "AUDIO_F32");
78
79 for (i = cvt->len_cvt; i; --i, --src, --dst) {
80 *dst = ((float) *src) * DIVBY128;
81 }
82
83 cvt->len_cvt *= 4;
84 if (cvt->filters[++cvt->filter_index]) {
85 cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
86 }
87}
#define DIVBY128

References AUDIO_F32SYS, SDL_AudioCVT::buf, DIVBY128, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, and LOG_DEBUG_CONVERT.

◆ SDL_Convert_U16_to_F32_Scalar()

static void SDL_Convert_U16_to_F32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 128 of file SDL_audiotypecvt.c.

129{
130 const Uint16 *src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
131 float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
132 int i;
133
134 LOG_DEBUG_CONVERT("AUDIO_U16", "AUDIO_F32");
135
136 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
137 *dst = (((float) *src) * DIVBY32768) - 1.0f;
138 }
139
140 cvt->len_cvt *= 2;
141 if (cvt->filters[++cvt->filter_index]) {
142 cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
143 }
144}

References AUDIO_F32SYS, SDL_AudioCVT::buf, DIVBY32768, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, and LOG_DEBUG_CONVERT.

◆ SDL_Convert_U8_to_F32_Scalar()

static void SDL_Convert_U8_to_F32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 90 of file SDL_audiotypecvt.c.

91{
92 const Uint8 *src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
93 float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
94 int i;
95
96 LOG_DEBUG_CONVERT("AUDIO_U8", "AUDIO_F32");
97
98 for (i = cvt->len_cvt; i; --i, --src, --dst) {
99 *dst = (((float) *src) * DIVBY128) - 1.0f;
100 }
101
102 cvt->len_cvt *= 4;
103 if (cvt->filters[++cvt->filter_index]) {
104 cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
105 }
106}

References AUDIO_F32SYS, SDL_AudioCVT::buf, DIVBY128, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, and LOG_DEBUG_CONVERT.

Variable Documentation

◆ SDL_Convert_F32_to_S16

SDL_AudioFilter SDL_Convert_F32_to_S16 = NULL

Definition at line 59 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

◆ SDL_Convert_F32_to_S32

SDL_AudioFilter SDL_Convert_F32_to_S32 = NULL

Definition at line 61 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

◆ SDL_Convert_F32_to_S8

SDL_AudioFilter SDL_Convert_F32_to_S8 = NULL

Definition at line 57 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

◆ SDL_Convert_F32_to_U16

SDL_AudioFilter SDL_Convert_F32_to_U16 = NULL

Definition at line 60 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

◆ SDL_Convert_F32_to_U8

SDL_AudioFilter SDL_Convert_F32_to_U8 = NULL

Definition at line 58 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

◆ SDL_Convert_S16_to_F32

SDL_AudioFilter SDL_Convert_S16_to_F32 = NULL

Definition at line 54 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

◆ SDL_Convert_S32_to_F32

SDL_AudioFilter SDL_Convert_S32_to_F32 = NULL

Definition at line 56 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

◆ SDL_Convert_S8_to_F32

SDL_AudioFilter SDL_Convert_S8_to_F32 = NULL

Definition at line 52 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

◆ SDL_Convert_U16_to_F32

SDL_AudioFilter SDL_Convert_U16_to_F32 = NULL

Definition at line 55 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

◆ SDL_Convert_U8_to_F32

SDL_AudioFilter SDL_Convert_U8_to_F32 = NULL

Definition at line 53 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().