SDL  2.0
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

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().

1606 {
1607  switch (spec->format) {
1608  case AUDIO_U8:
1609  spec->silence = 0x80;
1610  break;
1611  default:
1612  spec->silence = 0x00;
1613  break;
1614  }
1615  spec->size = SDL_AUDIO_BITSIZE(spec->format) / 8;
1616  spec->size *= spec->channels;
1617  spec->size *= spec->samples;
1618 }
Uint8 silence
Definition: SDL_audio.h:182
Uint16 samples
Definition: SDL_audio.h:183
#define AUDIO_U8
Definition: SDL_audio.h:89
Uint8 channels
Definition: SDL_audio.h:181
#define SDL_AUDIO_BITSIZE(x)
Definition: SDL_audio.h:75
Uint32 size
Definition: SDL_audio.h:185
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().

793 {
794  static SDL_bool converters_chosen = SDL_FALSE;
795 
796  if (converters_chosen) {
797  return;
798  }
799 
800 #define SET_CONVERTER_FUNCS(fntype) \
801  SDL_Convert_S8_to_F32 = SDL_Convert_S8_to_F32_##fntype; \
802  SDL_Convert_U8_to_F32 = SDL_Convert_U8_to_F32_##fntype; \
803  SDL_Convert_S16_to_F32 = SDL_Convert_S16_to_F32_##fntype; \
804  SDL_Convert_U16_to_F32 = SDL_Convert_U16_to_F32_##fntype; \
805  SDL_Convert_S32_to_F32 = SDL_Convert_S32_to_F32_##fntype; \
806  SDL_Convert_F32_to_S8 = SDL_Convert_F32_to_S8_##fntype; \
807  SDL_Convert_F32_to_U8 = SDL_Convert_F32_to_U8_##fntype; \
808  SDL_Convert_F32_to_S16 = SDL_Convert_F32_to_S16_##fntype; \
809  SDL_Convert_F32_to_U16 = SDL_Convert_F32_to_U16_##fntype; \
810  SDL_Convert_F32_to_S32 = SDL_Convert_F32_to_S32_##fntype; \
811  converters_chosen = SDL_TRUE
812 
813 #if HAVE_SSE2_INTRINSICS
814  if (SDL_HasSSE2()) {
815  SET_CONVERTER_FUNCS(SSE2);
816  return;
817  }
818 #endif
819 
820 #if NEED_SCALAR_CONVERTER_FALLBACKS
821  SET_CONVERTER_FUNCS(Scalar);
822 #endif
823 
824 #undef SET_CONVERTER_FUNCS
825 
826  SDL_assert(converters_chosen == SDL_TRUE);
827 }
#define SDL_assert(condition)
Definition: SDL_assert.h:169
SDL_bool
Definition: SDL_stdinc.h:139
#define SDL_HasSSE2
#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().

1585 {
1586  for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) {
1587  if (format_list[format_idx][0] == format) {
1588  break;
1589  }
1590  }
1591  format_idx_sub = 0;
1592  return SDL_NextAudioFormat();
1593 }
static int format_idx_sub
Definition: SDL_audio.c:1559
static int format_idx
Definition: SDL_audio.c:1558
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1560
SDL_AudioFormat SDL_NextAudioFormat(void)
Definition: SDL_audio.c:1596
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
#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().

465 {
470 }
static float * ResamplerFilter
Definition: SDL_audiocvt.c:431
static float * ResamplerFilterDifference
Definition: SDL_audiocvt.c:432
#define SDL_free
#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().

1597 {
1598  if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) {
1599  return 0;
1600  }
1602 }
static int format_idx_sub
Definition: SDL_audio.c:1559
static int format_idx
Definition: SDL_audio.c:1558
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1560
#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().

436 {
438  if (!ResamplerFilter) {
439  /* if dB > 50, beta=(0.1102 * (dB - 8.7)), according to Matlab. */
440  const double dB = 80.0;
441  const double beta = 0.1102 * (dB - 8.7);
442  const size_t alloclen = RESAMPLER_FILTER_SIZE * sizeof (float);
443 
444  ResamplerFilter = (float *) SDL_malloc(alloclen);
445  if (!ResamplerFilter) {
447  return SDL_OutOfMemory();
448  }
449 
450  ResamplerFilterDifference = (float *) SDL_malloc(alloclen);
455  return SDL_OutOfMemory();
456  }
458  }
460  return 0;
461 }
#define SDL_AtomicLock
static SDL_SpinLock ResampleFilterSpinlock
Definition: SDL_audiocvt.c:430
static float * ResamplerFilter
Definition: SDL_audiocvt.c:431
static void kaiser_and_sinc(float *table, float *diffs, const int tablelen, const double beta)
Definition: SDL_audiocvt.c:409
static float * ResamplerFilterDifference
Definition: SDL_audiocvt.c:432
#define SDL_AtomicUnlock
#define SDL_free
#define RESAMPLER_FILTER_SIZE
Definition: SDL_audiocvt.c:383
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_malloc

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().