SDL_audio_c.h File Reference
`#include "../SDL_internal.h"`
Include dependency graph for SDL_audio_c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Macros

#define | DEBUG_CONVERT 0
#define | LOG_DEBUG_CONVERT(from, to)

## Functions

SDL_AudioFormat | SDL_FirstAudioFormat (SDL_AudioFormat format)
SDL_AudioFormat | SDL_NextAudioFormat (void)
void | SDL_CalculateAudioSpec (SDL_AudioSpec *spec)
void | SDL_ChooseAudioConverters (void)
int | SDL_PrepareResampleFilter (void)
void | SDL_FreeResampleFilter (void)

## Variables

SDL_AudioFilter | SDL_Convert_S8_to_F32
SDL_AudioFilter | SDL_Convert_U8_to_F32
SDL_AudioFilter | SDL_Convert_S16_to_F32
SDL_AudioFilter | SDL_Convert_U16_to_F32
SDL_AudioFilter | SDL_Convert_S32_to_F32
SDL_AudioFilter | SDL_Convert_F32_to_S8
SDL_AudioFilter | SDL_Convert_F32_to_U8
SDL_AudioFilter | SDL_Convert_F32_to_S16
SDL_AudioFilter | SDL_Convert_F32_to_U16
SDL_AudioFilter | SDL_Convert_F32_to_S32

## Macro Definition Documentation

## DEBUG_CONVERT

#define DEBUG_CONVERT 0

Definition at line 28 of file SDL_audio_c.h.

## LOG_DEBUG_CONVERT

#define LOG_DEBUG_CONVERT | ( |  | from,
|  |  | to
| ) |  |

Definition at line 34 of file SDL_audio_c.h.

Referenced by SDL_Convert51To71(), SDL_Convert51ToQuad(), SDL_Convert51ToStereo(), SDL_Convert71To51(), SDL_Convert_F32_to_S16_Scalar(), SDL_Convert_F32_to_S32_Scalar(), SDL_Convert_F32_to_S8_Scalar(), SDL_Convert_F32_to_U16_Scalar(), SDL_Convert_F32_to_U8_Scalar(), SDL_Convert_S16_to_F32_Scalar(), SDL_Convert_S32_to_F32_Scalar(), SDL_Convert_S8_to_F32_Scalar(), SDL_Convert_U16_to_F32_Scalar(), SDL_Convert_U8_to_F32_Scalar(), SDL_ConvertMonoToStereo(), SDL_ConvertQuadTo51(), SDL_ConvertQuadToStereo(), SDL_ConvertStereoTo51(), SDL_ConvertStereoToMono(), and SDL_ConvertStereoToQuad().

## Function Documentation

## SDL_CalculateAudioSpec()

void SDL_CalculateAudioSpec | ( | SDL_AudioSpec * | spec | ) |

Definition at line 1605 of file SDL_audio.c.

References AUDIO_U8, SDL_AudioSpec::channels, SDL_AudioSpec::format, SDL_AudioSpec::samples, SDL_AUDIO_BITSIZE, SDL_AudioSpec::silence, and SDL_AudioSpec::size.

Referenced by open_audio_device(), and prepare_audiospec().

{
switch (spec->format) {
case AUDIO_U8:
spec->silence = 0x80;
break;
default:
spec->silence = 0x00;
break;
}
spec->size = SDL_AUDIO_BITSIZE(spec->format) / 8;
spec->size *= spec->channels;
spec->size *= spec->samples;
}
SDL_AudioSpec::silence
Uint8 silence
Definition: SDL_audio.h:182
SDL_AudioSpec::samples
Uint16 samples
Definition: SDL_audio.h:183
AUDIO_U8
#define AUDIO_U8
Definition: SDL_audio.h:89
SDL_AudioSpec::channels
Uint8 channels
Definition: SDL_audio.h:181
SDL_AUDIO_BITSIZE
#define SDL_AUDIO_BITSIZE(x)
Definition: SDL_audio.h:75
SDL_AudioSpec::size
Uint32 size
Definition: SDL_audio.h:185
SDL_AudioSpec::format
SDL_AudioFormat format
Definition: SDL_audio.h:180

## SDL_ChooseAudioConverters()

void SDL_ChooseAudioConverters | ( | void |  | ) |

Definition at line 792 of file SDL_audiotypecvt.c.

References SDL_assert, SDL_FALSE, 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()) {
SET_CONVERTER_FUNCS(SSE2);
return;
}
#endif
#if NEED_SCALAR_CONVERTER_FALLBACKS
SET_CONVERTER_FUNCS(Scalar);
#endif
#undef SET_CONVERTER_FUNCS
SDL_assert(converters_chosen == SDL_TRUE);
}
SDL_TRUE
Definition: SDL_stdinc.h:142
SDL_FALSE
Definition: SDL_stdinc.h:141
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:169
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:139
SDL_HasSSE2
#define SDL_HasSSE2
Definition: SDL_dynapi_overrides.h:108
SET_CONVERTER_FUNCS
#define SET_CONVERTER_FUNCS(fntype)

## SDL_FirstAudioFormat()

SDL_AudioFormat SDL_FirstAudioFormat | ( | SDL_AudioFormat | format | ) |

Definition at line 1584 of file SDL_audio.c.

References format_idx, format_idx_sub, format_list, NUM_FORMATS, and SDL_NextAudioFormat().

{
for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) {
if (format_list[format_idx][0] == format) {
break;
}
}
format_idx_sub = 0;
return SDL_NextAudioFormat();
}
format_idx_sub
static int format_idx_sub
Definition: SDL_audio.c:1559
format_idx
static int format_idx
Definition: SDL_audio.c:1558
format_list
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1560
SDL_NextAudioFormat
SDL_AudioFormat SDL_NextAudioFormat(void)
Definition: SDL_audio.c:1596
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
NUM_FORMATS
#define NUM_FORMATS
Definition: SDL_audio.c:1557

## SDL_FreeResampleFilter()

void SDL_FreeResampleFilter | ( | void |  | ) |

Definition at line 464 of file SDL_audiocvt.c.

References NULL, ResamplerFilter, ResamplerFilterDifference, and SDL_free.

Referenced by SDL_AudioQuit().

{
SDL_free(ResamplerFilter);
SDL_free(ResamplerFilterDifference);
ResamplerFilter = NULL;
ResamplerFilterDifference = NULL;
}
ResamplerFilter
static float * ResamplerFilter
Definition: SDL_audiocvt.c:431
ResamplerFilterDifference
static float * ResamplerFilterDifference
Definition: SDL_audiocvt.c:432
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
NULL
#define NULL
Definition: begin_code.h:164

## SDL_NextAudioFormat()

SDL_AudioFormat SDL_NextAudioFormat | ( | void |  | ) |

Definition at line 1596 of file SDL_audio.c.

References format_idx, format_idx_sub, format_list, and NUM_FORMATS.

Referenced by SDL_FirstAudioFormat().

{
if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) {
return 0;
}
return format_list[format_idx][format_idx_sub++];
}
format_idx_sub
static int format_idx_sub
Definition: SDL_audio.c:1559
format_idx
static int format_idx
Definition: SDL_audio.c:1558
format_list
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1560
NUM_FORMATS
#define NUM_FORMATS
Definition: SDL_audio.c:1557

## SDL_PrepareResampleFilter()

int SDL_PrepareResampleFilter | ( | void |  | ) |

Definition at line 435 of file SDL_audiocvt.c.

References kaiser_and_sinc(), NULL, ResampleFilterSpinlock, RESAMPLER_FILTER_SIZE, ResamplerFilter, ResamplerFilterDifference, SDL_AtomicLock, SDL_AtomicUnlock, SDL_free, SDL_malloc, and SDL_OutOfMemory.

Referenced by SDL_BuildAudioResampleCVT(), and SDL_NewAudioStream().

{
SDL_AtomicLock(&ResampleFilterSpinlock);
if (!ResamplerFilter) {
/* if dB > 50, beta=(0.1102 * (dB - 8.7)), according to Matlab. */
const double dB = 80.0;
const double beta = 0.1102 * (dB - 8.7);
const size_t alloclen = RESAMPLER_FILTER_SIZE * sizeof (float);
ResamplerFilter = (float *) SDL_malloc(alloclen);
if (!ResamplerFilter) {
SDL_AtomicUnlock(&ResampleFilterSpinlock);
return SDL_OutOfMemory();
}
ResamplerFilterDifference = (float *) SDL_malloc(alloclen);
if (!ResamplerFilterDifference) {
SDL_free(ResamplerFilter);
ResamplerFilter = NULL;
SDL_AtomicUnlock(&ResampleFilterSpinlock);
return SDL_OutOfMemory();
}
kaiser_and_sinc(ResamplerFilter, ResamplerFilterDifference, RESAMPLER_FILTER_SIZE, beta);
}
SDL_AtomicUnlock(&ResampleFilterSpinlock);
return 0;
}
SDL_AtomicLock
#define SDL_AtomicLock
Definition: SDL_dynapi_overrides.h:64
ResampleFilterSpinlock
static SDL_SpinLock ResampleFilterSpinlock
Definition: SDL_audiocvt.c:430
ResamplerFilter
static float * ResamplerFilter
Definition: SDL_audiocvt.c:431
kaiser_and_sinc
static void kaiser_and_sinc(float *table, float *diffs, const int tablelen, const double beta)
Definition: SDL_audiocvt.c:409
ResamplerFilterDifference
static float * ResamplerFilterDifference
Definition: SDL_audiocvt.c:432
SDL_AtomicUnlock
#define SDL_AtomicUnlock
Definition: SDL_dynapi_overrides.h:65
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
RESAMPLER_FILTER_SIZE
#define RESAMPLER_FILTER_SIZE
Definition: SDL_audiocvt.c:383
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374

## Variable Documentation

## SDL_Convert_F32_to_S16

SDL_AudioFilter SDL_Convert_F32_to_S16

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

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

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

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

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

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

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

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

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

Definition at line 52 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().