--- OniSplit/Sound/SoundData.cs 2020/05/28 21:28:44 1130 +++ OniSplit/Sound/SoundData.cs 2020/05/30 12:08:12 1131 @@ -11,7 +11,7 @@ namespace Oni.Sound public int ChannelCount; public byte[] Data; - public static SoundData Read(InstanceDescriptor sndd) + public static SoundData Read(InstanceDescriptor sndd, bool do_pc_demo_test) { if (sndd.Template.Tag != TemplateTag.SNDD) throw new ArgumentException("descriptor"); @@ -46,6 +46,28 @@ namespace Oni.Sound using (var rawReader = sndd.GetRawReader(dataOffset)) sound.Data = rawReader.ReadBytes(dataSize); + if (sound.IsIMA4 && do_pc_demo_test) // check if the raw data actually looks like IMA4 + { + int nIMABlocks = sound.Data.Length / 34; + int remainder = sound.Data.Length - nIMABlocks * 34; + if (remainder == 0 && (nIMABlocks % sound.ChannelCount) == 0) + { + bool stepIndexAbove88 = false; + for (int ii = 0; ii < nIMABlocks; ii++) + { + Byte cc = sound.Data[ii * 34 + 1]; + if ((cc & 0x7F) > 88) + stepIndexAbove88 = true; + } + if (stepIndexAbove88) + sound.IsIMA4 = false; + } + else + sound.IsIMA4 = false; + if (!(sound.IsIMA4)) + Console.WriteLine("PC-demo MS ADPCM detected; use -nodemo flag to treat as IMA4."); + } + return sound; } }