@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user