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 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 63 of file SDL_audiotypecvt.c.

◆ DIVBY32768

#define DIVBY32768   0.000030517578125f

Definition at line 64 of file SDL_audiotypecvt.c.

◆ DIVBY8388607

#define DIVBY8388607   0.00000011920930376163766f

Definition at line 65 of file SDL_audiotypecvt.c.

◆ NEED_SCALAR_CONVERTER_FALLBACKS

#define NEED_SCALAR_CONVERTER_FALLBACKS   1

Definition at line 47 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:170
int(* fntype)(const char *)
Definition: testloadso.c:22

Function Documentation

◆ SDL_ChooseAudioConverters()

void SDL_ChooseAudioConverters ( void  )

Definition at line 1385 of file SDL_audiotypecvt.c.

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

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 216 of file SDL_audiotypecvt.c.

217 {
218  const float *src = (const float *) cvt->buf;
219  Sint16 *dst = (Sint16 *) cvt->buf;
220  int i;
221 
222  LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S16");
223 
224  for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
225  const float sample = *src;
226  if (sample >= 1.0f) {
227  *dst = 32767;
228  } else if (sample <= -1.0f) {
229  *dst = -32768;
230  } else {
231  *dst = (Sint16)(sample * 32767.0f);
232  }
233  }
234 
235  cvt->len_cvt /= 2;
236  if (cvt->filters[++cvt->filter_index]) {
237  cvt->filters[cvt->filter_index](cvt, AUDIO_S16SYS);
238  }
239 }
#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:191
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 268 of file SDL_audiotypecvt.c.

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

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 164 of file SDL_audiotypecvt.c.

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

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 242 of file SDL_audiotypecvt.c.

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

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 190 of file SDL_audiotypecvt.c.

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

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 108 of file SDL_audiotypecvt.c.

109 {
110  const Sint16 *src = ((const Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
111  float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
112  int i;
113 
114  LOG_DEBUG_CONVERT("AUDIO_S16", "AUDIO_F32");
115 
116  for (i = cvt->len_cvt / sizeof (Sint16); i; --i, --src, --dst) {
117  *dst = ((float) *src) * DIVBY32768;
118  }
119 
120  cvt->len_cvt *= 2;
121  if (cvt->filters[++cvt->filter_index]) {
122  cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
123  }
124 }
#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 146 of file SDL_audiotypecvt.c.

147 {
148  const Sint32 *src = (const Sint32 *) cvt->buf;
149  float *dst = (float *) cvt->buf;
150  int i;
151 
152  LOG_DEBUG_CONVERT("AUDIO_S32", "AUDIO_F32");
153 
154  for (i = cvt->len_cvt / sizeof (Sint32); i; --i, ++src, ++dst) {
155  *dst = ((float) (*src>>8)) * DIVBY8388607;
156  }
157 
158  if (cvt->filters[++cvt->filter_index]) {
159  cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
160  }
161 }
#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 70 of file SDL_audiotypecvt.c.

71 {
72  const Sint8 *src = ((const Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
73  float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
74  int i;
75 
76  LOG_DEBUG_CONVERT("AUDIO_S8", "AUDIO_F32");
77 
78  for (i = cvt->len_cvt; i; --i, --src, --dst) {
79  *dst = ((float) *src) * DIVBY128;
80  }
81 
82  cvt->len_cvt *= 4;
83  if (cvt->filters[++cvt->filter_index]) {
84  cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
85  }
86 }
#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 127 of file SDL_audiotypecvt.c.

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

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 89 of file SDL_audiotypecvt.c.

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

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 58 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 60 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 56 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 59 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 57 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 53 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 55 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 51 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 54 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 52 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().