2using Microsoft.Xna.Framework.Audio;
12 public static implicit
operator Music(Cue cue) {
return new MusicCue() { cue = cue }; }
17 public abstract void Play();
19 public abstract void Stop(AudioStopOptions options);
30 public override void Pause() => cue.Pause();
31 public override void Play() => cue.Play();
32 public override void Resume() => cue.Resume();
33 public override void Stop(AudioStopOptions options) => cue.Stop(options);
34 public override void SetVariable(
string name,
float value) => cue.SetVariable(name, value);
37 cue.Stop(AudioStopOptions.Immediate);
38 cue = Main.soundBank.GetCue(cue.Name);
67 public override bool IsPaused =>
instance !=
null && instance.State == SoundState.Paused;
71 public override void Play() {
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 +
"'");
100 public override void Stop(AudioStopOptions options) {
127 if (read <
buffer.Length) {
135 Stop(AudioStopOptions.Immediate);
152 int chunkID = reader.ReadInt32();
153 int fileSize = reader.ReadInt32();
154 int riffType = reader.ReadInt32();
155 int fmtID = reader.ReadInt32();
156 int fmtSize = reader.ReadInt32();
157 int fmtCode = reader.ReadInt16();
158 channels = (AudioChannels)reader.ReadInt16();
160 int fmtAvgBPS = reader.ReadInt32();
161 int fmtBlockAlign = reader.ReadInt16();
162 int bitDepth = reader.ReadInt16();
166 int fmtExtraSize = reader.ReadInt16();
167 reader.ReadBytes(fmtExtraSize);
170 int dataID = reader.ReadInt32();
171 int dataSize = reader.ReadInt32();
190 var mp3Stream =
new MP3Stream(
stream);
192 channels = (AudioChannels)mp3Stream.ChannelCount;
196 public override void Stop(AudioStopOptions options) {
203 underlying.Position = 0;
225 string[] comments =
reader.Comments;
226 for (
int i = 0; i < comments.Length; i++) {
227 if (comments[i].StartsWith(
"LOOPSTART"))
228 int.TryParse(comments[i].Split(
'=')[1], out
loopStart);
229 else if (comments[i].StartsWith(
"LOOPEND"))
230 int.TryParse(comments[i].Split(
'=')[1], out
loopEnd);
247 public override void Stop(AudioStopOptions options) {
257 reader.DecodedPosition = 0;
261 for (
int i = 0; i <
floatBuf.Length; i++) {
262 short val = (short)(
floatBuf[i] *
short.MaxValue);
263 buffer[i * 2] = (byte)val;
264 buffer[i * 2 + 1] = (byte)(val >> 8);
override void Stop(AudioStopOptions options)
override void SetVariable(string name, float value)
abstract void Stop(AudioStopOptions options)
virtual void CheckBuffer()
abstract void SetVariable(string name, float value)
DynamicSoundEffectInstance instance
virtual void FillBuffer(byte[] buffer)
override void CheckBuffer()
abstract void PrepareStream()
MusicStreaming(string path)
const int bufferCountPerSubmit
override void SetVariable(string name, float value)
override void Stop(AudioStopOptions options)
override void Stop(AudioStopOptions options)
MusicStreamingMP3(string path)
override void PrepareStream()
override void Stop(AudioStopOptions options)
override void FillBuffer(byte[] buffer)
static void Convert(float[] floatBuf, byte[] buffer)
override void PrepareStream()
MusicStreamingOGG(string path)
MusicStreamingWAV(string path)
override void PrepareStream()
Manages content added by mods. Liasons between mod content and Terraria's arrays and oversees the Loa...
static Stream OpenRead(string assetName, bool newFileStream=false)