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)
 
SDL_AudioStreamSDL_NewAudioStream (const SDL_AudioFormat src_format, const Uint8 src_channels, const int src_rate, const SDL_AudioFormat dst_format, const Uint8 dst_channels, const int dst_rate)
 
int SDL_AudioStreamPut (SDL_AudioStream *stream, const void *buf, const Uint32 len)
 
int SDL_AudioStreamGet (SDL_AudioStream *stream, void *buf, const Uint32 len)
 
void SDL_AudioStreamClear (SDL_AudioStream *stream)
 
int SDL_AudioStreamAvailable (SDL_AudioStream *stream)
 
void SDL_FreeAudioStream (SDL_AudioStream *stream)
 

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

#define DEBUG_CONVERT   0

Definition at line 28 of file SDL_audio_c.h.

Function Documentation

int SDL_AudioStreamAvailable ( SDL_AudioStream stream)

Definition at line 1476 of file SDL_audiocvt.c.

References SDL_AudioStream::queue, and SDL_CountDataQueue().

Referenced by SDL_CaptureAudio(), and SDL_RunAudio().

1477 {
1478  return stream ? (int) SDL_CountDataQueue(stream->queue) : 0;
1479 }
SDL_DataQueue * queue
size_t SDL_CountDataQueue(SDL_DataQueue *queue)
void SDL_AudioStreamClear ( SDL_AudioStream stream)

Definition at line 1444 of file SDL_audiocvt.c.

References SDL_AudioStream::packetlen, SDL_AudioStream::queue, SDL_AudioStream::reset_resampler_func, SDL_ClearDataQueue(), and SDL_InvalidParamError.

Referenced by SDL_CaptureAudio().

1445 {
1446  if (!stream) {
1447  SDL_InvalidParamError("stream");
1448  } else {
1449  SDL_ClearDataQueue(stream->queue, stream->packetlen * 2);
1450  if (stream->reset_resampler_func) {
1451  stream->reset_resampler_func(stream);
1452  }
1453  }
1454 }
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
SDL_ResetAudioStreamResamplerFunc reset_resampler_func
void SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
Definition: SDL_dataqueue.c:98
SDL_DataQueue * queue
int SDL_AudioStreamGet ( SDL_AudioStream stream,
void buf,
const Uint32  len 
)

Definition at line 1459 of file SDL_audiocvt.c.

References SDL_AudioStream::dst_sample_frame_size, SDL_AudioStream::queue, SDL_InvalidParamError, SDL_ReadFromDataQueue(), and SDL_SetError.

Referenced by SDL_CaptureAudio(), and SDL_RunAudio().

1460 {
1461  if (!stream) {
1462  return SDL_InvalidParamError("stream");
1463  } else if (!buf) {
1464  return SDL_InvalidParamError("buf");
1465  } else if (len == 0) {
1466  return 0; /* nothing to do. */
1467  } else if ((len % stream->dst_sample_frame_size) != 0) {
1468  return SDL_SetError("Can't request partial sample frames");
1469  }
1470 
1471  return (int) SDL_ReadFromDataQueue(stream->queue, buf, len);
1472 }
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
GLenum GLsizei len
size_t SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
GLenum GLuint GLenum GLsizei const GLchar * buf
#define SDL_SetError
SDL_DataQueue * queue
int SDL_AudioStreamPut ( SDL_AudioStream stream,
const void buf,
const Uint32  len 
)

Definition at line 1366 of file SDL_audiocvt.c.

References SDL_AudioCVT::buf, SDL_AudioStream::cvt_after_resampling, SDL_AudioStream::cvt_before_resampling, SDL_AudioStream::dst_rate, EnsureStreamBufferSize(), SDL_AudioCVT::len, SDL_AudioCVT::len_cvt, SDL_AudioCVT::len_mult, SDL_AudioCVT::needed, NULL, SDL_AudioStream::queue, SDL_AudioStream::rate_incr, SDL_AudioStream::resampler_func, SDL_assert, SDL_ceil, SDL_ConvertAudio(), SDL_InvalidParamError, SDL_memcpy, SDL_SetError, SDL_WriteToDataQueue(), SDL_AudioStream::src_rate, and SDL_AudioStream::src_sample_frame_size.

Referenced by SDL_CaptureAudio(), and SDL_RunAudio().

1367 {
1368  int buflen = (int) _buflen;
1369  const void *origbuf = buf;
1370 
1371  /* !!! FIXME: several converters can take advantage of SIMD, but only
1372  !!! FIXME: if the data is aligned to 16 bytes. EnsureStreamBufferSize()
1373  !!! FIXME: guarantees the buffer will align, but the
1374  !!! FIXME: converters will iterate over the data backwards if
1375  !!! FIXME: the output grows, and this means we won't align if buflen
1376  !!! FIXME: isn't a multiple of 16. In these cases, we should chop off
1377  !!! FIXME: a few samples at the end and convert them separately. */
1378 
1379  if (!stream) {
1380  return SDL_InvalidParamError("stream");
1381  } else if (!buf) {
1382  return SDL_InvalidParamError("buf");
1383  } else if (buflen == 0) {
1384  return 0; /* nothing to do. */
1385  } else if ((buflen % stream->src_sample_frame_size) != 0) {
1386  return SDL_SetError("Can't add partial sample frames");
1387  }
1388 
1389  if (stream->cvt_before_resampling.needed) {
1390  const int workbuflen = buflen * stream->cvt_before_resampling.len_mult; /* will be "* 1" if not needed */
1391  Uint8 *workbuf = EnsureStreamBufferSize(stream, workbuflen);
1392  if (workbuf == NULL) {
1393  return -1; /* probably out of memory. */
1394  }
1395  SDL_assert(buf == origbuf);
1396  SDL_memcpy(workbuf, buf, buflen);
1397  stream->cvt_before_resampling.buf = workbuf;
1398  stream->cvt_before_resampling.len = buflen;
1399  if (SDL_ConvertAudio(&stream->cvt_before_resampling) == -1) {
1400  return -1; /* uhoh! */
1401  }
1402  buf = workbuf;
1403  buflen = stream->cvt_before_resampling.len_cvt;
1404  }
1405 
1406  if (stream->dst_rate != stream->src_rate) {
1407  const int workbuflen = buflen * ((int) SDL_ceil(stream->rate_incr));
1408  Uint8 *workbuf = EnsureStreamBufferSize(stream, workbuflen);
1409  if (workbuf == NULL) {
1410  return -1; /* probably out of memory. */
1411  }
1412  /* don't SDL_memcpy(workbuf, buf, buflen) here; our resampler can work inplace or not,
1413  libsamplerate needs buffers to be separate; either way, avoid a copy here if possible. */
1414  if (buf != origbuf) {
1415  buf = workbuf; /* in case we realloc()'d the pointer. */
1416  }
1417  buflen = stream->resampler_func(stream, buf, buflen, workbuf, workbuflen);
1418  buf = EnsureStreamBufferSize(stream, workbuflen);
1419  SDL_assert(buf != NULL); /* shouldn't be growing, just aligning. */
1420  }
1421 
1422  if (stream->cvt_after_resampling.needed) {
1423  const int workbuflen = buflen * stream->cvt_after_resampling.len_mult; /* will be "* 1" if not needed */
1424  Uint8 *workbuf = EnsureStreamBufferSize(stream, workbuflen);
1425  if (workbuf == NULL) {
1426  return -1; /* probably out of memory. */
1427  }
1428  if (buf == origbuf) { /* copy if we haven't before. */
1429  SDL_memcpy(workbuf, origbuf, buflen);
1430  }
1431  stream->cvt_after_resampling.buf = workbuf;
1432  stream->cvt_after_resampling.len = buflen;
1433  if (SDL_ConvertAudio(&stream->cvt_after_resampling) == -1) {
1434  return -1; /* uhoh! */
1435  }
1436  buf = workbuf;
1437  buflen = stream->cvt_after_resampling.len_cvt;
1438  }
1439 
1440  return SDL_WriteToDataQueue(stream->queue, buf, buflen);
1441 }
#define SDL_ceil
SDL_AudioCVT cvt_before_resampling
int SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
Uint8 * buf
Definition: SDL_audio.h:222
SDL_AudioCVT cvt_after_resampling
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
static Uint8 * EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen)
#define SDL_memcpy
uint8_t Uint8
Definition: SDL_stdinc.h:157
SDL_ResampleAudioStreamFunc resampler_func
int SDL_ConvertAudio(SDL_AudioCVT *cvt)
Definition: SDL_audiocvt.c:530
GLenum GLuint GLenum GLsizei const GLchar * buf
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define NULL
Definition: begin_code.h:164
#define SDL_SetError
SDL_DataQueue * queue
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:173
Uint16 samples
Definition: SDL_audio.h:174
#define AUDIO_U8
Definition: SDL_audio.h:89
Uint8 channels
Definition: SDL_audio.h:172
#define SDL_AUDIO_BITSIZE(x)
Definition: SDL_audio.h:75
Uint32 size
Definition: SDL_audio.h:176
SDL_AudioFormat format
Definition: SDL_audio.h:171
void SDL_ChooseAudioConverters ( void  )

Definition at line 747 of file SDL_audiotypecvt.c.

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

Referenced by SDL_BuildAudioCVT().

748 {
749  static SDL_bool converters_chosen = SDL_FALSE;
750 
751  if (converters_chosen) {
752  return;
753  }
754 
755 #define SET_CONVERTER_FUNCS(fntype) \
756  SDL_Convert_S8_to_F32 = SDL_Convert_S8_to_F32_##fntype; \
757  SDL_Convert_U8_to_F32 = SDL_Convert_U8_to_F32_##fntype; \
758  SDL_Convert_S16_to_F32 = SDL_Convert_S16_to_F32_##fntype; \
759  SDL_Convert_U16_to_F32 = SDL_Convert_U16_to_F32_##fntype; \
760  SDL_Convert_S32_to_F32 = SDL_Convert_S32_to_F32_##fntype; \
761  SDL_Convert_F32_to_S8 = SDL_Convert_F32_to_S8_##fntype; \
762  SDL_Convert_F32_to_U8 = SDL_Convert_F32_to_U8_##fntype; \
763  SDL_Convert_F32_to_S16 = SDL_Convert_F32_to_S16_##fntype; \
764  SDL_Convert_F32_to_U16 = SDL_Convert_F32_to_U16_##fntype; \
765  SDL_Convert_F32_to_S32 = SDL_Convert_F32_to_S32_##fntype; \
766  converters_chosen = SDL_TRUE
767 
768 #if HAVE_SSE2_INTRINSICS
769  if (SDL_HasSSE2()) {
770  SET_CONVERTER_FUNCS(SSE2);
771  return;
772  }
773 #endif
774 
775 #if NEED_SCALAR_CONVERTER_FALLBACKS
776  SET_CONVERTER_FUNCS(Scalar);
777 #endif
778 
779 #undef SET_CONVERTER_FUNCS
780 
781  SDL_assert(converters_chosen == SDL_TRUE);
782 }
#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_AudioFormat SDL_FirstAudioFormat ( SDL_AudioFormat  format)

Definition at line 1577 of file SDL_audio.c.

References format_idx, 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
void SDL_FreeAudioStream ( SDL_AudioStream stream)

Definition at line 1483 of file SDL_audiocvt.c.

References SDL_AudioStream::cleanup_resampler_func, SDL_AudioStream::queue, SDL_free(), SDL_FreeDataQueue(), and SDL_AudioStream::work_buffer_base.

Referenced by close_audio_device(), and SDL_NewAudioStream().

1484 {
1485  if (stream) {
1486  if (stream->cleanup_resampler_func) {
1487  stream->cleanup_resampler_func(stream);
1488  }
1489  SDL_FreeDataQueue(stream->queue);
1490  SDL_free(stream->work_buffer_base);
1491  SDL_free(stream);
1492  }
1493 }
void SDL_free(void *mem)
SDL_CleanupAudioStreamResamplerFunc cleanup_resampler_func
SDL_DataQueue * queue
Uint8 * work_buffer_base
void SDL_FreeDataQueue(SDL_DataQueue *queue)
Definition: SDL_dataqueue.c:88
void SDL_FreeResampleFilter ( void  )

Definition at line 459 of file SDL_audiocvt.c.

References NULL, and SDL_free().

Referenced by SDL_AudioQuit().

460 {
465 }
static float * ResamplerFilter
Definition: SDL_audiocvt.c:426
static float * ResamplerFilterDifference
Definition: SDL_audiocvt.c:427
void SDL_free(void *mem)
#define NULL
Definition: begin_code.h:164
SDL_AudioStream* SDL_NewAudioStream ( const SDL_AudioFormat  src_format,
const Uint8  src_channels,
const int  src_rate,
const SDL_AudioFormat  dst_format,
const Uint8  dst_channels,
const int  dst_rate 
)

Definition at line 1274 of file SDL_audiocvt.c.

References AUDIO_F32SYS, SDL_AudioStream::cleanup_resampler_func, SDL_AudioStream::cvt_after_resampling, SDL_AudioStream::cvt_before_resampling, SDL_AudioStream::dst_channels, SDL_AudioStream::dst_format, SDL_AudioStream::dst_rate, SDL_AudioStream::dst_sample_frame_size, SDL_AudioCVT::needed, NULL, SDL_AudioStream::packetlen, SDL_AudioStream::pre_resample_channels, SDL_AudioStream::queue, SDL_AudioStream::rate_incr, SDL_AudioStream::resampler_func, SDL_AudioStream::resampler_state, ResamplerPadding(), SDL_AudioStream::reset_resampler_func, retval, SDL_AUDIO_BITSIZE, SDL_BuildAudioCVT(), SDL_calloc(), SDL_CleanupAudioStreamResampler(), SDL_FALSE, SDL_free(), SDL_FreeAudioStream(), SDL_min, SDL_NewDataQueue(), SDL_OutOfMemory, SDL_PrepareResampleFilter(), SDL_ResampleAudioStream(), SDL_ResetAudioStreamResampler(), SDL_AudioStream::src_channels, SDL_AudioStream::src_format, SDL_AudioStream::src_rate, and SDL_AudioStream::src_sample_frame_size.

Referenced by open_audio_device().

1280 {
1281  const int packetlen = 4096; /* !!! FIXME: good enough for now. */
1282  Uint8 pre_resample_channels;
1284 
1285  retval = (SDL_AudioStream *) SDL_calloc(1, sizeof (SDL_AudioStream));
1286  if (!retval) {
1287  return NULL;
1288  }
1289 
1290  /* If increasing channels, do it after resampling, since we'd just
1291  do more work to resample duplicate channels. If we're decreasing, do
1292  it first so we resample the interpolated data instead of interpolating
1293  the resampled data (!!! FIXME: decide if that works in practice, though!). */
1294  pre_resample_channels = SDL_min(src_channels, dst_channels);
1295 
1296  retval->src_sample_frame_size = (SDL_AUDIO_BITSIZE(src_format) / 8) * src_channels;
1297  retval->src_format = src_format;
1298  retval->src_channels = src_channels;
1299  retval->src_rate = src_rate;
1300  retval->dst_sample_frame_size = (SDL_AUDIO_BITSIZE(dst_format) / 8) * dst_channels;
1301  retval->dst_format = dst_format;
1302  retval->dst_channels = dst_channels;
1303  retval->dst_rate = dst_rate;
1304  retval->pre_resample_channels = pre_resample_channels;
1305  retval->packetlen = packetlen;
1306  retval->rate_incr = ((double) dst_rate) / ((double) src_rate);
1307 
1308  /* Not resampling? It's an easy conversion (and maybe not even that!). */
1309  if (src_rate == dst_rate) {
1311  if (SDL_BuildAudioCVT(&retval->cvt_after_resampling, src_format, src_channels, dst_rate, dst_format, dst_channels, dst_rate) < 0) {
1312  SDL_FreeAudioStream(retval);
1313  return NULL; /* SDL_BuildAudioCVT should have called SDL_SetError. */
1314  }
1315  } else {
1316  /* Don't resample at first. Just get us to Float32 format. */
1317  /* !!! FIXME: convert to int32 on devices without hardware float. */
1318  if (SDL_BuildAudioCVT(&retval->cvt_before_resampling, src_format, src_channels, src_rate, AUDIO_F32SYS, pre_resample_channels, src_rate) < 0) {
1319  SDL_FreeAudioStream(retval);
1320  return NULL; /* SDL_BuildAudioCVT should have called SDL_SetError. */
1321  }
1322 
1323 #ifdef HAVE_LIBSAMPLERATE_H
1324  SetupLibSampleRateResampling(retval);
1325 #endif
1326 
1327  if (!retval->resampler_func) {
1328  const int chans = (int) pre_resample_channels;
1329  const int len = ResamplerPadding(src_rate, dst_rate) * chans;
1330  retval->resampler_state = SDL_calloc(len, sizeof (float));
1331  if (!retval->resampler_state) {
1332  SDL_FreeAudioStream(retval);
1333  SDL_OutOfMemory();
1334  return NULL;
1335  }
1336 
1337  if (SDL_PrepareResampleFilter() < 0) {
1338  SDL_free(retval->resampler_state);
1339  retval->resampler_state = NULL;
1340  SDL_FreeAudioStream(retval);
1341  return NULL;
1342  }
1343 
1347  }
1348 
1349  /* Convert us to the final format after resampling. */
1350  if (SDL_BuildAudioCVT(&retval->cvt_after_resampling, AUDIO_F32SYS, pre_resample_channels, dst_rate, dst_format, dst_channels, dst_rate) < 0) {
1351  SDL_FreeAudioStream(retval);
1352  return NULL; /* SDL_BuildAudioCVT should have called SDL_SetError. */
1353  }
1354  }
1355 
1356  retval->queue = SDL_NewDataQueue(packetlen, packetlen * 2);
1357  if (!retval->queue) {
1358  SDL_FreeAudioStream(retval);
1359  return NULL; /* SDL_NewDataQueue should have called SDL_SetError. */
1360  }
1361 
1362  return retval;
1363 }
static int ResamplerPadding(const int inrate, const int outrate)
Definition: SDL_audiocvt.c:468
#define SDL_min(x, y)
Definition: SDL_stdinc.h:375
SDL_AudioCVT cvt_before_resampling
SDL_AudioCVT cvt_after_resampling
void * resampler_state
SDL_AudioFormat src_format
SDL_DataQueue * SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack)
Definition: SDL_dataqueue.c:58
void SDL_FreeAudioStream(SDL_AudioStream *stream)
GLenum GLsizei len
SDL_bool retval
SDL_AudioFormat dst_format
static void SDL_ResetAudioStreamResampler(SDL_AudioStream *stream)
void * SDL_calloc(size_t nmemb, size_t size)
int SDL_PrepareResampleFilter(void)
Definition: SDL_audiocvt.c:430
#define AUDIO_F32SYS
Definition: SDL_audio.h:125
uint8_t Uint8
Definition: SDL_stdinc.h:157
void SDL_free(void *mem)
#define SDL_AUDIO_BITSIZE(x)
Definition: SDL_audio.h:75
SDL_ResampleAudioStreamFunc resampler_func
SDL_CleanupAudioStreamResamplerFunc cleanup_resampler_func
static int SDL_ResampleAudioStream(SDL_AudioStream *stream, const void *_inbuf, const int inbuflen, void *_outbuf, const int outbuflen)
SDL_ResetAudioStreamResamplerFunc reset_resampler_func
int SDL_BuildAudioCVT(SDL_AudioCVT *cvt, SDL_AudioFormat src_fmt, Uint8 src_channels, int src_rate, SDL_AudioFormat dst_fmt, Uint8 dst_channels, int dst_rate)
Definition: SDL_audiocvt.c:863
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
Uint8 pre_resample_channels
SDL_DataQueue * queue
static void SDL_CleanupAudioStreamResampler(SDL_AudioStream *stream)
SDL_AudioFormat SDL_NextAudioFormat ( void  )

Definition at line 1589 of file SDL_audio.c.

References format_idx, 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
int SDL_PrepareResampleFilter ( void  )

Definition at line 430 of file SDL_audiocvt.c.

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

Referenced by SDL_BuildAudioResampleCVT(), and SDL_NewAudioStream().

431 {
433  if (!ResamplerFilter) {
434  /* if dB > 50, beta=(0.1102 * (dB - 8.7)), according to Matlab. */
435  const double dB = 80.0;
436  const double beta = 0.1102 * (dB - 8.7);
437  const size_t alloclen = RESAMPLER_FILTER_SIZE * sizeof (float);
438 
439  ResamplerFilter = (float *) SDL_malloc(alloclen);
440  if (!ResamplerFilter) {
442  return SDL_OutOfMemory();
443  }
444 
445  ResamplerFilterDifference = (float *) SDL_malloc(alloclen);
450  return SDL_OutOfMemory();
451  }
453  }
455  return 0;
456 }
#define SDL_AtomicLock
static SDL_SpinLock ResampleFilterSpinlock
Definition: SDL_audiocvt.c:425
static float * ResamplerFilter
Definition: SDL_audiocvt.c:426
static void kaiser_and_sinc(float *table, float *diffs, const int tablelen, const double beta)
Definition: SDL_audiocvt.c:404
static float * ResamplerFilterDifference
Definition: SDL_audiocvt.c:427
#define SDL_AtomicUnlock
void SDL_free(void *mem)
#define RESAMPLER_FILTER_SIZE
Definition: SDL_audiocvt.c:378
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_malloc

Variable Documentation

SDL_AudioFilter SDL_Convert_F32_to_S16

Definition at line 58 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

SDL_AudioFilter SDL_Convert_F32_to_S32

Definition at line 60 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

SDL_AudioFilter SDL_Convert_F32_to_S8

Definition at line 56 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

SDL_AudioFilter SDL_Convert_F32_to_U16

Definition at line 59 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

SDL_AudioFilter SDL_Convert_F32_to_U8

Definition at line 57 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTFromFloat().

SDL_AudioFilter SDL_Convert_S16_to_F32

Definition at line 53 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

SDL_AudioFilter SDL_Convert_S32_to_F32

Definition at line 55 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

SDL_AudioFilter SDL_Convert_S8_to_F32

Definition at line 51 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

SDL_AudioFilter SDL_Convert_U16_to_F32

Definition at line 54 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().

SDL_AudioFilter SDL_Convert_U8_to_F32

Definition at line 52 of file SDL_audiotypecvt.c.

Referenced by SDL_BuildAudioTypeCVTToFloat().