ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/OniSplit/Sound/SoundData.cs
(Generate patch)

Comparing OniSplit/Sound/SoundData.cs (file contents):
Revision 1130 by geyser, Thu May 28 21:28:44 2020 UTC vs.
Revision 1131 by geyser, Sat May 30 12:08:12 2020 UTC

# Line 11 | Line 11 | namespace Oni.Sound
11          public int ChannelCount;
12          public byte[] Data;
13  
14 <        public static SoundData Read(InstanceDescriptor sndd)
14 >        public static SoundData Read(InstanceDescriptor sndd, bool do_pc_demo_test)
15          {
16              if (sndd.Template.Tag != TemplateTag.SNDD)
17                  throw new ArgumentException("descriptor");
# Line 46 | Line 46 | namespace Oni.Sound
46              using (var rawReader = sndd.GetRawReader(dataOffset))
47                  sound.Data = rawReader.ReadBytes(dataSize);
48  
49 +            if (sound.IsIMA4 && do_pc_demo_test) // check if the raw data actually looks like IMA4
50 +            {
51 +                int nIMABlocks = sound.Data.Length / 34;
52 +                int remainder = sound.Data.Length - nIMABlocks * 34;
53 +                if (remainder == 0 && (nIMABlocks % sound.ChannelCount) == 0)
54 +                {
55 +                    bool stepIndexAbove88 = false;
56 +                    for (int ii = 0; ii < nIMABlocks; ii++)
57 +                    {
58 +                        Byte cc = sound.Data[ii * 34 + 1];
59 +                        if ((cc & 0x7F) > 88)
60 +                            stepIndexAbove88 = true;
61 +                    }
62 +                    if (stepIndexAbove88)
63 +                        sound.IsIMA4 = false;
64 +                }
65 +                else
66 +                    sound.IsIMA4 = false;
67 +                if (!(sound.IsIMA4))
68 +                    Console.WriteLine("PC-demo MS ADPCM detected; use -nodemo flag to treat as IMA4.");
69 +            }
70 +
71              return sound;
72          }
73      }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)