playing sounds from bytes

I’m trying to read Midi and Voc files from an unencrypted archive file for a reverse engineering project, right now it exports the files, are there libraries that would let me play the files using raw bytes?

using System; using System.Collections.Generic; using System.IO; namespace OpenNitemare3D { class main { static void Main() { const string directory = @"C:files"; var path = Path.Combine(directory, "SND.DAT"); using (var stream = File.OpenRead(path)) using (var reader = new BinaryReader(stream)) { stream.Position = 0; var samples = new List<Sample>(); while (true) { var sample = new Sample(reader); if (sample.Position == stream.Length) break; samples.Add(sample); } var index = 0; foreach (var sample in samples) { string extension; switch (index) { case 0: extension = "IBK"; break; case int n when n >= 1 && n <= 15: extension = "MID"; break; case int n when n >= 34 && n <= 110: extension = "VOC"; break; default: extension = ".BIN"; break; } var name = $"{path}.{index++:D3}.{extension}"; if (sample.Length == 0) continue; stream.Position = sample.Position; var bytes = reader.ReadBytes(sample.Length); File.WriteAllBytes(name, bytes); } } } public struct Sample { public readonly short Length; public readonly int Position; public Sample(BinaryReader reader) { if (reader == null) throw new ArgumentNullException(nameof(reader)); Length = reader.ReadInt16(); Position = reader.ReadInt32(); } public override string ToString() { return $"{nameof(Position)}: {Position}, {nameof(Length)}: {Length}"; } } } } 

submitted by /u/GodIsDead_
[link] [comments]

Leave a Reply