| 1 |
/* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 |
/* SPDX-FileCopyrightText: OpenMPT Project Developers and Contributors */ |
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include "openmpt/all/BuildSettings.hpp" |
| 8 |
|
| 9 |
#include "mpt/uuid/uuid.hpp" |
| 10 |
|
| 11 |
#include "openmpt/base/Endian.hpp" |
| 12 |
#include "openmpt/fileformat_base/magic.hpp" |
| 13 |
|
| 14 |
#include <cstddef> |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
OPENMPT_NAMESPACE_BEGIN |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
// RIFF header |
| 23 |
struct RIFFHeader |
| 24 |
{ |
| 25 |
// 32-Bit chunk identifiers |
| 26 |
enum RIFFMagic |
| 27 |
{ |
| 28 |
idRIFF = MagicLE("RIFF"), // magic for WAV files |
| 29 |
idLIST = MagicLE("LIST"), // magic for samples in DLS banks |
| 30 |
idWAVE = MagicLE("WAVE"), // type for WAV files |
| 31 |
idwave = MagicLE("wave"), // type for samples in DLS banks |
| 32 |
}; |
| 33 |
|
| 34 |
uint32le magic; // RIFF (in WAV files) or LIST (in DLS banks) |
| 35 |
uint32le length; // Size of the file, not including magic and length |
| 36 |
uint32le type; // WAVE (in WAV files) or wave (in DLS banks) |
| 37 |
}; |
| 38 |
|
| 39 |
MPT_BINARY_STRUCT(RIFFHeader, 12) |
| 40 |
|
| 41 |
|
| 42 |
// General RIFF Chunk header |
| 43 |
struct RIFFChunk |
| 44 |
{ |
| 45 |
// 32-Bit chunk identifiers |
| 46 |
enum ChunkIdentifiers |
| 47 |
{ |
| 48 |
idfmt_ = MagicLE("fmt "), // Sample format information |
| 49 |
iddata = MagicLE("data"), // Sample data |
| 50 |
idpcm_ = MagicLE("pcm "), // IMA ADPCM samples |
| 51 |
idfact = MagicLE("fact"), // Compressed samples |
| 52 |
idsmpl = MagicLE("smpl"), // Sampler and loop information |
| 53 |
idinst = MagicLE("inst"), // Instrument information |
| 54 |
idLIST = MagicLE("LIST"), // List of chunks |
| 55 |
idxtra = MagicLE("xtra"), // OpenMPT extra infomration |
| 56 |
idcue_ = MagicLE("cue "), // Cue points |
| 57 |
idwsmp = MagicLE("wsmp"), // DLS bank samples |
| 58 |
idCSET = MagicLE("CSET"), // Character Set |
| 59 |
id____ = 0x00000000, // Found when loading buggy MPT samples |
| 60 |
|
| 61 |
// Identifiers in "LIST" chunk |
| 62 |
idINAM = MagicLE("INAM"), // title |
| 63 |
idISFT = MagicLE("ISFT"), // software |
| 64 |
idICOP = MagicLE("ICOP"), // copyright |
| 65 |
idIART = MagicLE("IART"), // artist |
| 66 |
idIPRD = MagicLE("IPRD"), // product (album) |
| 67 |
idICMT = MagicLE("ICMT"), // comment |
| 68 |
idIENG = MagicLE("IENG"), // engineer |
| 69 |
idISBJ = MagicLE("ISBJ"), // subject |
| 70 |
idIGNR = MagicLE("IGNR"), // genre |
| 71 |
idICRD = MagicLE("ICRD"), // date created |
| 72 |
|
| 73 |
idYEAR = MagicLE("YEAR"), // year |
| 74 |
idTRCK = MagicLE("TRCK"), // track number |
| 75 |
idTURL = MagicLE("TURL"), // url |
| 76 |
}; |
| 77 |
|
| 78 |
uint32le id; // See ChunkIdentifiers |
| 79 |
uint32le length; // Chunk size without header |
| 80 |
|
| 81 |
std::size_t GetLength() const |
| 82 |
{ |
| 83 |
return length; |
| 84 |
} |
| 85 |
|
| 86 |
ChunkIdentifiers GetID() const |
| 87 |
{ |
| 88 |
return static_cast<ChunkIdentifiers>(id.get()); |
| 89 |
} |
| 90 |
}; |
| 91 |
|
| 92 |
MPT_BINARY_STRUCT(RIFFChunk, 8) |
| 93 |
|
| 94 |
|
| 95 |
// Format Chunk |
| 96 |
struct WAVFormatChunk |
| 97 |
{ |
| 98 |
// Sample formats |
| 99 |
enum SampleFormats |
| 100 |
{ |
| 101 |
fmtPCM = 1, |
| 102 |
fmtFloat = 3, |
| 103 |
fmtALaw = 6, |
| 104 |
fmtULaw = 7, |
| 105 |
fmtIMA_ADPCM = 17, |
| 106 |
fmtMP3 = 85, |
| 107 |
fmtExtensible = 0xFFFE, |
| 108 |
}; |
| 109 |
|
| 110 |
uint16le format; // Sample format, see SampleFormats |
| 111 |
uint16le numChannels; // Number of audio channels |
| 112 |
uint32le sampleRate; // Sample rate in Hz |
| 113 |
uint32le byteRate; // Bytes per second (should be freqHz * blockAlign) |
| 114 |
uint16le blockAlign; // Size of a sample, in bytes (do not trust this value, it's incorrect in some files) |
| 115 |
uint16le bitsPerSample; // Bits per sample |
| 116 |
}; |
| 117 |
|
| 118 |
MPT_BINARY_STRUCT(WAVFormatChunk, 16) |
| 119 |
|
| 120 |
|
| 121 |
// Extension of the WAVFormatChunk structure, used if format == formatExtensible |
| 122 |
struct WAVFormatChunkExtension |
| 123 |
{ |
| 124 |
uint16le size; |
| 125 |
uint16le validBitsPerSample; |
| 126 |
uint32le channelMask; |
| 127 |
mpt::GUIDms subFormat; |
| 128 |
}; |
| 129 |
|
| 130 |
MPT_BINARY_STRUCT(WAVFormatChunkExtension, 24) |
| 131 |
|
| 132 |
|
| 133 |
// Sample cue point structure for the "cue " chunk |
| 134 |
struct WAVCuePoint |
| 135 |
{ |
| 136 |
uint32le id; // Unique identification value |
| 137 |
uint32le position; // Play order position |
| 138 |
uint32le riffChunkID; // RIFF ID of corresponding data chunk |
| 139 |
uint32le chunkStart; // Byte Offset of Data Chunk |
| 140 |
uint32le blockStart; // Byte Offset to sample of First Channel |
| 141 |
uint32le offset; // Byte Offset to sample byte of First Channel |
| 142 |
}; |
| 143 |
|
| 144 |
MPT_BINARY_STRUCT(WAVCuePoint, 24) |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
OPENMPT_NAMESPACE_END |