public OggVorbisFile(string name, string filepath, Sound soundType) { Name = name; string cachefile = SystemInfo.DecodedMusicCache + SystemInfo.PathSeparator.ToString () + soundType.ToString () + "_" + name.GetHashCode ().ToString () + ".wav"; Log.BlockList (id: 33, before: " - ", after: "", begin: "Load ogg audio files:", end: ""); Log.BlockList (id: 34, before: " - ", after: "", begin: "Decode ogg audio files:", end: ""); byte[] data; try { Log.ListElement (33, "[", soundType, "] ", name); data = File.ReadAllBytes (cachefile); } catch (Exception) { Log.ListElement (34, "[", soundType, "] ", name); OggDecoder decoder = new OggDecoder (); decoder.Initialize (TitleContainer.OpenStream (filepath)); data = decoder.SelectMany (chunk => chunk.Bytes.Take (chunk.Length)).ToArray (); using (MemoryStream stream = new MemoryStream ()) using (BinaryWriter writer = new BinaryWriter (stream)) { WriteWave (writer, decoder.Stereo ? 2 : 1, decoder.SampleRate, data); stream.Position = 0; data = stream.ToArray (); } File.WriteAllBytes (cachefile, data); } using (MemoryStream stream = new MemoryStream (data)) { stream.Position = 0; SoundEffect soundEffect = SoundEffect.FromStream (stream); internalFile = new SoundEffectFile (name, soundEffect, soundType); } }
public void Play(Sound sound) { sounds[sound.ToString()].Play(); }
private void Load(Sound sound) { string file = Utils.GetCurrentDirectory() + "\\Data\\Sound\\" + sound.ToString() + ".wav"; this.sound = Utils.LoadSound(file); soundInstance = this.sound.CreateInstance(); }
public static void SetVolume(Sound soundType, float volume) { volume = ValidVolume (volume); VolumeMap [soundType] = volume; Config.Default ["volume", soundType.ToString (), 1] = volume; Log.Debug ("Set Volume (", soundType, "): ", volume); }