SDL  2.0
SDL_wave.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../SDL_internal.h"
22 
23 /* RIFF WAVE files are little-endian */
24 
25 /*******************************************/
26 /* Define values for Microsoft WAVE format */
27 /*******************************************/
28 /* FOURCC */
29 #define RIFF 0x46464952 /* "RIFF" */
30 #define WAVE 0x45564157 /* "WAVE" */
31 #define FACT 0x74636166 /* "fact" */
32 #define LIST 0x5453494c /* "LIST" */
33 #define BEXT 0x74786562 /* "bext" */
34 #define JUNK 0x4B4E554A /* "JUNK" */
35 #define FMT 0x20746D66 /* "fmt " */
36 #define DATA 0x61746164 /* "data" */
37 /* Format tags */
38 #define UNKNOWN_CODE 0x0000
39 #define PCM_CODE 0x0001
40 #define MS_ADPCM_CODE 0x0002
41 #define IEEE_FLOAT_CODE 0x0003
42 #define ALAW_CODE 0x0006
43 #define MULAW_CODE 0x0007
44 #define IMA_ADPCM_CODE 0x0011
45 #define MPEG_CODE 0x0050
46 #define MPEGLAYER3_CODE 0x0055
47 #define EXTENSIBLE_CODE 0xFFFE
48 
49 /* Stores the WAVE format information. */
50 typedef struct WaveFormat
51 {
52  Uint16 formattag; /* Raw value of the first field in the fmt chunk data. */
53  Uint16 encoding; /* Actual encoding, possibly from the extensible header. */
54  Uint16 channels; /* Number of channels. */
55  Uint32 frequency; /* Sampling rate in Hz. */
56  Uint32 byterate; /* Average bytes per second. */
57  Uint16 blockalign; /* Bytes per block. */
58  Uint16 bitspersample; /* Currently supported are 8, 16, 24, 32, and 4 for ADPCM. */
59 
60  /* Extra information size. Number of extra bytes starting at byte 18 in the
61  * fmt chunk data. This is at least 22 for the extensible header.
62  */
64 
65  /* Extensible WAVE header fields */
67  Uint32 samplesperblock; /* For compressed formats. Can be zero. Actually 16 bits in the header. */
69  Uint8 subformat[16]; /* A format GUID. */
70 } WaveFormat;
71 
72 /* Stores information on the fact chunk. */
73 typedef struct WaveFact {
74  /* Represents the state of the fact chunk in the WAVE file.
75  * Set to -1 if the fact chunk is invalid.
76  * Set to 0 if the fact chunk is not present
77  * Set to 1 if the fact chunk is present and valid.
78  * Set to 2 if samplelength is going to be used as the number of sample frames.
79  */
81 
82  /* Version 1 of the RIFF specification calls the field in the fact chunk
83  * dwFileSize. The Standards Update then calls it dwSampleLength and specifies
84  * that it is 'the length of the data in samples'. WAVE files from Windows
85  * with this chunk have it set to the samples per channel (sample frames).
86  * This is useful to truncate compressed audio to a specific sample count
87  * because a compressed block is usually decoded to a fixed number of
88  * sample frames.
89  */
90  Uint32 samplelength; /* Raw sample length value from the fact chunk. */
91 } WaveFact;
92 
93 /* Generic struct for the chunks in the WAVE file. */
94 typedef struct WaveChunk
95 {
96  Uint32 fourcc; /* FOURCC of the chunk. */
97  Uint32 length; /* Size of the chunk data. */
98  Sint64 position; /* Position of the data in the stream. */
99  Uint8 *data; /* When allocated, this points to the chunk data. length is used for the malloc size. */
100  size_t size; /* Number of bytes in data that could be read from the stream. Can be smaller than length. */
101 } WaveChunk;
102 
103 /* Controls how the size of the RIFF chunk affects the loading of a WAVE file. */
104 typedef enum WaveRiffSizeHint {
111 
112 /* Controls how a truncated WAVE file is handled. */
113 typedef enum WaveTruncationHint {
120 
121 /* Controls how the fact chunk affects the loading of a WAVE file. */
122 typedef enum WaveFactChunkHint {
129 
130 typedef struct WaveFile
131 {
135 
136  /* Number of sample frames that will be decoded. Calculated either with the
137  * size of the data chunk or, if the appropriate hint is enabled, with the
138  * sample length value from the fact chunk.
139  */
141 
142  void *decoderdata; /* Some decoders require extra data for a state. */
143 
147 } WaveFile;
148 
149 /* vi: set ts=4 sw=4 expandtab: */
Uint16 extsize
Definition: SDL_wave.h:63
Uint32 channelmask
Definition: SDL_wave.h:68
Uint16 bitspersample
Definition: SDL_wave.h:58
Uint16 validsamplebits
Definition: SDL_wave.h:66
Uint16 channels
Definition: SDL_wave.h:54
WaveRiffSizeHint riffhint
Definition: SDL_wave.h:144
uint16_t Uint16
Definition: SDL_stdinc.h:191
WaveTruncationHint
Definition: SDL_wave.h:113
Uint32 byterate
Definition: SDL_wave.h:56
Uint32 samplelength
Definition: SDL_wave.h:90
WaveFactChunkHint facthint
Definition: SDL_wave.h:146
WaveRiffSizeHint
Definition: SDL_wave.h:104
WaveFactChunkHint
Definition: SDL_wave.h:122
WaveTruncationHint trunchint
Definition: SDL_wave.h:145
Uint32 fourcc
Definition: SDL_wave.h:96
uint8_t Uint8
Definition: SDL_stdinc.h:179
size_t size
Definition: SDL_wave.h:100
Sint32 status
Definition: SDL_wave.h:80
Uint16 blockalign
Definition: SDL_wave.h:57
Sint64 sampleframes
Definition: SDL_wave.h:140
WaveChunk chunk
Definition: SDL_wave.h:132
int32_t Sint32
Definition: SDL_stdinc.h:197
WaveFact fact
Definition: SDL_wave.h:134
Uint8 * data
Definition: SDL_wave.h:99
Sint64 position
Definition: SDL_wave.h:98
uint32_t Uint32
Definition: SDL_stdinc.h:203
Uint8 subformat[16]
Definition: SDL_wave.h:69
void * decoderdata
Definition: SDL_wave.h:142
Uint32 frequency
Definition: SDL_wave.h:55
Uint32 length
Definition: SDL_wave.h:97
Uint16 formattag
Definition: SDL_wave.h:52
int64_t Sint64
Definition: SDL_stdinc.h:210
Uint16 encoding
Definition: SDL_wave.h:53
WaveFormat format
Definition: SDL_wave.h:133
Uint32 samplesperblock
Definition: SDL_wave.h:67