--- OniSplit/Sound/WavExporter.cs 2020/05/30 12:08:12 1131 +++ OniSplit/Sound/WavExporter.cs 2021/05/03 15:22:15 1154 @@ -153,17 +153,20 @@ namespace Oni.Sound using (var stream = File.Create(Path.Combine(OutputDirPath, descriptor.FullName + ".wav"))) using (var writer = new BinaryWriter(stream)) { - var blockSizeADPCM = 512 * sound.ChannelCount * sound.SampleRate / 22050; + var blockSizeADPCM = sound.BlockAlignment; + int wholeBlocks = sound.Data.Length / blockSizeADPCM; int leftoverBytes = sound.Data.Length - (wholeBlocks * blockSizeADPCM); - int leftoverSamples = 8 * (leftoverBytes - 7 * sound.ChannelCount) - / 4 / sound.ChannelCount + 2; // 4 bits per sample + int leftoverSamples = 0; + if(leftoverBytes > 14) + leftoverSamples = 2 + (leftoverBytes - 7 * sound.ChannelCount) + * 8 / sound.BitsPerSample / sound.ChannelCount; int paddingBytes = 0; if (leftoverBytes > 0) // incomplete trailing block paddingBytes = blockSizeADPCM - leftoverBytes; - var samplesPerBlock = 2 + (blockSizeADPCM - sound.ChannelCount * 7) * 8 / sound.ChannelCount / 4; + var samplesPerBlock = 2 + (blockSizeADPCM - sound.ChannelCount * 7) * 8 / sound.ChannelCount / sound.BitsPerSample; - Int32 sampleCount = sampleCount = wholeBlocks * samplesPerBlock + leftoverSamples; + Int32 sampleCount = wholeBlocks * samplesPerBlock + leftoverSamples; if (sound.IsIMA4) // IMA4 ADPCM format {