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.
#define SIZE_MAX ((size_t)-1) |
Definition at line 27 of file SDL_wave.c.
#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 1594 of file SDL_wave.c.
Definition at line 741 of file SDL_wave.c.
References WaveFormat::channels, WaveFile::format, WaveFile::sampleframes, SDL_SetError, TruncDropFrame, WaveFile::trunchint, TruncStrict, TruncVeryStrict, and WaveAdjustToFactValue().
Referenced by IMA_ADPCM_Decode(), and IMA_ADPCM_Init().
Definition at line 1037 of file SDL_wave.c.
References WaveFormat::blockalign, WaveFormat::channels, WaveFile::chunk, WaveChunk::data, WaveFile::format, IMA_ADPCM_CalculateSampleFrames(), IMA_ADPCM_DecodeBlockData(), IMA_ADPCM_DecodeBlockHeader(), WaveChunk::length, NULL, SafeMult(), WaveFile::sampleframes, WaveFormat::samplesperblock, SDL_calloc, SDL_free, SDL_malloc, SDL_MAX_UINT32, SDL_OutOfMemory, SDL_SetError, SDL_zero, WaveChunk::size, SIZE_MAX, state, TruncDropFrame, WaveFile::trunchint, and TruncVeryStrict.
Referenced by WaveLoad().
|
static |
Definition at line 967 of file SDL_wave.c.
References i, IMA_ADPCM_ProcessNibble(), retval, and state.
Referenced by IMA_ADPCM_Decode().
|
static |
Definition at line 795 of file SDL_wave.c.
References WaveFile::chunk, WaveChunk::data, EXTENSIBLE_CODE, WaveFile::format, IMA_ADPCM_CalculateSampleFrames(), SDL_SetError, and WaveChunk::size.
Referenced by WaveCheckFormat().
Definition at line 1170 of file SDL_wave.c.
References ALAW_CODE, WaveFile::chunk, WaveChunk::data, WaveFormat::encoding, WaveFile::format, i, WaveChunk::length, MULAW_CODE, nibble(), NULL, SafeMult(), 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 1141 of file SDL_wave.c.
References WaveFile::format, WaveFile::sampleframes, SDL_SetError, WaveFile::trunchint, TruncStrict, TruncVeryStrict, and WaveAdjustToFactValue().
Referenced by WaveCheckFormat().
Definition at line 336 of file SDL_wave.c.
References WaveFormat::bitspersample, WaveFormat::blockalign, WaveFormat::channels, WaveFile::format, WaveFile::sampleframes, SDL_SetError, TruncDropFrame, WaveFile::trunchint, TruncStrict, TruncVeryStrict, and WaveAdjustToFactValue().
Referenced by MS_ADPCM_Decode(), and MS_ADPCM_Init().
Definition at line 641 of file SDL_wave.c.
References WaveFormat::blockalign, WaveFormat::channels, WaveFile::chunk, WaveChunk::data, WaveFile::decoderdata, WaveFile::format, WaveChunk::length, MS_ADPCM_CalculateSampleFrames(), MS_ADPCM_DecodeBlockData(), MS_ADPCM_DecodeBlockHeader(), NULL, SafeMult(), WaveFile::sampleframes, WaveFormat::samplesperblock, SDL_free, SDL_malloc, SDL_MAX_UINT32, SDL_OutOfMemory, SDL_SetError, SDL_zero, WaveChunk::size, SIZE_MAX, state, TruncDropFrame, WaveFile::trunchint, and TruncVeryStrict.
Referenced by WaveLoad().
|
static |
Definition at line 593 of file SDL_wave.c.
References MS_ADPCM_ProcessNibble(), and state.
Referenced by MS_ADPCM_Decode().
|
static |
Definition at line 532 of file SDL_wave.c.
References MS_ADPCM_ChannelState::coeff1, MS_ADPCM_ChannelState::coeff2, MS_ADPCM_ChannelState::delta, SDL_SetError, and state.
Referenced by MS_ADPCM_Decode().
Definition at line 376 of file SDL_wave.c.
References MS_ADPCM_CoeffData::aligndummy, WaveFile::chunk, MS_ADPCM_CoeffData::coeff, MS_ADPCM_CoeffData::coeffcount, WaveChunk::data, WaveFile::decoderdata, EXTENSIBLE_CODE, WaveFile::format, i, MS_ADPCM_CalculateSampleFrames(), NULL, SDL_malloc, SDL_OutOfMemory, SDL_SetError, and WaveChunk::size.
Referenced by WaveCheckFormat().
|
static |
Definition at line 495 of file SDL_wave.c.
References MS_ADPCM_ChannelState::coeff1, MS_ADPCM_ChannelState::coeff2, and MS_ADPCM_ChannelState::delta.
Referenced by MS_ADPCM_DecodeBlockData().
|
static |
Definition at line 1356 of file SDL_wave.c.
References WaveFile::chunk, WaveChunk::data, WaveFile::format, i, NULL, SafeMult(), WaveFile::sampleframes, SDL_MAX_UINT32, SDL_OutOfMemory, SDL_realloc, SDL_SetError, WaveChunk::size, and SIZE_MAX.
Referenced by PCM_Decode().
Definition at line 1408 of file SDL_wave.c.
References WaveFile::chunk, WaveChunk::data, WaveFile::format, WaveChunk::length, NULL, PCM_CODE, PCM_ConvertSint24ToSint32(), SafeMult(), WaveFile::sampleframes, SDL_MAX_UINT32, SDL_OutOfMemory, SDL_SetError, WaveChunk::size, SIZE_MAX, and WaveAdjustToFactValue().
Referenced by WaveLoad().
Definition at line 1313 of file SDL_wave.c.
References WaveFile::format, IEEE_FLOAT_CODE, PCM_CODE, WaveFile::sampleframes, SDL_SetError, WaveFile::trunchint, TruncStrict, TruncVeryStrict, and WaveAdjustToFactValue().
Referenced by WaveCheckFormat().
Definition at line 48 of file SDL_wave.c.
References SIZE_MAX.
Referenced by IMA_ADPCM_Decode(), LAW_Decode(), MS_ADPCM_Decode(), PCM_ConvertSint24ToSint32(), and PCM_Decode().
This function frees data previously allocated with SDL_LoadWAV_RW()
Definition at line 2148 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 2095 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, SDL_zero, spec, WaveFile::trunchint, WaveFreeChunkData(), WaveGetFactChunkHint(), WaveGetRiffSizeHint(), WaveGetTruncationHint(), and WaveLoad().
Definition at line 322 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 1679 of file SDL_wave.c.
References ALAW_CODE, WaveFile::chunk, EXTENSIBLE_CODE, WaveFile::fact, WaveFile::facthint, FactIgnoreZero, FactStrict, FactTruncate, WaveFile::format, 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, and WaveFact::status.
Referenced by WaveLoad().
Definition at line 1511 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 1491 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 1605 of file SDL_wave.c.
References WaveExtensibleGUID::encoding, extensible_guids, WaveExtensibleGUID::guid, i, SDL_arraysize, SDL_memcmp, and UNKNOWN_CODE.
Referenced by WaveReadFormat().
|
static |
Definition at line 1451 of file SDL_wave.c.
References NULL, RiffSizeForce, RiffSizeIgnore, RiffSizeIgnoreZero, RiffSizeMaximum, RiffSizeNoHint, SDL_GetHint, SDL_HINT_WAVE_RIFF_CHUNK_SIZE, and SDL_strcmp.
Referenced by SDL_LoadWAV_RW().
|
static |
Definition at line 1471 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 1787 of file SDL_wave.c.
References ALAW_CODE, AUDIO_F32LSB, AUDIO_S16LSB, AUDIO_S16SYS, AUDIO_S32LSB, AUDIO_U8, SDL_AudioSpec::channels, WaveFile::chunk, DATA, FACT, WaveFile::fact, WaveFile::facthint, FactIgnore, FactNoHint, FMT, WaveFile::format, SDL_AudioSpec::format, WaveChunk::fourcc, SDL_AudioSpec::freq, 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, RiffSizeForce, 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_zero, SDL_zerop, WaveChunk::size, spec, WaveFact::status, WaveFile::trunchint, TruncStrict, TruncVeryStrict, WAVE, WaveCheckFormat(), WaveFreeChunkData(), WaveNextChunk(), WaveReadChunkData(), WaveReadFormat(), and WaveReadPartialChunkData().
Referenced by SDL_LoadWAV_RW().
Definition at line 1521 of file SDL_wave.c.
References WaveChunk::fourcc, WaveChunk::length, WaveChunk::position, RW_SEEK_SET, SDL_MAX_SINT64, SDL_RWread, SDL_RWseek, SDL_SwapLE32, and WaveFreeChunkData().
Referenced by WaveLoad().
Definition at line 1583 of file SDL_wave.c.
References WaveChunk::length, and WaveReadPartialChunkData().
Referenced by WaveLoad().
|
static |
Definition at line 1617 of file SDL_wave.c.
References WaveFile::chunk, WaveChunk::data, EXTENSIBLE_CODE, WaveFile::format, NULL, PCM_CODE, SDL_MAX_SINT32, SDL_OutOfMemory, SDL_ReadLE16, SDL_ReadLE32, SDL_RWclose, SDL_RWFromConstMem, SDL_RWread, SDL_SetError, WaveChunk::size, and WaveGetFormatGUIDEncoding().
Referenced by WaveLoad().
Definition at line 1554 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 1595 of file SDL_wave.c.
Referenced by WaveGetFormatGUIDEncoding().