--- OniSplit/Sound/WavExporter.cs 2021/05/03 15:22:15 1154 +++ OniSplit/Sound/WavExporter.cs 2021/05/08 01:44:24 1156 @@ -153,27 +153,29 @@ namespace Oni.Sound using (var stream = File.Create(Path.Combine(OutputDirPath, descriptor.FullName + ".wav"))) using (var writer = new BinaryWriter(stream)) { - var blockSizeADPCM = sound.BlockAlignment; - - int wholeBlocks = sound.Data.Length / blockSizeADPCM; - int leftoverBytes = sound.Data.Length - (wholeBlocks * blockSizeADPCM); - 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 / sound.BitsPerSample; - - Int32 sampleCount = wholeBlocks * samplesPerBlock + leftoverSamples; - + int blockSizeADPCM, samplesPerBlock, sampleCount, paddingBytes = 0; if (sound.IsIMA4) // IMA4 ADPCM format { blockSizeADPCM = 34 * sound.ChannelCount; samplesPerBlock = 64; sampleCount = (sound.Data.Length / blockSizeADPCM) * samplesPerBlock; } + else + { + blockSizeADPCM = sound.BlockAlignment; + int wholeBlocks = sound.Data.Length / blockSizeADPCM; + int leftoverBytes = sound.Data.Length - (wholeBlocks * blockSizeADPCM); + int leftoverSamples = 0; + if (leftoverBytes > 7 * sound.ChannelCount) + leftoverSamples = 2 + (leftoverBytes - 7 * sound.ChannelCount) + * 8 / sound.BitsPerSample / sound.ChannelCount; + else + Console.Error.WriteLine("Improper trailing bytes/samples!"); + if (leftoverBytes > 0) // incomplete trailing block + paddingBytes = blockSizeADPCM - leftoverBytes; + samplesPerBlock = 2 + (blockSizeADPCM - sound.ChannelCount * 7) * 8 / sound.ChannelCount / sound.BitsPerSample; + sampleCount = wholeBlocks * samplesPerBlock + leftoverSamples; + } if (!convert_to_PCM) { if (sound.IsIMA4)