Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
OGGAudioTrack.cs
Go to the documentation of this file.
2using System.IO;
3using Microsoft.Xna.Framework.Audio;
4using NVorbis;
5
6namespace Terraria.Audio;
7
9{
10 private VorbisReader _vorbisReader;
11
12 private int _loopStart;
13
14 private int _loopEnd;
15
17 {
18 //IL_0009: Unknown result type (might be due to invalid IL or missing references)
19 //IL_0013: Expected O, but got Unknown
20 _vorbisReader = new VorbisReader(streamToRead, true);
21 FindLoops();
22 CreateSoundEffect(_vorbisReader.SampleRate, (AudioChannels)_vorbisReader.Channels);
23 }
24
25 protected override void ReadAheadPutAChunkIntoTheBuffer()
26 {
29 }
30
31 private void PrepareBufferToSubmit()
32 {
35 VorbisReader vorbisReader = _vorbisReader;
36 int num = vorbisReader.ReadSamples(temporaryBuffer, 0, temporaryBuffer.Length);
37 bool num2 = _loopEnd > 0 && vorbisReader.DecodedPosition >= _loopEnd;
38 bool flag = num < temporaryBuffer.Length;
39 if (num2 || flag)
40 {
41 vorbisReader.DecodedPosition = _loopStart;
42 vorbisReader.ReadSamples(temporaryBuffer, num, temporaryBuffer.Length - num);
43 }
45 }
46
47 private static void ApplyTemporaryBufferTo(float[] temporaryBuffer, byte[] samplesBuffer)
48 {
49 for (int i = 0; i < temporaryBuffer.Length; i++)
50 {
51 short num = (short)(temporaryBuffer[i] * 32767f);
52 samplesBuffer[i * 2] = (byte)num;
53 samplesBuffer[i * 2 + 1] = (byte)(num >> 8);
54 }
55 }
56
57 public override void Reuse()
58 {
59 _vorbisReader.SeekTo(0L, SeekOrigin.Begin);
60 }
61
62 private void FindLoops()
63 {
65 TryReadingTag(all, "LOOPSTART", ref _loopStart);
66 TryReadingTag(all, "LOOPEND", ref _loopEnd);
67 }
68
69 private void TryReadingTag(IDictionary<string, IList<string>> tags, string entryName, ref int result)
70 {
71 if (tags.TryGetValue(entryName, out var value) && value.Count > 0 && int.TryParse(value[0], out var result2))
72 {
73 result = result2;
74 }
75 }
76
77 public override void Dispose()
78 {
79 _soundEffectInstance.Dispose();
80 _vorbisReader.Dispose();
81 }
82}
void CreateSoundEffect(int sampleRate, AudioChannels channels)
override void ReadAheadPutAChunkIntoTheBuffer()
static void ApplyTemporaryBufferTo(float[] temporaryBuffer, byte[] samplesBuffer)
OGGAudioTrack(Stream streamToRead)
void TryReadingTag(IDictionary< string, IList< string > > tags, string entryName, ref int result)