Terraria ModLoader  0.11.8.3
A mod to make and play Terraria mods
Terraria.ModLoader.Audio.MusicStreaming Class Referenceabstract
+ Inheritance diagram for Terraria.ModLoader.Audio.MusicStreaming:
+ Collaboration diagram for Terraria.ModLoader.Audio.MusicStreaming:

Public Member Functions

 MusicStreaming (string path)
 
override void CheckBuffer ()
 
void Dispose ()
 
override void Pause ()
 
override void Play ()
 
override void Resume ()
 
override void SetVariable (string name, float value)
 
override void Stop (AudioStopOptions options)
 
- Public Member Functions inherited from Terraria.ModLoader.Audio.Music
abstract void Reset ()
 

Public Attributes

override bool IsPaused => instance != null && instance.State == SoundState.Paused
 
override bool IsPlaying => instance != null && instance.State != SoundState.Stopped
 

Protected Member Functions

virtual void FillBuffer (byte[] buffer)
 
abstract void PrepareStream ()
 

Protected Attributes

AudioChannels channels
 
int sampleRate
 
Stream stream
 

Private Member Functions

void EnsureLoaded ()
 
void SubmitSingle ()
 

Private Attributes

byte[] buffer
 
const int bufferCountPerSubmit = 2
 
const int bufferLength = 4096
 
const int bufferMin = 4
 
DynamicSoundEffectInstance instance
 
string path
 

Additional Inherited Members

- Static Public Member Functions inherited from Terraria.ModLoader.Audio.Music
static implicit operator Music (Cue cue)
 
- Properties inherited from Terraria.ModLoader.Audio.Music
abstract bool IsPaused [get]
 
abstract bool IsPlaying [get]
 

Detailed Description

Definition at line 42 of file MusicWrappers.cs.

Constructor & Destructor Documentation

Terraria.ModLoader.Audio.MusicStreaming.MusicStreaming ( string  path)

Definition at line 63 of file MusicWrappers.cs.

63  {
64  this.path = path;
65  }

Member Function Documentation

override void Terraria.ModLoader.Audio.MusicStreaming.CheckBuffer ( )
virtual

Reimplemented from Terraria.ModLoader.Audio.Music.

Definition at line 112 of file MusicWrappers.cs.

112  {
113  if (!IsPlaying || instance.PendingBufferCount >= bufferMin)
114  return;
115 
116  for (int i = 0; i < bufferCountPerSubmit; i++)
117  SubmitSingle();
118  }
DynamicSoundEffectInstance instance
void Terraria.ModLoader.Audio.MusicStreaming.Dispose ( )

Definition at line 133 of file MusicWrappers.cs.

133  {
134  if (instance != null)
135  Stop(AudioStopOptions.Immediate);
136  }
override void Stop(AudioStopOptions options)
DynamicSoundEffectInstance instance
void Terraria.ModLoader.Audio.MusicStreaming.EnsureLoaded ( )
private

Definition at line 85 of file MusicWrappers.cs.

References Terraria.ModLoader.ModContent.OpenRead().

85  {
86  if (instance != null)
87  return;
88 
89  stream = ModContent.OpenRead(path, true);
90  PrepareStream();
91 
92  instance = new DynamicSoundEffectInstance(sampleRate, channels);
93  buffer = new byte[bufferLength]; // could use a buffer pool but swapping music isn't likely to thrash the GC too much
94 
95  CheckBuffer();
96  }
DynamicSoundEffectInstance instance

+ Here is the call graph for this function:

virtual void Terraria.ModLoader.Audio.MusicStreaming.FillBuffer ( byte[]  buffer)
protectedvirtual

Reimplemented in Terraria.ModLoader.Audio.MusicStreamingOGG.

Definition at line 125 of file MusicWrappers.cs.

125  {
126  int read = stream.Read(buffer, 0, buffer.Length);
127  if (read < buffer.Length) {
128  Reset();
129  stream.Read(buffer, read, buffer.Length - read);
130  }
131  }
override void Terraria.ModLoader.Audio.MusicStreaming.Pause ( )
virtual
override void Terraria.ModLoader.Audio.MusicStreaming.Play ( )
virtual

Implements Terraria.ModLoader.Audio.Music.

Definition at line 71 of file MusicWrappers.cs.

71  {
72  EnsureLoaded();
73  instance.Play();
74  }
DynamicSoundEffectInstance instance
abstract void Terraria.ModLoader.Audio.MusicStreaming.PrepareStream ( )
protectedpure virtual
override void Terraria.ModLoader.Audio.MusicStreaming.Resume ( )
virtual
override void Terraria.ModLoader.Audio.MusicStreaming.SetVariable ( string  name,
float  value 
)
virtual

Implements Terraria.ModLoader.Audio.Music.

Definition at line 76 of file MusicWrappers.cs.

76  {
77  switch (name) {
78  case "Volume": instance.Volume = value; return;
79  case "Pitch": instance.Pitch = value; return;
80  case "Pan": instance.Pan = value; return;
81  default: throw new Exception("Invalid field: '" + name + "'");
82  }
83  }
DynamicSoundEffectInstance instance
override void Terraria.ModLoader.Audio.MusicStreaming.Stop ( AudioStopOptions  options)
virtual

Implements Terraria.ModLoader.Audio.Music.

Reimplemented in Terraria.ModLoader.Audio.MusicStreamingOGG, and Terraria.ModLoader.Audio.MusicStreamingMP3.

Definition at line 100 of file MusicWrappers.cs.

100  {
101  instance.Stop();
102 
103  instance.Dispose();
104  instance = null;
105 
106  stream.Dispose();
107  stream = null;
108 
109  buffer = null;
110  }
DynamicSoundEffectInstance instance
void Terraria.ModLoader.Audio.MusicStreaming.SubmitSingle ( )
private

Definition at line 120 of file MusicWrappers.cs.

120  {
122  instance.SubmitBuffer(buffer);
123  }
DynamicSoundEffectInstance instance
virtual void FillBuffer(byte[] buffer)

Member Data Documentation

byte [] Terraria.ModLoader.Audio.MusicStreaming.buffer
private

Definition at line 58 of file MusicWrappers.cs.

const int Terraria.ModLoader.Audio.MusicStreaming.bufferCountPerSubmit = 2
private

Definition at line 49 of file MusicWrappers.cs.

const int Terraria.ModLoader.Audio.MusicStreaming.bufferLength = 4096
private

Definition at line 48 of file MusicWrappers.cs.

const int Terraria.ModLoader.Audio.MusicStreaming.bufferMin = 4
private

Definition at line 52 of file MusicWrappers.cs.

AudioChannels Terraria.ModLoader.Audio.MusicStreaming.channels
protected

Definition at line 61 of file MusicWrappers.cs.

DynamicSoundEffectInstance Terraria.ModLoader.Audio.MusicStreaming.instance
private

Definition at line 56 of file MusicWrappers.cs.

override bool Terraria.ModLoader.Audio.MusicStreaming.IsPaused => instance != null && instance.State == SoundState.Paused

Definition at line 67 of file MusicWrappers.cs.

override bool Terraria.ModLoader.Audio.MusicStreaming.IsPlaying => instance != null && instance.State != SoundState.Stopped

Definition at line 68 of file MusicWrappers.cs.

string Terraria.ModLoader.Audio.MusicStreaming.path
private

Definition at line 54 of file MusicWrappers.cs.

int Terraria.ModLoader.Audio.MusicStreaming.sampleRate
protected

Definition at line 60 of file MusicWrappers.cs.

Stream Terraria.ModLoader.Audio.MusicStreaming.stream
protected

Definition at line 57 of file MusicWrappers.cs.