source: OniSplit/Sound/SoundData.cs@ 1126

Last change on this file since 1126 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.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace 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}
Note: See TracBrowser for help on using the repository browser.