Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WAVAudioTrack.cs
Go to the documentation of this file.
1using System.IO;
2using Microsoft.Xna.Framework.Audio;
3
4namespace Terraria.Audio;
5
7{
8 private long _streamContentStartIndex = -1L;
9
10 private Stream _stream;
11
12 private const uint JUNK = 1263424842u;
13
14 private const uint FMT = 544501094u;
15
16 public WAVAudioTrack(Stream stream)
17 {
18 _stream = stream;
19 BinaryReader binaryReader = new BinaryReader(stream);
20 binaryReader.ReadInt32();
21 binaryReader.ReadInt32();
22 binaryReader.ReadInt32();
23 AudioChannels channels = AudioChannels.Mono;
24 uint sampleRate = 0u;
25 bool flag = false;
26 int num = 0;
27 while (!flag && num < 10)
28 {
29 uint num2 = binaryReader.ReadUInt32();
30 int chunkSize = binaryReader.ReadInt32();
31 switch (num2)
32 {
33 case 1263424842u:
34 SkipJunk(binaryReader, chunkSize);
35 break;
36 case 544501094u:
37 binaryReader.ReadInt16();
38 channels = (AudioChannels)binaryReader.ReadUInt16();
39 sampleRate = binaryReader.ReadUInt32();
40 binaryReader.ReadInt32();
41 binaryReader.ReadInt16();
42 binaryReader.ReadInt16();
43 flag = true;
44 break;
45 }
46 if (!flag)
47 {
48 num++;
49 }
50 }
51 binaryReader.ReadInt32();
52 binaryReader.ReadInt32();
53 _streamContentStartIndex = stream.Position;
54 CreateSoundEffect((int)sampleRate, channels);
55 }
56
57 private static void SkipJunk(BinaryReader reader, int chunkSize)
58 {
59 int num = chunkSize;
60 if (num % 2 != 0)
61 {
62 num++;
63 }
64 reader.ReadBytes(num);
65 }
66
67 protected override void ReadAheadPutAChunkIntoTheBuffer()
68 {
69 byte[] bufferToSubmit = _bufferToSubmit;
70 if (_stream.Read(bufferToSubmit, 0, bufferToSubmit.Length) < 1)
71 {
72 Stop(AudioStopOptions.Immediate);
73 }
74 else
75 {
77 }
78 }
79
80 public override void Reuse()
81 {
82 _stream.Position = _streamContentStartIndex;
83 }
84
85 public override void Dispose()
86 {
87 _soundEffectInstance.Dispose();
89 }
90}
virtual ushort ReadUInt16()
virtual int ReadInt32()
virtual short ReadInt16()
virtual byte[] ReadBytes(int count)
virtual uint ReadUInt32()
int Read(byte[] buffer, int offset, int count)
void Dispose()
Definition Stream.cs:639
void CreateSoundEffect(int sampleRate, AudioChannels channels)
override void ReadAheadPutAChunkIntoTheBuffer()
static void SkipJunk(BinaryReader reader, int chunkSize)