diff --git a/packages/wolf_3d_data/lib/src/classes/sound.dart b/packages/wolf_3d_data/lib/src/classes/sound.dart index f126f8c..da124e6 100644 --- a/packages/wolf_3d_data/lib/src/classes/sound.dart +++ b/packages/wolf_3d_data/lib/src/classes/sound.dart @@ -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 instructions; + + ImfMusic(this.instructions); + + factory ImfMusic.fromBytes(Uint8List bytes) { + List 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); + } } diff --git a/packages/wolf_3d_data/lib/src/wl_parser.dart b/packages/wolf_3d_data/lib/src/wl_parser.dart index 5908a14..d195360 100644 --- a/packages/wolf_3d_data/lib/src/wl_parser.dart +++ b/packages/wolf_3d_data/lib/src/wl_parser.dart @@ -341,7 +341,7 @@ abstract class WLParser { List music = allAudioChunks .skip(300) .where((chunk) => chunk.isNotEmpty) - .map((bytes) => ImfMusic(bytes)) + .map((bytes) => ImfMusic.fromBytes(bytes)) .toList(); return (adLib: adLib, music: music); diff --git a/packages/wolf_3d_data/lib/wolf_3d_data.dart b/packages/wolf_3d_data/lib/wolf_3d_data.dart index a9320b0..2996597 100644 --- a/packages/wolf_3d_data/lib/wolf_3d_data.dart +++ b/packages/wolf_3d_data/lib/wolf_3d_data.dart @@ -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;