SDL
2.0
|
#include "../SDL_internal.h"
#include "SDL.h"
#include "SDL_audio.h"
#include "SDL_audio_c.h"
#include "SDL_loadso.h"
#include "SDL_assert.h"
#include "../SDL_dataqueue.h"
#include "SDL_cpuinfo.h"
Go to the source code of this file.
Data Structures | |
struct | SDL_AudioStream |
Macros | |
#define | DEBUG_AUDIOSTREAM 0 |
#define | RESAMPLER_ZERO_CROSSINGS 5 |
#define | RESAMPLER_BITS_PER_SAMPLE 16 |
#define | RESAMPLER_SAMPLES_PER_ZERO_CROSSING (1 << ((RESAMPLER_BITS_PER_SAMPLE / 2) + 1)) |
#define | RESAMPLER_FILTER_SIZE ((RESAMPLER_SAMPLES_PER_ZERO_CROSSING * RESAMPLER_ZERO_CROSSINGS) + 1) |
#define | CASESWAP(b) |
#define | RESAMPLER_FUNCS(chans) |
Typedefs | |
typedef int(* | SDL_ResampleAudioStreamFunc) (SDL_AudioStream *stream, const void *inbuf, const int inbuflen, void *outbuf, const int outbuflen) |
typedef void(* | SDL_ResetAudioStreamResamplerFunc) (SDL_AudioStream *stream) |
typedef void(* | SDL_CleanupAudioStreamResamplerFunc) (SDL_AudioStream *stream) |
Variables | |
static SDL_SpinLock | ResampleFilterSpinlock = 0 |
static float * | ResamplerFilter = NULL |
static float * | ResamplerFilterDifference = NULL |
#define CASESWAP | ( | b | ) |
Referenced by SDL_Convert_Byteswap().
#define DEBUG_AUDIOSTREAM 0 |
Definition at line 37 of file SDL_audiocvt.c.
Referenced by SDL_AudioStreamFlush().
#define RESAMPLER_BITS_PER_SAMPLE 16 |
Definition at line 381 of file SDL_audiocvt.c.
#define RESAMPLER_FILTER_SIZE ((RESAMPLER_SAMPLES_PER_ZERO_CROSSING * RESAMPLER_ZERO_CROSSINGS) + 1) |
Definition at line 383 of file SDL_audiocvt.c.
Referenced by SDL_PrepareResampleFilter(), and SDL_ResampleAudio().
#define RESAMPLER_FUNCS | ( | chans | ) |
Definition at line 748 of file SDL_audiocvt.c.
#define RESAMPLER_SAMPLES_PER_ZERO_CROSSING (1 << ((RESAMPLER_BITS_PER_SAMPLE / 2) + 1)) |
Definition at line 382 of file SDL_audiocvt.c.
Referenced by kaiser_and_sinc(), ResamplerPadding(), and SDL_ResampleAudio().
#define RESAMPLER_ZERO_CROSSINGS 5 |
Definition at line 380 of file SDL_audiocvt.c.
Definition at line 1081 of file SDL_audiocvt.c.
typedef int(* SDL_ResampleAudioStreamFunc) (SDL_AudioStream *stream, const void *inbuf, const int inbuflen, void *outbuf, const int outbuflen) |
Definition at line 1079 of file SDL_audiocvt.c.
Definition at line 1080 of file SDL_audiocvt.c.
|
static |
Definition at line 387 of file SDL_audiocvt.c.
References e, i, SDL_pow, and SDL_TRUE.
Referenced by kaiser_and_sinc().
|
static |
Definition at line 761 of file SDL_audiocvt.c.
References NULL.
Referenced by SDL_BuildAudioResampleCVT().
|
static |
Definition at line 1114 of file SDL_audiocvt.c.
References NULL, SDL_assert, SDL_FALSE, SDL_OutOfMemory, SDL_realloc, SDL_SetError, SDL_TRUE, and state.
Referenced by SDL_AudioStreamPutInternal().
|
static |
Definition at line 409 of file SDL_audiocvt.c.
References bessel(), i, RESAMPLER_SAMPLES_PER_ZERO_CROSSING, SDL_pow, SDL_sinf, and SDL_sqrt.
Referenced by SDL_PrepareResampleFilter().
|
static |
Definition at line 473 of file SDL_audiocvt.c.
References RESAMPLER_SAMPLES_PER_ZERO_CROSSING, and SDL_ceil.
Referenced by SDL_NewAudioStream(), SDL_ResampleAudio(), and SDL_ResampleCVT().
|
static |
Definition at line 601 of file SDL_audiocvt.c.
References SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, NULL, SDL_AUDIOCVT_MAX_FILTERS, and SDL_SetError.
Referenced by SDL_BuildAudioCVT(), SDL_BuildAudioResampleCVT(), SDL_BuildAudioTypeCVTFromFloat(), and SDL_BuildAudioTypeCVTToFloat().
int SDL_AudioStreamAvailable | ( | SDL_AudioStream * | stream | ) |
Get the number of converted/resampled bytes available. The stream may be buffering data behind the scenes until it has enough to resample correctly, so this number might be lower than what you expect, or even be zero. Add more data or flush the stream if you need the data now.
Definition at line 1636 of file SDL_audiocvt.c.
References SDL_CountDataQueue().
void SDL_AudioStreamClear | ( | SDL_AudioStream * | stream | ) |
Clear any pending data in the stream without converting it
Definition at line 1642 of file SDL_audiocvt.c.
References SDL_ClearDataQueue(), SDL_InvalidParamError, and SDL_TRUE.
int SDL_AudioStreamFlush | ( | SDL_AudioStream * | stream | ) |
Tell the stream that you're done sending data, and anything being buffered should be converted/resampled and made available immediately.
It is legal to add more data to a stream after flushing, but there will be audio gaps in the output. Generally this is intended to signal the end of input, so the complete output becomes available.
Definition at line 1561 of file SDL_audiocvt.c.
References DEBUG_AUDIOSTREAM, SDL_AudioStream::first_run, SDL_assert, SDL_AudioStreamPutInternal(), SDL_ceil, SDL_InvalidParamError, SDL_memset, and SDL_TRUE.
int SDL_AudioStreamGet | ( | SDL_AudioStream * | stream, |
void * | buf, | ||
int | len | ||
) |
Get converted/resampled data from the stream
stream | The stream the audio is being requested from |
buf | A buffer to fill with audio data |
len | The maximum number of bytes to fill |
Definition at line 1615 of file SDL_audiocvt.c.
References SDL_InvalidParamError, SDL_ReadFromDataQueue(), and SDL_SetError.
int SDL_AudioStreamPut | ( | SDL_AudioStream * | stream, |
const void * | buf, | ||
int | len | ||
) |
Add data to be converted/resampled to the stream
stream | The stream the audio data is being added to |
buf | A pointer to the audio data to add |
len | The number of bytes to write to the stream |
Definition at line 1497 of file SDL_audiocvt.c.
References NULL, SDL_assert, SDL_AudioStreamPutInternal(), SDL_InvalidParamError, SDL_memcpy, SDL_SetError, and SDL_WriteToDataQueue().
|
static |
Definition at line 1368 of file SDL_audiocvt.c.
References EnsureStreamBufferSize(), NULL, SDL_assert, SDL_ceil, SDL_ConvertAudio(), SDL_FALSE, SDL_memcpy, and SDL_WriteToDataQueue().
Referenced by SDL_AudioStreamFlush(), and SDL_AudioStreamPut().
int SDL_BuildAudioCVT | ( | SDL_AudioCVT * | cvt, |
SDL_AudioFormat | src_format, | ||
Uint8 | src_channels, | ||
int | src_rate, | ||
SDL_AudioFormat | dst_format, | ||
Uint8 | dst_channels, | ||
int | dst_rate | ||
) |
This function takes a source format and rate and a destination format and rate, and initializes the cvt
structure with information needed by SDL_ConvertAudio() to convert a buffer of audio data from one format to the other. An unsupported format causes an error and -1 will be returned.
Definition at line 872 of file SDL_audiocvt.c.
References SDL_AudioCVT::dst_format, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, SDL_AudioCVT::len_mult, SDL_AudioCVT::len_ratio, SDL_AudioCVT::needed, NULL, SDL_AudioCVT::rate_incr, SDL_AddAudioCVTFilter(), SDL_AUDIO_MASK_ENDIAN, SDL_BuildAudioResampleCVT(), SDL_BuildAudioTypeCVTFromFloat(), SDL_BuildAudioTypeCVTToFloat(), SDL_ChooseAudioConverters(), SDL_Convert51To71(), SDL_Convert51ToQuad(), SDL_Convert51ToStereo(), SDL_Convert71To51(), SDL_Convert_Byteswap(), SDL_ConvertMonoToStereo(), SDL_ConvertQuadTo51(), SDL_ConvertQuadToStereo(), SDL_ConvertStereoTo51(), SDL_ConvertStereoToMono(), SDL_ConvertStereoToQuad(), SDL_HasSSE3, SDL_InvalidParamError, SDL_SetError, SDL_SupportedAudioFormat(), SDL_SupportedChannelCount(), SDL_zero, SDL_zerop, and SDL_AudioCVT::src_format.
Referenced by SDL_NewAudioStream().
|
static |
Definition at line 776 of file SDL_audiocvt.c.
References ChooseCVTResampler(), SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, SDL_AudioCVT::len_mult, SDL_AudioCVT::len_ratio, NULL, SDL_AddAudioCVTFilter(), SDL_AUDIOCVT_MAX_FILTERS, SDL_ceil, SDL_PrepareResampleFilter(), and SDL_SetError.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 662 of file SDL_audiocvt.c.
References AUDIO_S16, AUDIO_S32, AUDIO_S8, AUDIO_U16, AUDIO_U8, SDL_AudioCVT::len_mult, SDL_AudioCVT::len_ratio, NULL, retval, SDL_AddAudioCVTFilter(), SDL_assert, SDL_AUDIO_BITSIZE, SDL_AUDIO_ISBIGENDIAN, SDL_AUDIO_ISFLOAT, SDL_AUDIO_MASK_ENDIAN, SDL_BYTEORDER, SDL_Convert_Byteswap(), SDL_Convert_F32_to_S16, SDL_Convert_F32_to_S32, SDL_Convert_F32_to_S8, SDL_Convert_F32_to_U16, SDL_Convert_F32_to_U8, SDL_LIL_ENDIAN, and SDL_SetError.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 615 of file SDL_audiocvt.c.
References AUDIO_S16, AUDIO_S32, AUDIO_S8, AUDIO_U16, AUDIO_U8, SDL_AudioCVT::len_mult, SDL_AudioCVT::len_ratio, NULL, retval, SDL_AddAudioCVTFilter(), SDL_assert, SDL_AUDIO_BITSIZE, SDL_AUDIO_ISBIGENDIAN, SDL_AUDIO_ISFLOAT, SDL_AUDIO_MASK_ENDIAN, SDL_BYTEORDER, SDL_Convert_Byteswap(), SDL_Convert_S16_to_F32, SDL_Convert_S32_to_F32, SDL_Convert_S8_to_F32, SDL_Convert_U16_to_F32, SDL_Convert_U8_to_F32, SDL_LIL_ENDIAN, and SDL_SetError.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 1253 of file SDL_audiocvt.c.
References SDL_free.
Referenced by SDL_NewAudioStream().
|
static |
Definition at line 335 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, LOG_DEBUG_CONVERT, and SDL_assert.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 181 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, LOG_DEBUG_CONVERT, SDL_assert, and SDLCALL.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 103 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, LOG_DEBUG_CONVERT, SDL_assert, and SDLCALL.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 151 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, LOG_DEBUG_CONVERT, SDL_assert, and SDLCALL.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 563 of file SDL_audiocvt.c.
References CASESWAP, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, SDL_assert, SDL_AUDIO_BITSIZE, and SDL_AUDIO_MASK_ENDIAN.
Referenced by SDL_BuildAudioCVT(), SDL_BuildAudioTypeCVTFromFloat(), and SDL_BuildAudioTypeCVTToFloat().
int SDL_ConvertAudio | ( | SDL_AudioCVT * | cvt | ) |
Once you have initialized the cvt
structure using SDL_BuildAudioCVT(), created an audio buffer cvt->buf
, and filled it with cvt->len
bytes of audio data in the source format, this function will convert it in-place to the desired format.
The data conversion may expand the size of the audio data, so the buffer cvt->buf
should be allocated after the cvt
structure is initialized by SDL_BuildAudioCVT(), and should be cvt->len*cvt->len_mult
bytes long.
cvt->buf
is NULL. Definition at line 540 of file SDL_audiocvt.c.
References SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, SDL_AudioCVT::len, SDL_AudioCVT::len_cvt, NULL, SDL_SetError, SDLCALL, and SDL_AudioCVT::src_format.
Referenced by SDL_AudioStreamPutInternal().
|
static |
Definition at line 210 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, LOG_DEBUG_CONVERT, SDL_assert, and SDLCALL.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 268 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, LOG_DEBUG_CONVERT, SDL_assert, and SDLCALL.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 128 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, LOG_DEBUG_CONVERT, SDL_assert, and SDLCALL.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 234 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, LOG_DEBUG_CONVERT, SDL_assert, and SDLCALL.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 81 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, LOG_DEBUG_CONVERT, SDL_assert, and SDLCALL.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 305 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, i, SDL_AudioCVT::len_cvt, LOG_DEBUG_CONVERT, SDL_assert, and SDLCALL.
Referenced by SDL_BuildAudioCVT().
void SDL_FreeAudioStream | ( | SDL_AudioStream * | stream | ) |
Free an audio stream
Definition at line 1658 of file SDL_audiocvt.c.
References SDL_free, and SDL_FreeDataQueue().
Referenced by SDL_NewAudioStream().
Definition at line 464 of file SDL_audiocvt.c.
References NULL, ResamplerFilter, ResamplerFilterDifference, and SDL_free.
Referenced by SDL_AudioQuit().
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 | ||
) |
Create a new audio stream
src_format | The format of the source audio |
src_channels | The number of channels of the source audio |
src_rate | The sampling rate of the source audio |
dst_format | The format of the desired audio output |
dst_channels | The number of channels of the desired audio output |
dst_rate | The sampling rate of the desired audio output |
Definition at line 1259 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioStream::dst_channels, SDL_AudioStream::dst_format, SDL_AudioStream::dst_rate, NULL, SDL_AudioStream::packetlen, SDL_AudioStream::pre_resample_channels, ResamplerPadding(), retval, SDL_AUDIO_BITSIZE, SDL_BuildAudioCVT(), SDL_calloc, SDL_CleanupAudioStreamResampler(), SDL_FALSE, SDL_free, SDL_FreeAudioStream(), SDL_malloc, SDL_min, SDL_NewDataQueue(), SDL_OutOfMemory, SDL_PrepareResampleFilter(), SDL_ResampleAudioStream(), SDL_ResetAudioStreamResampler(), SDL_TRUE, SDL_AudioStream::src_channels, SDL_AudioStream::src_format, and SDL_AudioStream::src_rate.
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().
|
static |
Definition at line 485 of file SDL_audiocvt.c.
References i, j, RESAMPLER_FILTER_SIZE, RESAMPLER_SAMPLES_PER_ZERO_CROSSING, ResamplerFilter, ResamplerFilterDifference, ResamplerPadding(), and SDL_min.
Referenced by SDL_ResampleAudioStream(), and SDL_ResampleCVT().
|
static |
Definition at line 1220 of file SDL_audiocvt.c.
References retval, SDL_assert, SDL_memcpy, SDL_min, and SDL_ResampleAudio().
Referenced by SDL_NewAudioStream().
|
static |
Definition at line 707 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, SDL_AudioCVT::len, SDL_AudioCVT::len_cvt, SDL_AudioCVT::len_mult, ResamplerPadding(), SDL_assert, SDL_AUDIOCVT_MAX_FILTERS, SDL_calloc, SDL_free, SDL_memmove, SDL_OutOfMemory, and SDL_ResampleAudio().
|
static |
Definition at line 1245 of file SDL_audiocvt.c.
References SDL_memset.
Referenced by SDL_NewAudioStream().
|
static |
Definition at line 825 of file SDL_audiocvt.c.
References AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S8, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, SDL_FALSE, and SDL_TRUE.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 848 of file SDL_audiocvt.c.
References SDL_FALSE, and SDL_TRUE.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 430 of file SDL_audiocvt.c.
Referenced by SDL_PrepareResampleFilter().
|
static |
Definition at line 431 of file SDL_audiocvt.c.
Referenced by SDL_FreeResampleFilter(), SDL_PrepareResampleFilter(), and SDL_ResampleAudio().
|
static |
Definition at line 432 of file SDL_audiocvt.c.
Referenced by SDL_FreeResampleFilter(), SDL_PrepareResampleFilter(), and SDL_ResampleAudio().