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