Ignore:
Timestamp:
May 8, 2021, 3:44:24 AM (14 months ago)
Author:
geyser
Message:

Fixed importing of "fact" chunk, as well as an unhandled fatal when attempting to transcode IMA4 to MS ADPCM. Also added missing padding to SNDD template and fixed the duration calculation for WAV-to-SNDD.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OniSplit/Sound/WavExporter.cs

    r1154 r1156  
    154154            using (var writer = new BinaryWriter(stream))
    155155            {
    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;
    171157                if (sound.IsIMA4) // IMA4 ADPCM format
    172158                {
     
    174160                    samplesPerBlock = 64;
    175161                    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;
    176178                }
    177179                if (!convert_to_PCM)
Note: See TracChangeset for help on using the changeset viewer.