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

1599 {
1600  switch (spec->format) {
1601  case AUDIO_U8:
1602  spec->silence = 0x80;
1603  break;
1604  default:
1605  spec->silence = 0x00;
1606  break;
1607  }
1608  spec->size = SDL_AUDIO_BITSIZE(spec->format) / 8;
1609  spec->size *= spec->channels;
1610  spec->size *= spec->samples;
1611 }
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 782 of file SDL_audiotypecvt.c.

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

Referenced by SDL_BuildAudioCVT().

783 {
784  static SDL_bool converters_chosen = SDL_FALSE;
785 
786  if (converters_chosen) {
787  return;
788  }
789 
790 #define SET_CONVERTER_FUNCS(fntype) \
791  SDL_Convert_S8_to_F32 = SDL_Convert_S8_to_F32_##fntype; \
792  SDL_Convert_U8_to_F32 = SDL_Convert_U8_to_F32_##fntype; \
793  SDL_Convert_S16_to_F32 = SDL_Convert_S16_to_F32_##fntype; \
794  SDL_Convert_U16_to_F32 = SDL_Convert_U16_to_F32_##fntype; \
795  SDL_Convert_S32_to_F32 = SDL_Convert_S32_to_F32_##fntype; \
796  SDL_Convert_F32_to_S8 = SDL_Convert_F32_to_S8_##fntype; \
797  SDL_Convert_F32_to_U8 = SDL_Convert_F32_to_U8_##fntype; \
798  SDL_Convert_F32_to_S16 = SDL_Convert_F32_to_S16_##fntype; \
799  SDL_Convert_F32_to_U16 = SDL_Convert_F32_to_U16_##fntype; \
800  SDL_Convert_F32_to_S32 = SDL_Convert_F32_to_S32_##fntype; \
801  converters_chosen = SDL_TRUE
802 
803 #if HAVE_SSE2_INTRINSICS
804  if (SDL_HasSSE2()) {
805  SET_CONVERTER_FUNCS(SSE2);
806  return;
807  }
808 #endif
809 
810 #if NEED_SCALAR_CONVERTER_FALLBACKS
811  SET_CONVERTER_FUNCS(Scalar);
812 #endif
813 
814 #undef SET_CONVERTER_FUNCS
815 
816  SDL_assert(converters_chosen == SDL_TRUE);
817 }
#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 1577 of file SDL_audio.c.

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

1578 {
1579  for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) {
1580  if (format_list[format_idx][0] == format) {
1581  break;
1582  }
1583  }
1584  format_idx_sub = 0;
1585  return SDL_NextAudioFormat();
1586 }
static int format_idx_sub
Definition: SDL_audio.c:1552
static int format_idx
Definition: SDL_audio.c:1551
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1553
SDL_AudioFormat SDL_NextAudioFormat(void)
Definition: SDL_audio.c:1589
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
#define NUM_FORMATS
Definition: SDL_audio.c:1550

◆ 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 1589 of file SDL_audio.c.

References format_idx, format_idx_sub, format_list, and NUM_FORMATS.

Referenced by SDL_FirstAudioFormat().

1590 {
1591  if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) {
1592  return 0;
1593  }
1595 }
static int format_idx_sub
Definition: SDL_audio.c:1552
static int format_idx
Definition: SDL_audio.c:1551
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1553
#define NUM_FORMATS
Definition: SDL_audio.c:1550

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