| 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 |  | { |