Changeset 1156 for OniSplit/Sound/WavExporter.cs
- Timestamp:
- May 8, 2021, 3:44:24 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OniSplit/Sound/WavExporter.cs
r1154 r1156 154 154 using (var writer = new BinaryWriter(stream)) 155 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; 171 157 if (sound.IsIMA4) // IMA4 ADPCM format 172 158 { … … 174 160 samplesPerBlock = 64; 175 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; 176 178 } 177 179 if (!convert_to_PCM)
Note:
See TracChangeset
for help on using the changeset viewer.