source: OniSplit/Sound/AifExporter.cs@ 1131

Last change on this file since 1131 was 1131, checked in by geyser, 4 years ago

Yay, another SNDD fix that no one cares about: PC demo SNDDs! (short .dat headers, but the .raw data is MS ADPCM; use -nodemo to treat as Mac/IMA4 anyway).

File size: 2.5 KB
Line 
1using System;
2using System.IO;
3
4namespace Oni.Sound
5{
6 internal class AifExporter : SoundExporter
7 {
8 #region Private data
9 private bool do_pc_demo_test;
10
11 private const int fcc_FORM = 0x464f524d;
12 private const int fcc_AIFC = 0x41494643;
13 private const int fcc_COMM = 0x434f4d4d;
14 private const int fcc_ima4 = 0x696d6134;
15 private const int fcc_SSND = 0x53534e44;
16
17 private static readonly byte[] sampleRate = new byte[10]
18 {
19 0x40, 0x0d, 0xac, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
20 };
21
22 #endregion
23
24 public AifExporter(InstanceFileManager fileManager, string outputDirPath, bool noDemo = false)
25 : base(fileManager, outputDirPath)
26 {
27 do_pc_demo_test = !noDemo;
28 }
29
30 protected override void ExportInstance(InstanceDescriptor descriptor)
31 {
32 var sound = SoundData.Read(descriptor, do_pc_demo_test);
33
34 using (var stream = File.Create(Path.Combine(OutputDirPath, descriptor.FullName + ".aif")))
35 using (var writer = new BinaryWriter(stream))
36 {
37 if (!(sound.IsIMA4))
38 {
39 throw new NotSupportedException("Transcoding from MS ADPCM (PC) to IMA4 ADPCM (Mac) not supported!");
40 }
41 writer.Write(Utils.ByteSwap(fcc_FORM));
42 writer.Write(Utils.ByteSwap(50 + sound.Data.Length));
43 writer.Write(Utils.ByteSwap(fcc_AIFC));
44
45 //
46 // write COMM chunk
47 //
48
49 writer.Write(Utils.ByteSwap(fcc_COMM));
50 writer.Write(Utils.ByteSwap(22)); // chunk size
51 writer.Write(Utils.ByteSwap((short)sound.ChannelCount));
52 writer.Write(Utils.ByteSwap(sound.Data.Length / (sound.ChannelCount * 34))); // numSampleFrames
53 writer.Write(Utils.ByteSwap((short)16)); // sampleSize
54 writer.Write(sampleRate); // sampleRate
55 writer.Write(Utils.ByteSwap(fcc_ima4));
56
57 //
58 // write SSND chunk
59 //
60
61 writer.Write(Utils.ByteSwap(fcc_SSND));
62 writer.Write(Utils.ByteSwap(8 + sound.Data.Length)); // chunk size
63 writer.Write(0);
64 writer.Write(0);
65 writer.Write(sound.Data);
66 }
67 }
68
69 }
70}
Note: See TracBrowser for help on using the repository browser.