using System; using System.Collections.Generic; using System.Text; namespace Oni.Sound { internal class SoundData { public bool IsIMA4; public int SampleRate; public int ChannelCount; public byte[] Data; public static SoundData Read(InstanceDescriptor sndd) { if (sndd.Template.Tag != TemplateTag.SNDD) throw new ArgumentException("descriptor"); var sound = new SoundData(); int dataSize; int dataOffset; using (var reader = sndd.OpenRead()) { if (sndd.IsMacFile) { sound.ChannelCount = (reader.ReadInt32() >> 1) + 1; sound.SampleRate = 22050; reader.Skip(4); sound.IsIMA4 = true; } else { reader.Skip(6); // ADPCM format identifiers (change to support PCM?) sound.ChannelCount = reader.ReadInt16(); sound.SampleRate = reader.ReadInt32(); reader.Skip(44); sound.IsIMA4 = false; } dataSize = reader.ReadInt32(); dataOffset = reader.ReadInt32(); } using (var rawReader = sndd.GetRawReader(dataOffset)) sound.Data = rawReader.ReadBytes(dataSize); return sound; } } }