Terraria ModLoader  0.11.5
A framework for 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 41 of file MusicWrappers.cs.

Constructor & Destructor Documentation

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

Definition at line 62 of file MusicWrappers.cs.

62  {
63  this.path = path;
64  }

Member Function Documentation

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

Reimplemented from Terraria.ModLoader.Audio.Music.

Definition at line 111 of file MusicWrappers.cs.

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

Definition at line 132 of file MusicWrappers.cs.

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

Definition at line 84 of file MusicWrappers.cs.

References Terraria.ModLoader.ModContent.OpenRead().

84  {
85  if (instance != null)
86  return;
87 
88  stream = ModContent.OpenRead(path, true);
89  PrepareStream();
90 
91  instance = new DynamicSoundEffectInstance(sampleRate, channels);
92  buffer = new byte[bufferLength]; // could use a buffer pool but swapping music isn't likely to thrash the GC too much
93 
94  CheckBuffer();
95  }
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 124 of file MusicWrappers.cs.

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

Implements Terraria.ModLoader.Audio.Music.

Definition at line 70 of file MusicWrappers.cs.

70  {
71  EnsureLoaded();
72  instance.Play();
73  }
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 75 of file MusicWrappers.cs.

75  {
76  switch (name) {
77  case "Volume": instance.Volume = value; return;
78  case "Pitch": instance.Pitch = value; return;
79  case "Pan": instance.Pan = value; return;
80  default: throw new Exception("Invalid field: '" + name + "'");
81  }
82  }
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 99 of file MusicWrappers.cs.

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

Definition at line 119 of file MusicWrappers.cs.

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

Member Data Documentation

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

Definition at line 57 of file MusicWrappers.cs.

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

Definition at line 48 of file MusicWrappers.cs.

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

Definition at line 47 of file MusicWrappers.cs.

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

Definition at line 51 of file MusicWrappers.cs.

AudioChannels Terraria.ModLoader.Audio.MusicStreaming.channels
protected

Definition at line 60 of file MusicWrappers.cs.

DynamicSoundEffectInstance Terraria.ModLoader.Audio.MusicStreaming.instance
private

Definition at line 55 of file MusicWrappers.cs.

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

Definition at line 66 of file MusicWrappers.cs.

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

Definition at line 67 of file MusicWrappers.cs.

string Terraria.ModLoader.Audio.MusicStreaming.path
private

Definition at line 53 of file MusicWrappers.cs.

int Terraria.ModLoader.Audio.MusicStreaming.sampleRate
protected

Definition at line 59 of file MusicWrappers.cs.

Stream Terraria.ModLoader.Audio.MusicStreaming.stream
protected

Definition at line 56 of file MusicWrappers.cs.