SDL_wave.h
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
/* RIFF WAVE files are little-endian */
/*******************************************/
/* Define values for Microsoft WAVE format */
/*******************************************/
/* FOURCC */
#define RIFF 0x46464952 /* "RIFF" */
#define WAVE 0x45564157 /* "WAVE" */
#define FACT 0x74636166 /* "fact" */
#define LIST 0x5453494c /* "LIST" */
#define BEXT 0x74786562 /* "bext" */
#define JUNK 0x4B4E554A /* "JUNK" */
#define FMT 0x20746D66 /* "fmt " */
#define DATA 0x61746164 /* "data" */
/* Format tags */
#define UNKNOWN_CODE 0x0000
#define PCM_CODE 0x0001
#define MS_ADPCM_CODE 0x0002
#define IEEE_FLOAT_CODE 0x0003
#define ALAW_CODE 0x0006
#define MULAW_CODE 0x0007
#define IMA_ADPCM_CODE 0x0011
#define MPEG_CODE 0x0050
#define MPEGLAYER3_CODE 0x0055
#define EXTENSIBLE_CODE 0xFFFE
/* Stores the WAVE format information. */
typedef struct WaveFormat
{
Uint16 formattag; /* Raw value of the first field in the fmt chunk data. */
Uint16 encoding; /* Actual encoding, possibly from the extensible header. */
Uint16 channels; /* Number of channels. */
Uint32 frequency; /* Sampling rate in Hz. */
Uint32 byterate; /* Average bytes per second. */
Uint16 blockalign; /* Bytes per block. */
Uint16 bitspersample; /* Currently supported are 8, 16, 24, 32, and 4 for ADPCM. */
/* Extra information size. Number of extra bytes starting at byte 18 in the
* fmt chunk data. This is at least 22 for the extensible header.
*/
Uint16 extsize;
/* Extensible WAVE header fields */
Uint16 validsamplebits;
Uint32 samplesperblock; /* For compressed formats. Can be zero. Actually 16 bits in the header. */
Uint32 channelmask;
Uint8 subformat[16]; /* A format GUID. */
} WaveFormat;
/* Stores information on the fact chunk. */
typedef struct WaveFact {
/* Represents the state of the fact chunk in the WAVE file.
* Set to -1 if the fact chunk is invalid.
* Set to 0 if the fact chunk is not present
* Set to 1 if the fact chunk is present and valid.
* Set to 2 if samplelength is going to be used as the number of sample frames.
*/
Sint32 status;
/* Version 1 of the RIFF specification calls the field in the fact chunk
* dwFileSize. The Standards Update then calls it dwSampleLength and specifies
* that it is 'the length of the data in samples'. WAVE files from Windows
* with this chunk have it set to the samples per channel (sample frames).
* This is useful to truncate compressed audio to a specific sample count
* because a compressed block is usually decoded to a fixed number of
* sample frames.
*/
Uint32 samplelength; /* Raw sample length value from the fact chunk. */
} WaveFact;
/* Generic struct for the chunks in the WAVE file. */
typedef struct WaveChunk
{
Uint32 fourcc; /* FOURCC of the chunk. */
Uint32 length; /* Size of the chunk data. */
Sint64 position; /* Position of the data in the stream. */
Uint8 *data; /* When allocated, this points to the chunk data. length is used for the malloc size. */
size_t size; /* Number of bytes in data that could be read from the stream. Can be smaller than length. */
} WaveChunk;
/* Controls how the size of the RIFF chunk affects the loading of a WAVE file. */
typedef enum WaveRiffSizeHint {
RiffSizeNoHint,
RiffSizeForce,
RiffSizeIgnoreZero,
RiffSizeIgnore,
RiffSizeMaximum
} WaveRiffSizeHint;
/* Controls how a truncated WAVE file is handled. */
typedef enum WaveTruncationHint {
TruncNoHint,
TruncVeryStrict,
TruncStrict,
TruncDropFrame,
TruncDropBlock
} WaveTruncationHint;
/* Controls how the fact chunk affects the loading of a WAVE file. */
typedef enum WaveFactChunkHint {
FactNoHint,
FactTruncate,
FactStrict,
FactIgnoreZero,
FactIgnore
} WaveFactChunkHint;
typedef struct WaveFile
{
WaveChunk chunk;
WaveFormat format;
WaveFact fact;
/* Number of sample frames that will be decoded. Calculated either with the
* size of the data chunk or, if the appropriate hint is enabled, with the
* sample length value from the fact chunk.
*/
Sint64 sampleframes;
void *decoderdata; /* Some decoders require extra data for a state. */
WaveRiffSizeHint riffhint;
WaveTruncationHint trunchint;
WaveFactChunkHint facthint;
} WaveFile;
/* vi: set ts=4 sw=4 expandtab: */
WaveFormat::subformat
Uint8 subformat[16]
Definition: SDL_wave.h:69
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
TruncVeryStrict
@ TruncVeryStrict
Definition: SDL_wave.h:115
Sint32
int32_t Sint32
Definition: SDL_stdinc.h:197
WaveFile::format
WaveFormat format
Definition: SDL_wave.h:133
Sint64
int64_t Sint64
Definition: SDL_stdinc.h:210
TruncNoHint
@ TruncNoHint
Definition: SDL_wave.h:114
WaveChunk::data
Uint8 * data
Definition: SDL_wave.h:99
WaveFile::riffhint
WaveRiffSizeHint riffhint
Definition: SDL_wave.h:144
WaveFormat::byterate
Uint32 byterate
Definition: SDL_wave.h:56
WaveTruncationHint
WaveTruncationHint
Definition: SDL_wave.h:113
RiffSizeForce
@ RiffSizeForce
Definition: SDL_wave.h:106
WaveFormat::bitspersample
Uint16 bitspersample
Definition: SDL_wave.h:58
WaveRiffSizeHint
WaveRiffSizeHint
Definition: SDL_wave.h:104
WaveFile
Definition: SDL_wave.h:130
RiffSizeNoHint
@ RiffSizeNoHint
Definition: SDL_wave.h:105
WaveFile::facthint
WaveFactChunkHint facthint
Definition: SDL_wave.h:146
RiffSizeIgnore
@ RiffSizeIgnore
Definition: SDL_wave.h:108
WaveFormat
Definition: SDL_wave.h:50
WaveFormat::encoding
Uint16 encoding
Definition: SDL_wave.h:53
FactTruncate
@ FactTruncate
Definition: SDL_wave.h:124
WaveChunk::size
size_t size
Definition: SDL_wave.h:100
TruncDropFrame
@ TruncDropFrame
Definition: SDL_wave.h:117
WaveFact::samplelength
Uint32 samplelength
Definition: SDL_wave.h:90
FactStrict
@ FactStrict
Definition: SDL_wave.h:125
WaveFact
Definition: SDL_wave.h:73
WaveChunk::fourcc
Uint32 fourcc
Definition: SDL_wave.h:96
WaveFactChunkHint
WaveFactChunkHint
Definition: SDL_wave.h:122
WaveFile::trunchint
WaveTruncationHint trunchint
Definition: SDL_wave.h:145
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
WaveFile::sampleframes
Sint64 sampleframes
Definition: SDL_wave.h:140
WaveFact::status
Sint32 status
Definition: SDL_wave.h:80
WaveFormat::samplesperblock
Uint32 samplesperblock
Definition: SDL_wave.h:67
WaveFile::chunk
WaveChunk chunk
Definition: SDL_wave.h:132
FactIgnoreZero
@ FactIgnoreZero
Definition: SDL_wave.h:126
WaveFile::fact
WaveFact fact
Definition: SDL_wave.h:134
FactIgnore
@ FactIgnore
Definition: SDL_wave.h:127
WaveChunk::length
Uint32 length
Definition: SDL_wave.h:97
RiffSizeIgnoreZero
@ RiffSizeIgnoreZero
Definition: SDL_wave.h:107
WaveChunk
Definition: SDL_wave.h:94
TruncDropBlock
@ TruncDropBlock
Definition: SDL_wave.h:118
WaveFormat::channelmask
Uint32 channelmask
Definition: SDL_wave.h:68
FactNoHint
@ FactNoHint
Definition: SDL_wave.h:123
WaveFormat::extsize
Uint16 extsize
Definition: SDL_wave.h:63
WaveFormat::formattag
Uint16 formattag
Definition: SDL_wave.h:52
WaveFormat::channels
Uint16 channels
Definition: SDL_wave.h:54
TruncStrict
@ TruncStrict
Definition: SDL_wave.h:116
RiffSizeMaximum
@ RiffSizeMaximum
Definition: SDL_wave.h:109
WaveFormat::frequency
Uint32 frequency
Definition: SDL_wave.h:55
WaveFormat::blockalign
Uint16 blockalign
Definition: SDL_wave.h:57
WaveFormat::validsamplebits
Uint16 validsamplebits
Definition: SDL_wave.h:66
WaveChunk::position
Sint64 position
Definition: SDL_wave.h:98
WaveFile::decoderdata
void * decoderdata
Definition: SDL_wave.h:142
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179