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)
 
Uint8 SDL_SilenceValueForFormat (const SDL_AudioFormat format)
 
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.

Function Documentation

◆ SDL_CalculateAudioSpec()

void SDL_CalculateAudioSpec ( SDL_AudioSpec spec)

Definition at line 1689 of file SDL_audio.c.

1690 {
1693  spec->size *= spec->channels;
1694  spec->size *= spec->samples;
1695 }
Uint8 SDL_SilenceValueForFormat(const SDL_AudioFormat format)
Definition: SDL_audio.c:1671
#define SDL_AUDIO_BITSIZE(x)
Definition: SDL_audio.h:75
SDL_AudioSpec spec
Definition: loopwave.c:31
Uint32 size
Definition: SDL_audio.h:186
Uint16 samples
Definition: SDL_audio.h:184
Uint8 channels
Definition: SDL_audio.h:182
Uint8 silence
Definition: SDL_audio.h:183
SDL_AudioFormat format
Definition: SDL_audio.h:181

References SDL_AudioSpec::channels, SDL_AudioSpec::format, SDL_AudioSpec::samples, SDL_AUDIO_BITSIZE, SDL_SilenceValueForFormat(), SDL_AudioSpec::silence, SDL_AudioSpec::size, and spec.

Referenced by open_audio_device(), and prepare_audiospec().

◆ 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_TRUE
Definition: SDL_stdinc.h:170
@ 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_FirstAudioFormat()

SDL_AudioFormat SDL_FirstAudioFormat ( SDL_AudioFormat  format)

Definition at line 1650 of file SDL_audio.c.

1651 {
1652  for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) {
1653  if (format_list[format_idx][0] == format) {
1654  break;
1655  }
1656  }
1657  format_idx_sub = 0;
1658  return SDL_NextAudioFormat();
1659 }
static int format_idx_sub
Definition: SDL_audio.c:1625
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
Definition: SDL_audio.c:1626
#define NUM_FORMATS
Definition: SDL_audio.c:1623
static int format_idx
Definition: SDL_audio.c:1624
SDL_AudioFormat SDL_NextAudioFormat(void)
Definition: SDL_audio.c:1662
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572

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

◆ SDL_FreeResampleFilter()

void SDL_FreeResampleFilter ( void  )

Definition at line 463 of file SDL_audiocvt.c.

464 {
469 }
static float * ResamplerFilterDifference
Definition: SDL_audiocvt.c:431
static float * ResamplerFilter
Definition: SDL_audiocvt.c:430
#define SDL_free
#define NULL
Definition: begin_code.h:163

References NULL, ResamplerFilter, ResamplerFilterDifference, and SDL_free.

Referenced by SDL_AudioQuit().

◆ SDL_NextAudioFormat()

SDL_AudioFormat SDL_NextAudioFormat ( void  )

Definition at line 1662 of file SDL_audio.c.

1663 {
1664  if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) {
1665  return 0;
1666  }
1668 }

References format_idx, format_idx_sub, format_list, and NUM_FORMATS.

Referenced by SDL_FirstAudioFormat().

◆ SDL_PrepareResampleFilter()

int SDL_PrepareResampleFilter ( void  )

Definition at line 434 of file SDL_audiocvt.c.

435 {
437  if (!ResamplerFilter) {
438  /* if dB > 50, beta=(0.1102 * (dB - 8.7)), according to Matlab. */
439  const double dB = 80.0;
440  const double beta = 0.1102 * (dB - 8.7);
441  const size_t alloclen = RESAMPLER_FILTER_SIZE * sizeof (float);
442 
443  ResamplerFilter = (float *) SDL_malloc(alloclen);
444  if (!ResamplerFilter) {
446  return SDL_OutOfMemory();
447  }
448 
449  ResamplerFilterDifference = (float *) SDL_malloc(alloclen);
454  return SDL_OutOfMemory();
455  }
457  }
459  return 0;
460 }
static void kaiser_and_sinc(float *table, float *diffs, const int tablelen, const double beta)
Definition: SDL_audiocvt.c:408
static SDL_SpinLock ResampleFilterSpinlock
Definition: SDL_audiocvt.c:429
#define RESAMPLER_FILTER_SIZE
Definition: SDL_audiocvt.c:382
#define SDL_AtomicLock
#define SDL_malloc
#define SDL_AtomicUnlock
#define SDL_OutOfMemory()
Definition: SDL_error.h:88

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

Uint8 SDL_SilenceValueForFormat ( const SDL_AudioFormat  format)

Definition at line 1671 of file SDL_audio.c.

1672 {
1673  switch (format) {
1674  /* !!! FIXME: 0x80 isn't perfect for U16, but we can't fit 0x8000 in a
1675  !!! FIXME: byte for memset() use. This is actually 0.1953 percent
1676  !!! FIXME: off from silence. Maybe just don't use U16. */
1677  case AUDIO_U16LSB:
1678  case AUDIO_U16MSB:
1679  case AUDIO_U8:
1680  return 0x80;
1681 
1682  default: break;
1683  }
1684 
1685  return 0x00;
1686 }
#define AUDIO_U16LSB
Definition: SDL_audio.h:91
#define AUDIO_U16MSB
Definition: SDL_audio.h:93
#define AUDIO_U8
Definition: SDL_audio.h:89

References AUDIO_U16LSB, AUDIO_U16MSB, and AUDIO_U8.

Referenced by SDL_CalculateAudioSpec(), and WaveLoad().

Variable Documentation

◆ SDL_Convert_F32_to_S16

SDL_AudioFilter SDL_Convert_F32_to_S16
extern

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
extern

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
extern

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
extern

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
extern

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
extern

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
extern

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
extern

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
extern

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
extern

Definition at line 52 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().