Added music decoding

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-15 11:42:02 +01:00
parent 9d1f38752a
commit e6fa4b761e
3 changed files with 35 additions and 5 deletions

View File

@@ -10,7 +10,36 @@ class AdLibSound {
AdLibSound(this.bytes);
}
class ImfMusic {
final Uint8List bytes;
ImfMusic(this.bytes);
class ImfInstruction {
final int register;
final int data;
final int delay; // Delay in 1/700ths of a second
ImfInstruction({
required this.register,
required this.data,
required this.delay,
});
}
class ImfMusic {
final List<ImfInstruction> instructions;
ImfMusic(this.instructions);
factory ImfMusic.fromBytes(Uint8List bytes) {
List<ImfInstruction> instructions = [];
// Read the file in 4-byte chunks
for (int i = 0; i < bytes.length - 3; i += 4) {
instructions.add(
ImfInstruction(
register: bytes[i],
data: bytes[i + 1],
delay: bytes[i + 2] | (bytes[i + 3] << 8), // 16-bit little-endian
),
);
}
return ImfMusic(instructions);
}
}

View File

@@ -341,7 +341,7 @@ abstract class WLParser {
List<ImfMusic> music = allAudioChunks
.skip(300)
.where((chunk) => chunk.isNotEmpty)
.map((bytes) => ImfMusic(bytes))
.map((bytes) => ImfMusic.fromBytes(bytes))
.toList();
return (adLib: adLib, music: music);

View File

@@ -6,7 +6,8 @@ library;
export 'src/classes/game_file.dart' show GameFile;
export 'src/classes/game_version.dart' show GameVersion;
export 'src/classes/image.dart' show VgaImage;
export 'src/classes/sound.dart' show PcmSound, AdLibSound, ImfMusic;
export 'src/classes/sound.dart'
show PcmSound, AdLibSound, ImfMusic, ImfInstruction;
export 'src/classes/sprite.dart' hide Matrix;
export 'src/classes/wolf_level.dart' show WolfLevel;
export 'src/classes/wolfenstein_data.dart' show WolfensteinData;