SDL
2.0
|
#include "../SDL_internal.h"
#include "SDL_log.h"
#include "SDL_hints.h"
#include "SDL_audio.h"
#include "SDL_wave.h"
Go to the source code of this file.
Data Structures | |
struct | ADPCM_DecoderState |
struct | MS_ADPCM_CoeffData |
struct | MS_ADPCM_ChannelState |
struct | WaveExtensibleGUID |
Macros | |
#define | SIZE_MAX ((size_t)-1) |
#define | INT_MAX (SDL_MAX_SINT32) |
#define | WAVE_FORMATTAG_GUID(tag) {(tag) & 0xff, (tag) >> 8, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113} |
Variables | |
static WaveExtensibleGUID | extensible_guids [] |
#define INT_MAX (SDL_MAX_SINT32) |
Definition at line 31 of file SDL_wave.c.
Referenced by sdltest_randomBoundaryNumberSint32(), sdltest_randomIntegerInRange(), SDLTest_RandomSint32BoundaryValue(), and WaveCheckFormat().
#define SIZE_MAX ((size_t)-1) |
Definition at line 27 of file SDL_wave.c.
Referenced by IMA_ADPCM_Decode(), LAW_Decode(), MS_ADPCM_Decode(), MultiplySize(), PCM_ConvertSint24ToSint32(), and PCM_Decode().
#define WAVE_FORMATTAG_GUID | ( | tag | ) | {(tag) & 0xff, (tag) >> 8, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113} |
Definition at line 1578 of file SDL_wave.c.
Definition at line 735 of file SDL_wave.c.
References WaveFormat::blockalign, ADPCM_DecoderState::blockheadersize, WaveFormat::channels, WaveFile::format, WaveFile::sampleframes, WaveFormat::samplesperblock, SDL_SetError, TruncDropFrame, WaveFile::trunchint, TruncStrict, TruncVeryStrict, and WaveAdjustToFactValue().
Referenced by IMA_ADPCM_Decode(), and IMA_ADPCM_Init().
Definition at line 1031 of file SDL_wave.c.
References ADPCM_DecoderState::block, WaveFormat::blockalign, ADPCM_DecoderState::blockheadersize, ADPCM_DecoderState::blocksize, WaveFormat::channels, ADPCM_DecoderState::channels, WaveFile::chunk, ADPCM_DecoderState::cstate, ADPCM_DecoderState::data, WaveChunk::data, WaveFile::format, ADPCM_DecoderState::framesize, ADPCM_DecoderState::framesleft, ADPCM_DecoderState::framestotal, IMA_ADPCM_CalculateSampleFrames(), IMA_ADPCM_DecodeBlockData(), IMA_ADPCM_DecodeBlockHeader(), ADPCM_DecoderState::input, WaveChunk::length, MultiplySize(), NULL, ADPCM_DecoderState::output, ADPCM_DecoderState::pos, WaveFile::sampleframes, ADPCM_DecoderState::samplesperblock, WaveFormat::samplesperblock, SDL_calloc, SDL_free, SDL_malloc, SDL_MAX_UINT32, SDL_OutOfMemory, SDL_SetError, ADPCM_DecoderState::size, WaveChunk::size, SIZE_MAX, state, TruncDropFrame, WaveFile::trunchint, and TruncVeryStrict.
Referenced by WaveLoad().
|
static |
Definition at line 961 of file SDL_wave.c.
References ADPCM_DecoderState::block, ADPCM_DecoderState::blocksize, ADPCM_DecoderState::channels, ADPCM_DecoderState::cstate, ADPCM_DecoderState::data, ADPCM_DecoderState::framesleft, i, IMA_ADPCM_ProcessNibble(), ADPCM_DecoderState::output, ADPCM_DecoderState::pos, retval, ADPCM_DecoderState::samplesperblock, and ADPCM_DecoderState::size.
Referenced by IMA_ADPCM_Decode().
|
static |
Definition at line 921 of file SDL_wave.c.
References ADPCM_DecoderState::block, ADPCM_DecoderState::blockheadersize, ADPCM_DecoderState::channels, ADPCM_DecoderState::cstate, ADPCM_DecoderState::data, ADPCM_DecoderState::framesleft, ADPCM_DecoderState::output, and ADPCM_DecoderState::pos.
Referenced by IMA_ADPCM_Decode().
Definition at line 789 of file SDL_wave.c.
References WaveFormat::bitspersample, WaveFormat::blockalign, ADPCM_DecoderState::blockheadersize, WaveFormat::channels, WaveFile::chunk, WaveChunk::data, EXTENSIBLE_CODE, WaveFormat::extsize, WaveFile::format, WaveFormat::formattag, IMA_ADPCM_CalculateSampleFrames(), ADPCM_DecoderState::samplesperblock, WaveFormat::samplesperblock, SDL_SetError, and WaveChunk::size.
Referenced by WaveCheckFormat().
Definition at line 1161 of file SDL_wave.c.
References ALAW_CODE, WaveFormat::blockalign, WaveFormat::channels, WaveFile::chunk, WaveChunk::data, WaveFormat::encoding, WaveFile::format, i, WaveChunk::length, MULAW_CODE, MultiplySize(), nibble(), NULL, WaveFile::sampleframes, SDL_free, SDL_MAX_UINT32, SDL_OutOfMemory, SDL_realloc, SDL_SetError, WaveChunk::size, SIZE_MAX, and WaveAdjustToFactValue().
Referenced by WaveLoad().
Definition at line 1132 of file SDL_wave.c.
References WaveFormat::bitspersample, WaveFormat::blockalign, WaveFormat::channels, WaveFile::format, WaveFile::sampleframes, SDL_SetError, WaveFile::trunchint, TruncStrict, TruncVeryStrict, and WaveAdjustToFactValue().
Referenced by WaveCheckFormat().
Definition at line 333 of file SDL_wave.c.
References WaveFormat::bitspersample, WaveFormat::blockalign, ADPCM_DecoderState::blockheadersize, WaveFormat::channels, WaveFile::format, WaveFile::sampleframes, WaveFormat::samplesperblock, SDL_SetError, TruncDropFrame, WaveFile::trunchint, TruncStrict, TruncVeryStrict, and WaveAdjustToFactValue().
Referenced by MS_ADPCM_Decode(), and MS_ADPCM_Init().
Definition at line 638 of file SDL_wave.c.
References ADPCM_DecoderState::block, WaveFormat::blockalign, ADPCM_DecoderState::blockheadersize, ADPCM_DecoderState::blocksize, WaveFormat::channels, ADPCM_DecoderState::channels, WaveFile::chunk, ADPCM_DecoderState::cstate, ADPCM_DecoderState::data, WaveChunk::data, ADPCM_DecoderState::ddata, WaveFile::decoderdata, WaveFile::format, ADPCM_DecoderState::framesize, ADPCM_DecoderState::framesleft, ADPCM_DecoderState::framestotal, ADPCM_DecoderState::input, WaveChunk::length, MS_ADPCM_CalculateSampleFrames(), MS_ADPCM_DecodeBlockData(), MS_ADPCM_DecodeBlockHeader(), MultiplySize(), NULL, ADPCM_DecoderState::output, ADPCM_DecoderState::pos, WaveFile::sampleframes, ADPCM_DecoderState::samplesperblock, WaveFormat::samplesperblock, SDL_free, SDL_malloc, SDL_MAX_UINT32, SDL_OutOfMemory, SDL_SetError, ADPCM_DecoderState::size, WaveChunk::size, SIZE_MAX, state, TruncDropFrame, WaveFile::trunchint, and TruncVeryStrict.
Referenced by WaveLoad().
|
static |
Definition at line 590 of file SDL_wave.c.
References ADPCM_DecoderState::block, ADPCM_DecoderState::blocksize, ADPCM_DecoderState::channels, ADPCM_DecoderState::cstate, ADPCM_DecoderState::data, ADPCM_DecoderState::framesleft, MS_ADPCM_ProcessNibble(), ADPCM_DecoderState::output, ADPCM_DecoderState::pos, ADPCM_DecoderState::samplesperblock, and ADPCM_DecoderState::size.
Referenced by MS_ADPCM_Decode().
|
static |
Definition at line 529 of file SDL_wave.c.
References ADPCM_DecoderState::block, ADPCM_DecoderState::blockheadersize, ADPCM_DecoderState::channels, MS_ADPCM_ChannelState::coeff1, MS_ADPCM_ChannelState::coeff2, ADPCM_DecoderState::cstate, ADPCM_DecoderState::data, ADPCM_DecoderState::ddata, MS_ADPCM_ChannelState::delta, ADPCM_DecoderState::framesleft, ADPCM_DecoderState::output, ADPCM_DecoderState::pos, and SDL_SetError.
Referenced by MS_ADPCM_Decode().
Definition at line 373 of file SDL_wave.c.
References MS_ADPCM_CoeffData::aligndummy, WaveFormat::bitspersample, WaveFormat::blockalign, ADPCM_DecoderState::blockheadersize, WaveFormat::channels, WaveFile::chunk, MS_ADPCM_CoeffData::coeff, MS_ADPCM_CoeffData::coeffcount, WaveChunk::data, WaveFile::decoderdata, EXTENSIBLE_CODE, WaveFormat::extsize, WaveFile::format, WaveFormat::formattag, i, MS_ADPCM_CalculateSampleFrames(), NULL, ADPCM_DecoderState::samplesperblock, WaveFormat::samplesperblock, SDL_malloc, SDL_OutOfMemory, SDL_SetError, and WaveChunk::size.
Referenced by WaveCheckFormat().
|
static |
Definition at line 492 of file SDL_wave.c.
References MS_ADPCM_ChannelState::coeff1, MS_ADPCM_ChannelState::coeff2, and MS_ADPCM_ChannelState::delta.
Referenced by MS_ADPCM_DecodeBlockData().
Definition at line 47 of file SDL_wave.c.
References SDL_FALSE, SDL_TRUE, and SIZE_MAX.
Referenced by IMA_ADPCM_Decode(), LAW_Decode(), MS_ADPCM_Decode(), PCM_ConvertSint24ToSint32(), and PCM_Decode().
|
static |
Definition at line 1346 of file SDL_wave.c.
References WaveFormat::channels, WaveFile::chunk, WaveChunk::data, WaveFile::format, i, MultiplySize(), NULL, WaveFile::sampleframes, SDL_MAX_UINT32, SDL_OutOfMemory, SDL_realloc, SDL_SetError, WaveChunk::size, and SIZE_MAX.
Referenced by PCM_Decode().
Definition at line 1397 of file SDL_wave.c.
References WaveFormat::bitspersample, WaveFormat::blockalign, WaveFile::chunk, WaveChunk::data, WaveFormat::encoding, WaveFile::format, WaveChunk::length, MultiplySize(), NULL, PCM_CODE, PCM_ConvertSint24ToSint32(), WaveFile::sampleframes, SDL_MAX_UINT32, SDL_OutOfMemory, SDL_SetError, WaveChunk::size, SIZE_MAX, and WaveAdjustToFactValue().
Referenced by WaveLoad().
Definition at line 1303 of file SDL_wave.c.
References WaveFormat::bitspersample, WaveFormat::blockalign, WaveFormat::channels, WaveFormat::encoding, WaveFile::format, IEEE_FLOAT_CODE, PCM_CODE, WaveFile::sampleframes, SDL_SetError, WaveFile::trunchint, TruncStrict, TruncVeryStrict, and WaveAdjustToFactValue().
Referenced by WaveCheckFormat().
This function frees data previously allocated with SDL_LoadWAV_RW()
Definition at line 2126 of file SDL_wave.c.
References SDL_free.
SDL_AudioSpec* SDL_LoadWAV_RW | ( | SDL_RWops * | src, |
int | freesrc, | ||
SDL_AudioSpec * | spec, | ||
Uint8 ** | audio_buf, | ||
Uint32 * | audio_len | ||
) |
Load the audio data of a WAVE file into memory.
Loading a WAVE file requires src
, spec
, audio_buf
and audio_len
to be valid pointers. The entire data portion of the file is then loaded into memory and decoded if necessary.
If freesrc
is non-zero, the data source gets automatically closed and freed before the function returns.
Supported are RIFF WAVE files with the formats PCM (8, 16, 24, and 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and A-law and µ-law (8 bits). Other formats are currently unsupported and cause an error.
If this function succeeds, the pointer returned by it is equal to spec
and the pointer to the audio data allocated by the function is written to audio_buf
and its length in bytes to audio_len
. The SDL_AudioSpec members freq
, channels
, and format
are set to the values of the audio data in the buffer. The samples
member is set to a sane default and all others are set to zero.
It's necessary to use SDL_FreeWAV() to free the audio data returned in audio_buf
when it is no longer used.
Because of the underspecification of the Waveform format, there are many problematic files in the wild that cause issues with strict decoders. To provide compatibility with these files, this decoder is lenient in regards to the truncation of the file, the fact chunk, and the size of the RIFF chunk. The hints SDL_HINT_WAVE_RIFF_CHUNK_SIZE, SDL_HINT_WAVE_TRUNCATION, and SDL_HINT_WAVE_FACT_CHUNK can be used to tune the behavior of the loading process.
Any file that is invalid (due to truncation, corruption, or wrong values in the headers), too big, or unsupported causes an error. Additionally, any critical I/O error from the data source will terminate the loading process with an error. The function returns NULL on error and in all cases (with the exception of src
being NULL), an appropriate error message will be set.
It is required that the data source supports seeking.
Example:
src | The data source with the WAVE data |
freesrc | A integer value that makes the function close the data source if non-zero |
spec | A pointer filled with the audio format of the audio data |
audio_buf | A pointer filled with the audio data allocated by the function |
audio_len | A pointer filled with the length of the audio data buffer in bytes |
Definition at line 2075 of file SDL_wave.c.
References WaveFile::chunk, WaveFile::decoderdata, WaveFile::facthint, NULL, WaveChunk::position, WaveFile::riffhint, RW_SEEK_SET, SDL_free, SDL_InvalidParamError, SDL_RWclose, SDL_RWseek, spec, WaveFile::trunchint, WaveFreeChunkData(), WaveGetFactChunkHint(), WaveGetRiffSizeHint(), WaveGetTruncationHint(), and WaveLoad().
Definition at line 319 of file SDL_wave.c.
References WaveFile::fact, WaveFile::facthint, FactStrict, WaveFact::samplelength, SDL_SetError, and WaveFact::status.
Referenced by IMA_ADPCM_CalculateSampleFrames(), LAW_Decode(), LAW_Init(), MS_ADPCM_CalculateSampleFrames(), PCM_Decode(), and PCM_Init().
Definition at line 1663 of file SDL_wave.c.
References ALAW_CODE, WaveFormat::bitspersample, WaveFormat::blockalign, WaveFormat::channels, WaveFile::chunk, WaveFormat::encoding, EXTENSIBLE_CODE, WaveFile::fact, WaveFile::facthint, FactIgnoreZero, FactStrict, FactTruncate, WaveFile::format, WaveFormat::formattag, WaveFormat::frequency, IEEE_FLOAT_CODE, IMA_ADPCM_CODE, IMA_ADPCM_Init(), INT_MAX, LAW_Init(), MPEG_CODE, MPEGLAYER3_CODE, MS_ADPCM_CODE, MS_ADPCM_Init(), MULAW_CODE, PCM_CODE, PCM_Init(), WaveFact::samplelength, SDL_SetError, WaveChunk::size, WaveFact::status, and WaveFormat::subformat.
Referenced by WaveLoad().
Definition at line 1500 of file SDL_wave.c.
References WaveChunk::data, NULL, SDL_free, and WaveChunk::size.
Referenced by SDL_LoadWAV_RW(), WaveLoad(), WaveNextChunk(), and WaveReadPartialChunkData().
|
static |
Definition at line 1480 of file SDL_wave.c.
References FactIgnore, FactIgnoreZero, FactNoHint, FactStrict, FactTruncate, NULL, SDL_GetHint, SDL_HINT_WAVE_FACT_CHUNK, and SDL_strcmp.
Referenced by SDL_LoadWAV_RW().
|
static |
Definition at line 1589 of file SDL_wave.c.
References WaveExtensibleGUID::encoding, WaveExtensibleGUID::guid, i, SDL_arraysize, SDL_memcmp, WaveFormat::subformat, and UNKNOWN_CODE.
Referenced by WaveReadFormat().
|
static |
Definition at line 1440 of file SDL_wave.c.
References NULL, RiffSizeChunkSearch, RiffSizeIgnore, RiffSizeIgnoreZero, RiffSizeMaximum, RiffSizeNoHint, SDL_GetHint, SDL_HINT_WAVE_RIFF_CHUNK_SIZE, and SDL_strcmp.
Referenced by SDL_LoadWAV_RW().
|
static |
Definition at line 1460 of file SDL_wave.c.
References NULL, SDL_GetHint, SDL_HINT_WAVE_TRUNCATION, SDL_strcmp, TruncDropBlock, TruncDropFrame, TruncNoHint, TruncStrict, and TruncVeryStrict.
Referenced by SDL_LoadWAV_RW().
|
static |
Definition at line 1771 of file SDL_wave.c.
References ALAW_CODE, AUDIO_F32LSB, AUDIO_S16LSB, AUDIO_S16SYS, AUDIO_S32LSB, AUDIO_U8, WaveFormat::bitspersample, WaveFormat::channels, SDL_AudioSpec::channels, WaveFile::chunk, DATA, WaveFormat::encoding, FACT, WaveFile::fact, WaveFile::facthint, FactIgnore, FactNoHint, FMT, WaveFile::format, SDL_AudioSpec::format, WaveChunk::fourcc, SDL_AudioSpec::freq, WaveFormat::frequency, IEEE_FLOAT_CODE, IMA_ADPCM_CODE, IMA_ADPCM_Decode(), LAW_Decode(), WaveChunk::length, MS_ADPCM_CODE, MS_ADPCM_Decode(), MULAW_CODE, NULL, PCM_CODE, PCM_Decode(), WaveChunk::position, RIFF, WaveFile::riffhint, RiffSizeChunkSearch, RiffSizeIgnore, RiffSizeIgnoreZero, RiffSizeMaximum, RW_SEEK_SET, WaveFact::samplelength, SDL_AudioSpec::samples, SDL_FALSE, SDL_getenv, SDL_MAX_SINT64, SDL_MAX_UINT32, SDL_RWread, SDL_RWseek, SDL_RWtell, SDL_SetError, SDL_sscanf, SDL_SwapLE32, SDL_TRUE, SDL_zerop, WaveChunk::size, WaveFact::status, WaveFile::trunchint, TruncStrict, TruncVeryStrict, WAVE, WaveCheckFormat(), WaveFreeChunkData(), WaveNextChunk(), WaveReadChunkData(), WaveReadFormat(), and WaveReadPartialChunkData().
Referenced by SDL_LoadWAV_RW().
Definition at line 1510 of file SDL_wave.c.
References WaveChunk::fourcc, WaveChunk::length, WaveChunk::position, RW_SEEK_SET, SDL_RWread, SDL_RWseek, SDL_SwapLE32, and WaveFreeChunkData().
Referenced by WaveLoad().
Definition at line 1567 of file SDL_wave.c.
References WaveChunk::length, and WaveReadPartialChunkData().
Referenced by WaveLoad().
|
static |
Definition at line 1601 of file SDL_wave.c.
References WaveFormat::bitspersample, WaveFormat::blockalign, WaveFormat::byterate, WaveFormat::channelmask, WaveFormat::channels, WaveFile::chunk, WaveChunk::data, WaveFormat::encoding, EXTENSIBLE_CODE, WaveFormat::extsize, WaveFile::format, WaveFormat::formattag, WaveFormat::frequency, NULL, PCM_CODE, WaveFormat::samplesperblock, SDL_MAX_SINT32, SDL_OutOfMemory, SDL_ReadLE16, SDL_ReadLE32, SDL_RWclose, SDL_RWFromConstMem, SDL_RWread, SDL_SetError, WaveChunk::size, WaveFormat::subformat, WaveFormat::validsamplebits, and WaveGetFormatGUIDEncoding().
Referenced by WaveLoad().
Definition at line 1538 of file SDL_wave.c.
References WaveChunk::data, WaveChunk::length, NULL, WaveChunk::position, RW_SEEK_SET, SDL_malloc, SDL_OutOfMemory, SDL_RWread, SDL_RWseek, WaveChunk::size, and WaveFreeChunkData().
Referenced by WaveLoad(), and WaveReadChunkData().
|
static |
Definition at line 1579 of file SDL_wave.c.