ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/OniSplit/Sound/SoundData.cs
Revision: 1114
Committed: Wed Jan 22 14:08:57 2020 UTC (5 years, 8 months ago) by iritscen
File size: 1376 byte(s)
Log Message:
Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace Oni.Sound
6 {
7 internal class SoundData
8 {
9 public int SampleRate;
10 public int ChannelCount;
11 public byte[] Data;
12
13 public static SoundData Read(InstanceDescriptor sndd)
14 {
15 if (sndd.Template.Tag != TemplateTag.SNDD)
16 throw new ArgumentException("descriptor");
17
18 var sound = new SoundData();
19
20 int dataSize;
21 int dataOffset;
22
23 using (var reader = sndd.OpenRead())
24 {
25 if (sndd.IsMacFile)
26 {
27 sound.ChannelCount = (reader.ReadInt32() >> 1) + 1;
28 sound.SampleRate = 22050;
29 reader.Skip(4);
30 }
31 else
32 {
33 reader.Skip(6);
34 sound.ChannelCount = reader.ReadInt16();
35 sound.SampleRate = reader.ReadInt32();
36 reader.Skip(44);
37 }
38
39 dataSize = reader.ReadInt32();
40 dataOffset = reader.ReadInt32();
41 }
42
43 using (var rawReader = sndd.GetRawReader(dataOffset))
44 sound.Data = rawReader.ReadBytes(dataSize);
45
46 return sound;
47 }
48 }
49 }