source: OniSplit/Sound/AifImporter.cs@ 1127

Last change on this file since 1127 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: 1.5 KB
RevLine 
[1114]1using System;
2using System.IO;
3
4namespace Oni.Sound
5{
6 internal class AifImporter : Importer
7 {
8 private const int fcc_ima4 = 0x696d6134;
9 private static readonly byte[] sampleRate = new byte[10] { 0x40, 0x0d, 0xac, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
10
11 public AifImporter()
12 : base(InstanceFileHeader.OniMacTemplateChecksum)
13 {
14 }
15
16 public override void Import(string filePath, string outputDirPath)
17 {
18 var aif = AifFile.FromFile(filePath);
19
20 if (aif.Format != fcc_ima4)
21 {
22 Console.Error.WriteLine("Unsupported AIF compression (0x{0:X})", aif.Format);
23 return;
24 }
25
26 if (!Utils.ArrayEquals(aif.SampleRate, sampleRate))
27 {
28 Console.Error.WriteLine("Unsupported sample rate");
29 return;
30 }
31
32 if (aif.ChannelCount != 1 && aif.ChannelCount != 2)
33 {
34 Console.Error.WriteLine("Unsupported number of channels ({0})", aif.ChannelCount);
35 return;
36 }
37
38 BeginImport();
39 WriteSNDD(Path.GetFileNameWithoutExtension(filePath), aif);
40 Write(outputDirPath);
41 }
42
43 private void WriteSNDD(string name, AifFile aif)
44 {
45 int duration = (int)(aif.SampleFrames * 64.0f / 22050.0f * 60.0f);
46
47 var sndd = CreateInstance(TemplateTag.SNDD, name);
48
49 using (var writer = sndd.OpenWrite())
50 {
51 writer.Write((aif.ChannelCount == 1) ? 1 : 3);
52 writer.Write(duration);
53 writer.Write(aif.SoundData.Length);
54 writer.Write(WriteRawPart(aif.SoundData));
55 }
56 }
57 }
58}
Note: See TracBrowser for help on using the repository browser.