Added audio loading and decompressing
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -47,6 +47,8 @@ abstract class WLParser {
|
||||
vgaDict: await fileFetcher('VGADICT.$ext'),
|
||||
vgaHead: await fileFetcher('VGAHEAD.$ext'),
|
||||
vgaGraph: await fileFetcher('VGAGRAPH.$ext'),
|
||||
audioHed: await fileFetcher('AUDIOHED.$ext'),
|
||||
audioT: await fileFetcher('AUDIOT.$ext'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,9 +63,13 @@ abstract class WLParser {
|
||||
required ByteData vgaDict,
|
||||
required ByteData vgaHead,
|
||||
required ByteData vgaGraph,
|
||||
required ByteData audioHed,
|
||||
required ByteData audioT,
|
||||
}) {
|
||||
final isShareware = version == GameVersion.shareware;
|
||||
|
||||
final audio = parseAudio(audioHed, audioT);
|
||||
|
||||
return WolfensteinData(
|
||||
version: version,
|
||||
walls: parseWalls(vswap),
|
||||
@@ -71,6 +77,8 @@ abstract class WLParser {
|
||||
sounds: parseSounds(vswap).map((bytes) => PcmSound(bytes)).toList(),
|
||||
levels: parseMaps(mapHead, gameMaps, isShareware: isShareware),
|
||||
vgaImages: parseVgaImages(vgaDict, vgaHead, vgaGraph),
|
||||
adLibSounds: audio.adLib,
|
||||
music: audio.music,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -289,6 +297,56 @@ abstract class WLParser {
|
||||
return levels;
|
||||
}
|
||||
|
||||
/// Extracts AdLib sounds and IMF music tracks from the audio files.
|
||||
static ({List<AdLibSound> adLib, List<ImfMusic> music}) parseAudio(
|
||||
ByteData audioHed,
|
||||
ByteData audioT,
|
||||
) {
|
||||
List<int> offsets = [];
|
||||
// AUDIOHED is a series of 32-bit unsigned integers
|
||||
for (int i = 0; i < audioHed.lengthInBytes ~/ 4; i++) {
|
||||
offsets.add(audioHed.getUint32(i * 4, Endian.little));
|
||||
}
|
||||
|
||||
List<Uint8List> allAudioChunks = [];
|
||||
|
||||
for (int i = 0; i < offsets.length - 1; i++) {
|
||||
int start = offsets[i];
|
||||
int next = offsets[i + 1];
|
||||
|
||||
// 0xFFFFFFFF (or 4294967295) marks an empty slot
|
||||
if (start == 0xFFFFFFFF || start >= audioT.lengthInBytes) {
|
||||
allAudioChunks.add(Uint8List(0));
|
||||
continue;
|
||||
}
|
||||
|
||||
int length = next - start;
|
||||
if (length <= 0) {
|
||||
allAudioChunks.add(Uint8List(0));
|
||||
} else {
|
||||
allAudioChunks.add(
|
||||
audioT.buffer.asUint8List(audioT.offsetInBytes + start, length),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Wolfenstein 3D split:
|
||||
// Chunks 0-299: AdLib Sounds
|
||||
// Chunks 300+: IMF Music
|
||||
List<AdLibSound> adLib = allAudioChunks
|
||||
.take(300)
|
||||
.map((bytes) => AdLibSound(bytes))
|
||||
.toList();
|
||||
|
||||
List<ImfMusic> music = allAudioChunks
|
||||
.skip(300)
|
||||
.where((chunk) => chunk.isNotEmpty)
|
||||
.map((bytes) => ImfMusic(bytes))
|
||||
.toList();
|
||||
|
||||
return (adLib: adLib, music: music);
|
||||
}
|
||||
|
||||
// --- ALGORITHM 1: CARMACK EXPANSION ---
|
||||
static Uint16List _expandCarmack(Uint8List compressed) {
|
||||
ByteData data = ByteData.sublistView(compressed);
|
||||
|
||||
Reference in New Issue
Block a user