|
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_dataqueue.h"#include "SDL_cpuinfo.h"
Include dependency graph for SDL_audiocvt.c: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 | ) |
| #define DEBUG_AUDIOSTREAM 0 |
Definition at line 36 of file SDL_audiocvt.c.
| #define RESAMPLER_BITS_PER_SAMPLE 16 |
Definition at line 380 of file SDL_audiocvt.c.
| #define RESAMPLER_FILTER_SIZE ((RESAMPLER_SAMPLES_PER_ZERO_CROSSING * RESAMPLER_ZERO_CROSSINGS) + 1) |
Definition at line 382 of file SDL_audiocvt.c.
| #define RESAMPLER_FUNCS | ( | chans | ) |
Definition at line 753 of file SDL_audiocvt.c.
| #define RESAMPLER_SAMPLES_PER_ZERO_CROSSING (1 << ((RESAMPLER_BITS_PER_SAMPLE / 2) + 1)) |
Definition at line 381 of file SDL_audiocvt.c.
| #define RESAMPLER_ZERO_CROSSINGS 5 |
Definition at line 379 of file SDL_audiocvt.c.
Definition at line 1090 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 1088 of file SDL_audiocvt.c.
Definition at line 1089 of file SDL_audiocvt.c.
|
static |
Definition at line 386 of file SDL_audiocvt.c.
References i, SDL_pow, and SDL_TRUE.
Referenced by kaiser_and_sinc().
|
static |
Definition at line 766 of file SDL_audiocvt.c.
References NULL.
Referenced by SDL_BuildAudioResampleCVT().
Definition at line 1123 of file SDL_audiocvt.c.
References NULL, ptr, SDL_OutOfMemory, and SDL_realloc.
Referenced by SDL_AudioStreamPutInternal().
|
static |
Definition at line 408 of file SDL_audiocvt.c.
References bessel(), i, RESAMPLER_SAMPLES_PER_ZERO_CROSSING, SDL_pow, SDL_sinf, and SDL_sqrt.
Referenced by SDL_PrepareResampleFilter().
Definition at line 472 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 600 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 1645 of file SDL_audiocvt.c.
References int(), and SDL_CountDataQueue().
| void SDL_AudioStreamClear | ( | SDL_AudioStream * | stream | ) |
Clear any pending data in the stream without converting it
Definition at line 1651 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 1570 of file SDL_audiocvt.c.
References DEBUG_AUDIOSTREAM, int(), SDL_assert, SDL_AudioStreamPutInternal(), SDL_ceil, SDL_InvalidParamError, SDL_memset, and SDL_TRUE.
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 1624 of file SDL_audiocvt.c.
References SDL_InvalidParamError, SDL_ReadFromDataQueue(), and SDL_SetError.
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 1506 of file SDL_audiocvt.c.
References NULL, SDL_assert, SDL_AudioStreamPutInternal(), SDL_InvalidParamError, SDL_memcpy, SDL_SetError, and SDL_WriteToDataQueue().
|
static |
Definition at line 1377 of file SDL_audiocvt.c.
References EnsureStreamBufferSize(), frames, int(), 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 877 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, RESAMPLER_SAMPLES_PER_ZERO_CROSSING, 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_MAX_SINT32, SDL_SetError, SDL_SupportedAudioFormat(), SDL_SupportedChannelCount(), SDL_zeroa, SDL_zerop, and SDL_AudioCVT::src_format.
Referenced by SDL_NewAudioStream().
|
static |
Definition at line 781 of file SDL_audiocvt.c.
References ChooseCVTResampler(), SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, int(), 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 661 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 614 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 1262 of file SDL_audiocvt.c.
References SDL_free.
Referenced by SDL_NewAudioStream().
|
static |
Definition at line 334 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 180 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 102 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 150 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 562 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 539 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, and SDL_AudioCVT::src_format.
Referenced by SDL_AudioStreamPutInternal().
|
static |
Definition at line 209 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 267 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 127 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 233 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 80 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 304 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().
| void SDL_FreeAudioStream | ( | SDL_AudioStream * | stream | ) |
Free an audio stream
Definition at line 1667 of file SDL_audiocvt.c.
References SDL_free, and SDL_FreeDataQueue().
Referenced by SDL_NewAudioStream().
Definition at line 463 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 1268 of file SDL_audiocvt.c.
References AUDIO_F32SYS, NULL, 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(), and SDL_TRUE.
Definition at line 434 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 484 of file SDL_audiocvt.c.
References i, int(), 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 1229 of file SDL_audiocvt.c.
References int(), retval, SDL_assert, SDL_memcpy, SDL_min, and SDL_ResampleAudio().
Referenced by SDL_NewAudioStream().
|
static |
Definition at line 706 of file SDL_audiocvt.c.
References AUDIO_F32SYS, SDL_AudioCVT::buf, SDL_AudioCVT::filter_index, SDL_AudioCVT::filters, int(), SDL_AudioCVT::len, SDL_AudioCVT::len_cvt, SDL_AudioCVT::len_mult, ResamplerPadding(), SDL_assert, SDL_AUDIOCVT_MAX_FILTERS, SDL_calloc, SDL_free, SDL_MAX_SINT32, SDL_memmove, SDL_OutOfMemory, and SDL_ResampleAudio().
|
static |
Definition at line 1254 of file SDL_audiocvt.c.
References SDL_memset.
Referenced by SDL_NewAudioStream().
|
static |
Definition at line 830 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().
Definition at line 853 of file SDL_audiocvt.c.
References SDL_FALSE, and SDL_TRUE.
Referenced by SDL_BuildAudioCVT().
|
static |
Definition at line 429 of file SDL_audiocvt.c.
Referenced by SDL_PrepareResampleFilter().
|
static |
Definition at line 430 of file SDL_audiocvt.c.
Referenced by SDL_FreeResampleFilter(), SDL_PrepareResampleFilter(), and SDL_ResampleAudio().
|
static |
Definition at line 431 of file SDL_audiocvt.c.
Referenced by SDL_FreeResampleFilter(), SDL_PrepareResampleFilter(), and SDL_ResampleAudio().