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

#define DIVBY128   0.0078125f
#define DIVBY32768   0.000030517578125f
#define DIVBY8388607   0.00000011920930376163766f

Definition at line 67 of file SDL_audiotypecvt.c.

Referenced by SDL_Convert_S32_to_F32_Scalar().

#define NEED_SCALAR_CONVERTER_FALLBACKS   1

Definition at line 49 of file SDL_audiotypecvt.c.

#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

Referenced by SDL_ChooseAudioConverters().

Function Documentation

void SDL_ChooseAudioConverters ( void  )

Definition at line 1387 of file SDL_audiotypecvt.c.

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

Referenced by SDL_BuildAudioCVT().

{
static SDL_bool converters_chosen = SDL_FALSE;
if (converters_chosen) {
return;
}
#define SET_CONVERTER_FUNCS(fntype) \
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
#if HAVE_SSE2_INTRINSICS
if (SDL_HasSSE2()) {
return;
}
#endif
#if HAVE_NEON_INTRINSICS
if (SDL_HasNEON()) {
return;
}
#endif
#if NEED_SCALAR_CONVERTER_FALLBACKS
#endif
#undef SET_CONVERTER_FUNCS
SDL_assert(converters_chosen == SDL_TRUE);
}
static void SDL_Convert_F32_to_S16_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 218 of file SDL_audiotypecvt.c.

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

{
const float *src = (const float *) cvt->buf;
Sint16 *dst = (Sint16 *) cvt->buf;
int i;
LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S16");
for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
const float sample = *src;
if (sample >= 1.0f) {
*dst = 32767;
} else if (sample <= -1.0f) {
*dst = -32768;
} else {
*dst = (Sint16)(sample * 32767.0f);
}
}
cvt->len_cvt /= 2;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index](cvt, AUDIO_S16SYS);
}
}
static void SDL_Convert_F32_to_S32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 270 of file SDL_audiotypecvt.c.

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

{
const float *src = (const float *) cvt->buf;
Sint32 *dst = (Sint32 *) cvt->buf;
int i;
LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S32");
for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
const float sample = *src;
if (sample >= 1.0f) {
*dst = 2147483647;
} else if (sample <= -1.0f) {
*dst = (Sint32) -2147483648LL;
} else {
*dst = ((Sint32)(sample * 8388607.0f)) << 8;
}
}
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index](cvt, AUDIO_S32SYS);
}
}
static void SDL_Convert_F32_to_S8_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 166 of file SDL_audiotypecvt.c.

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

{
const float *src = (const float *) cvt->buf;
Sint8 *dst = (Sint8 *) cvt->buf;
int i;
LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S8");
for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
const float sample = *src;
if (sample >= 1.0f) {
*dst = 127;
} else if (sample <= -1.0f) {
*dst = -128;
} else {
*dst = (Sint8)(sample * 127.0f);
}
}
cvt->len_cvt /= 4;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index](cvt, AUDIO_S8);
}
}
static void SDL_Convert_F32_to_U16_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 244 of file SDL_audiotypecvt.c.

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

{
const float *src = (const float *) cvt->buf;
Uint16 *dst = (Uint16 *) cvt->buf;
int i;
LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U16");
for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
const float sample = *src;
if (sample >= 1.0f) {
*dst = 65535;
} else if (sample <= -1.0f) {
*dst = 0;
} else {
*dst = (Uint16)((sample + 1.0f) * 32767.0f);
}
}
cvt->len_cvt /= 2;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index](cvt, AUDIO_U16SYS);
}
}
static void SDL_Convert_F32_to_U8_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 192 of file SDL_audiotypecvt.c.

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

{
const float *src = (const float *) cvt->buf;
Uint8 *dst = (Uint8 *) cvt->buf;
int i;
LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U8");
for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
const float sample = *src;
if (sample >= 1.0f) {
*dst = 255;
} else if (sample <= -1.0f) {
*dst = 0;
} else {
*dst = (Uint8)((sample + 1.0f) * 127.0f);
}
}
cvt->len_cvt /= 4;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index](cvt, AUDIO_U8);
}
}
static void SDL_Convert_S16_to_F32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 110 of file SDL_audiotypecvt.c.

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

{
const Sint16 *src = ((const Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
int i;
LOG_DEBUG_CONVERT("AUDIO_S16", "AUDIO_F32");
for (i = cvt->len_cvt / sizeof (Sint16); i; --i, --src, --dst) {
*dst = ((float) *src) * DIVBY32768;
}
cvt->len_cvt *= 2;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
}
}
static void SDL_Convert_S32_to_F32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 148 of file SDL_audiotypecvt.c.

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

{
const Sint32 *src = (const Sint32 *) cvt->buf;
float *dst = (float *) cvt->buf;
int i;
LOG_DEBUG_CONVERT("AUDIO_S32", "AUDIO_F32");
for (i = cvt->len_cvt / sizeof (Sint32); i; --i, ++src, ++dst) {
*dst = ((float) (*src>>8)) * DIVBY8388607;
}
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
}
}
static void SDL_Convert_S8_to_F32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 72 of file SDL_audiotypecvt.c.

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

{
const Sint8 *src = ((const Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
int i;
LOG_DEBUG_CONVERT("AUDIO_S8", "AUDIO_F32");
for (i = cvt->len_cvt; i; --i, --src, --dst) {
*dst = ((float) *src) * DIVBY128;
}
cvt->len_cvt *= 4;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
}
}
static void SDL_Convert_U16_to_F32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 129 of file SDL_audiotypecvt.c.

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

{
const Uint16 *src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
int i;
LOG_DEBUG_CONVERT("AUDIO_U16", "AUDIO_F32");
for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
*dst = (((float) *src) * DIVBY32768) - 1.0f;
}
cvt->len_cvt *= 2;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
}
}
static void SDL_Convert_U8_to_F32_Scalar ( SDL_AudioCVT cvt,
SDL_AudioFormat  format 
)
static

Definition at line 91 of file SDL_audiotypecvt.c.

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

{
const Uint8 *src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
int i;
LOG_DEBUG_CONVERT("AUDIO_U8", "AUDIO_F32");
for (i = cvt->len_cvt; i; --i, --src, --dst) {
*dst = (((float) *src) * DIVBY128) - 1.0f;
}
cvt->len_cvt *= 4;
if (cvt->filters[++cvt->filter_index]) {
cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
}
}

Variable Documentation

SDL_AudioFilter SDL_Convert_F32_to_S16 = NULL

Definition at line 60 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

SDL_AudioFilter SDL_Convert_F32_to_S32 = NULL

Definition at line 62 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

SDL_AudioFilter SDL_Convert_F32_to_S8 = NULL

Definition at line 58 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

SDL_AudioFilter SDL_Convert_F32_to_U16 = NULL

Definition at line 61 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

SDL_AudioFilter SDL_Convert_F32_to_U8 = NULL

Definition at line 59 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

SDL_AudioFilter SDL_Convert_S16_to_F32 = NULL

Definition at line 55 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

SDL_AudioFilter SDL_Convert_S32_to_F32 = NULL

Definition at line 57 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

SDL_AudioFilter SDL_Convert_S8_to_F32 = NULL

Definition at line 53 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

SDL_AudioFilter SDL_Convert_U16_to_F32 = NULL

Definition at line 56 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

SDL_AudioFilter SDL_Convert_U8_to_F32 = NULL

Definition at line 54 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().