source: OniSplit/Sound/AifExporter.cs@ 1122

Last change on this file since 1122 was 1114, checked in by iritscen, 5 years ago

Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

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