public SoundReversibleInstance CreateInstance(float volume, float pitch, float pan, bool inReverse = false) { SoundReversibleInstance newInstance = new SoundReversibleInstance(this, audioBytes, sampleRate, (AudioChannels)channels, inReverse); newInstance.Volume = volume; newInstance.Pitch = pitch; newInstance.Pan = pan; newInstance.IsReversed = inReverse; return newInstance; }
public static void Initialize() { registeredSounds = new HashSet<SoundReversibleInstance>(); soundsToUnregister = new List<SoundReversibleInstance>(); HasPlayedMap = new Dictionary<string, bool>(); currentMusicInstance = null; currentMusicName = null; targetVolume = DEFAULT_VOLUME; currentVolume = targetVolume; }
public static void UnregisterSoundInstance(SoundReversibleInstance instance) { soundsToUnregister.Add(instance); }
public static void StopMusic() { if (currentMusicInstance != null) { currentMusicInstance.Stop(); currentMusicInstance = null; currentMusicName = null; } }
public static void RegisterSoundInstance(SoundReversibleInstance instance) { registeredSounds.Add(instance); }
public static void PlaySoundAsMusic(string soundName) { if (soundName == currentMusicName) return; else if (soundName == null) { currentMusicInstance.Stop(); currentMusicInstance = null; return; } if (SoundMap.ContainsKey(soundName)) { if (currentMusicInstance != null) { if (soundName == currentMusicName) { if (currentMusicInstance.IsDisposed || currentMusicInstance.State == SoundState.Stopped) currentMusicInstance.Play(); } else { currentMusicInstance.Stop(); SoundReversibleInstance instance = SoundMap[soundName].CreateInstance(); instance.IsLooped = true; instance.Volume = musicMasterVolume * currentVolume; instance.Play(); currentMusicInstance = instance; currentMusicName = soundName; HasPlayedMap[soundName] = true; } } else { SoundReversibleInstance instance = SoundMap[soundName].CreateInstance(); instance.IsLooped = true; instance.Volume = musicMasterVolume * currentVolume; instance.Play(); currentMusicInstance = instance; currentMusicName = soundName; HasPlayedMap[soundName] = true; } } }