| 153 |  | using (var stream = File.Create(Path.Combine(OutputDirPath, descriptor.FullName + ".wav"))) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 154 |  | using (var writer = new BinaryWriter(stream)) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 155 |  | { | 
 
 
 
 
 
 
 
 
 
 
 | 156 | < | var blockSizeADPCM = sound.BlockAlignment; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 157 | < |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 158 | < | int wholeBlocks = sound.Data.Length / blockSizeADPCM; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 159 | < | int leftoverBytes = sound.Data.Length - (wholeBlocks * blockSizeADPCM); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 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 / sound.BitsPerSample; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 168 | < |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 169 | < | Int32 sampleCount = wholeBlocks * samplesPerBlock + leftoverSamples; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 170 | < |  | 
 
 
 
 
 
 
 
 
 | 156 | > | int blockSizeADPCM, samplesPerBlock, sampleCount, paddingBytes = 0; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 157 |  | if (sound.IsIMA4) // IMA4 ADPCM format | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 158 |  | { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 159 |  | blockSizeADPCM = 34 * sound.ChannelCount; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 160 |  | samplesPerBlock = 64; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 161 |  | sampleCount = (sound.Data.Length / blockSizeADPCM) * samplesPerBlock; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 162 |  | } | 
 
 
 
 
 
 
 
 | 163 | + | else | 
 
 
 
 
 
 
 
 | 164 | + | { | 
 
 
 
 
 
 
 
 | 165 | + | blockSizeADPCM = sound.BlockAlignment; | 
 
 
 
 
 
 
 
 | 166 | + | int wholeBlocks = sound.Data.Length / blockSizeADPCM; | 
 
 
 
 
 
 
 
 | 167 | + | int leftoverBytes = sound.Data.Length - (wholeBlocks * blockSizeADPCM); | 
 
 
 
 
 
 
 
 | 168 | + | int leftoverSamples = 0; | 
 
 
 
 
 
 
 
 | 169 | + | if (leftoverBytes > 7 * sound.ChannelCount) | 
 
 
 
 
 
 
 
 | 170 | + | leftoverSamples = 2 + (leftoverBytes - 7 * sound.ChannelCount) | 
 
 
 
 
 
 
 
 | 171 | + | * 8 / sound.BitsPerSample / sound.ChannelCount; | 
 
 
 
 
 
 
 
 | 172 | + | else | 
 
 
 
 
 
 
 
 | 173 | + | Console.Error.WriteLine("Improper trailing bytes/samples!"); | 
 
 
 
 
 
 
 
 | 174 | + | if (leftoverBytes > 0) // incomplete trailing block | 
 
 
 
 
 
 
 
 | 175 | + | paddingBytes = blockSizeADPCM - leftoverBytes; | 
 
 
 
 
 
 
 
 | 176 | + | samplesPerBlock = 2 + (blockSizeADPCM - sound.ChannelCount * 7) * 8 / sound.ChannelCount / sound.BitsPerSample; | 
 
 
 
 
 
 
 
 | 177 | + | sampleCount = wholeBlocks * samplesPerBlock + leftoverSamples; | 
 
 
 
 
 
 
 
 | 178 | + | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 179 |  | if (!convert_to_PCM) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 180 |  | { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 181 |  | if (sound.IsIMA4) |