Changeset 1131 for OniSplit/Sound
- Timestamp:
- May 30, 2020, 2:08:12 PM (4 years ago)
- Location:
- OniSplit/Sound
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
OniSplit/Sound/AifExporter.cs
r1130 r1131 7 7 { 8 8 #region Private data 9 private bool do_pc_demo_test; 10 9 11 private const int fcc_FORM = 0x464f524d; 10 12 private const int fcc_AIFC = 0x41494643; … … 20 22 #endregion 21 23 22 public AifExporter(InstanceFileManager fileManager, string outputDirPath )24 public AifExporter(InstanceFileManager fileManager, string outputDirPath, bool noDemo = false) 23 25 : base(fileManager, outputDirPath) 24 26 { 27 do_pc_demo_test = !noDemo; 25 28 } 26 29 27 30 protected override void ExportInstance(InstanceDescriptor descriptor) 28 31 { 29 var sound = SoundData.Read(descriptor );32 var sound = SoundData.Read(descriptor, do_pc_demo_test); 30 33 31 34 using (var stream = File.Create(Path.Combine(OutputDirPath, descriptor.FullName + ".aif"))) … … 34 37 if (!(sound.IsIMA4)) 35 38 { 36 throw new NotSupportedException("Transcoding from PC ADPCM to Mac/demo ADPCMnot supported!");39 throw new NotSupportedException("Transcoding from MS ADPCM (PC) to IMA4 ADPCM (Mac) not supported!"); 37 40 } 38 41 writer.Write(Utils.ByteSwap(fcc_FORM)); -
OniSplit/Sound/SoundData.cs
r1130 r1131 12 12 public byte[] Data; 13 13 14 public static SoundData Read(InstanceDescriptor sndd )14 public static SoundData Read(InstanceDescriptor sndd, bool do_pc_demo_test) 15 15 { 16 16 if (sndd.Template.Tag != TemplateTag.SNDD) … … 47 47 sound.Data = rawReader.ReadBytes(dataSize); 48 48 49 if (sound.IsIMA4 && do_pc_demo_test) // check if the raw data actually looks like IMA4 50 { 51 int nIMABlocks = sound.Data.Length / 34; 52 int remainder = sound.Data.Length - nIMABlocks * 34; 53 if (remainder == 0 && (nIMABlocks % sound.ChannelCount) == 0) 54 { 55 bool stepIndexAbove88 = false; 56 for (int ii = 0; ii < nIMABlocks; ii++) 57 { 58 Byte cc = sound.Data[ii * 34 + 1]; 59 if ((cc & 0x7F) > 88) 60 stepIndexAbove88 = true; 61 } 62 if (stepIndexAbove88) 63 sound.IsIMA4 = false; 64 } 65 else 66 sound.IsIMA4 = false; 67 if (!(sound.IsIMA4)) 68 Console.WriteLine("PC-demo MS ADPCM detected; use -nodemo flag to treat as IMA4."); 69 } 70 49 71 return sound; 50 72 } -
OniSplit/Sound/WavExporter.cs
r1130 r1131 8 8 #region Private data 9 9 private bool convert_to_PCM; 10 private bool do_pc_demo_test; 10 11 11 12 private const int fcc_RIFF = 0x46464952; … … 86 87 #endregion 87 88 88 public WavExporter(InstanceFileManager fileManager, string outputDirPath, bool convertToPCM = false )89 public WavExporter(InstanceFileManager fileManager, string outputDirPath, bool convertToPCM = false, bool noDemo = false) 89 90 : base(fileManager, outputDirPath) 90 91 { 91 92 convert_to_PCM = convertToPCM; 93 do_pc_demo_test = !noDemo; 92 94 } 93 95 … … 147 149 protected override void ExportInstance(InstanceDescriptor descriptor) 148 150 { 149 var sound = SoundData.Read(descriptor );151 var sound = SoundData.Read(descriptor, do_pc_demo_test); 150 152 151 153 using (var stream = File.Create(Path.Combine(OutputDirPath, descriptor.FullName + ".wav"))) … … 162 164 var samplesPerBlock = 2 + (blockSizeADPCM - sound.ChannelCount * 7) * 8 / sound.ChannelCount / 4; 163 165 164 Int32 sampleCount = sampleCount = wholeBlocks * samplesPerBlock + leftoverSamples; 165 166 Int32 sampleCount = sampleCount = wholeBlocks * samplesPerBlock + leftoverSamples; 167 166 168 if (sound.IsIMA4) // IMA4 ADPCM format 167 169 { … … 170 172 sampleCount = (sound.Data.Length / blockSizeADPCM) * samplesPerBlock; 171 173 } 172 173 174 if (!convert_to_PCM) 174 175 { 175 176 if (sound.IsIMA4) 176 177 { 177 throw new NotSupportedException("Transcoding from Mac/demo ADPCM to PC ADPCMnot supported! Please use -extract:pcm");178 throw new NotSupportedException("Transcoding from IMA4 ADPCM (Mac) to MS ADPCM (PC) not supported! Please use -extract:pcm"); 178 179 } 179 180 var format = (byte[])formatTemplate_ADPCM.Clone(); … … 271 272 } 272 273 stepIndexL = headerLoL & 0x7f; 274 if (stepIndexL > 88) 275 Console.WriteLine("Block {0} (L): Initial IMA4 step index is {1}, clamping to 88.", block, stepIndexL); 276 ClampToRange(ref stepIndexL, 0, 88); 277 273 278 for (int b = 0; b < 32; b++) 274 279 { … … 291 296 } 292 297 stepIndexR = headerLoR & 0x7f; 298 if (stepIndexR > 88) 299 Console.WriteLine("Block {0} (R): Initial IMA4 step index is {1}, clamping to 88.", block, stepIndexR); 300 ClampToRange(ref stepIndexR, 0, 88); 293 301 294 302 for (int b = 0; b < 32; b++) … … 360 368 } 361 369 } 362 // read pair of nibbles 363 Byte nibbles = sound.Data[pos++]; 364 Byte nibbleHi = (Byte)(nibbles >> 4); 365 Byte nibbleLo = (Byte)(nibbles & 0xF); 366 samplesL[iSampleL++] = NibbletoSampleMSADPCM(ref sample1L, ref sample2L, ref deltaL, pred_indexL, nibbleHi); 367 if (sound.ChannelCount == 2) 368 samplesR[iSampleR++] = NibbletoSampleMSADPCM(ref sample1R, ref sample2R, ref deltaR, pred_indexR, nibbleLo); 369 else 370 samplesL[iSampleL++] = NibbletoSampleMSADPCM(ref sample1L, ref sample2L, ref deltaL, pred_indexL, nibbleLo); 370 else // read pair of nibbles 371 { 372 Byte nibbles = sound.Data[pos++]; 373 Byte nibbleHi = (Byte)(nibbles >> 4); 374 Byte nibbleLo = (Byte)(nibbles & 0xF); 375 samplesL[iSampleL++] = NibbletoSampleMSADPCM(ref sample1L, ref sample2L, ref deltaL, pred_indexL, nibbleHi); 376 if (sound.ChannelCount == 2) 377 samplesR[iSampleR++] = NibbletoSampleMSADPCM(ref sample1R, ref sample2R, ref deltaR, pred_indexR, nibbleLo); 378 else 379 samplesL[iSampleL++] = NibbletoSampleMSADPCM(ref sample1L, ref sample2L, ref deltaL, pred_indexL, nibbleLo); 380 } 371 381 } 372 382 }
Note:
See TracChangeset
for help on using the changeset viewer.