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

Comparing OniSplit/Sound/WavExporter.cs (file contents):
Revision 1131 by geyser, Sat May 30 12:08:12 2020 UTC vs.
Revision 1154 by geyser, Mon May 3 15:22:15 2021 UTC

# Line 153 | Line 153 | namespace Oni.Sound
153              using (var stream = File.Create(Path.Combine(OutputDirPath, descriptor.FullName + ".wav")))
154              using (var writer = new BinaryWriter(stream))
155              {
156 <                var blockSizeADPCM = 512 * sound.ChannelCount * sound.SampleRate / 22050;
156 >                var blockSizeADPCM = sound.BlockAlignment;
157 >                
158                  int wholeBlocks = sound.Data.Length / blockSizeADPCM;
159                  int leftoverBytes = sound.Data.Length - (wholeBlocks * blockSizeADPCM);
160 <                int leftoverSamples = 8 * (leftoverBytes - 7 * sound.ChannelCount)
161 <                                      / 4 / sound.ChannelCount + 2; // 4 bits per sample
160 >                int leftoverSamples = 0;
161 >                if(leftoverBytes > 14)
162 >                    leftoverSamples = 2 + (leftoverBytes - 7 * sound.ChannelCount)
163 >                                    * 8 / sound.BitsPerSample / sound.ChannelCount;
164                  int paddingBytes = 0;
165                  if (leftoverBytes > 0) // incomplete trailing block
166                      paddingBytes = blockSizeADPCM - leftoverBytes;
167 <                var samplesPerBlock = 2 + (blockSizeADPCM - sound.ChannelCount * 7) * 8 / sound.ChannelCount / 4;
167 >                var samplesPerBlock = 2 + (blockSizeADPCM - sound.ChannelCount * 7) * 8 / sound.ChannelCount / sound.BitsPerSample;
168  
169 <                Int32 sampleCount = sampleCount = wholeBlocks * samplesPerBlock + leftoverSamples;
169 >                Int32 sampleCount = wholeBlocks * samplesPerBlock + leftoverSamples;
170  
171                  if (sound.IsIMA4) // IMA4 ADPCM format
172                  {

Diff Legend

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