// Plays the sound public void Play(string key) { if (!this.sounds.ContainsKey(key)) { return; } MyWave w = this.sounds[key]; var sourceVoice = new SourceVoice(this.xaudio, w.WaveFormat); sourceVoice.SubmitSourceBuffer(w.Buffer, w.DecodedPacketsInfo); sourceVoice.Start(); }
// Reads a sound and puts it in the dictionary public AudioBuffer AddWave(string key, string filepath) { MyWave wave = new MyWave(); var nativeFileStream = new NativeFileStream(filepath, NativeFileMode.Open, NativeFileAccess.Read, NativeFileShare.Read); var soundStream = new SoundStream(nativeFileStream); var buffer = new AudioBuffer() { Stream = soundStream, AudioBytes = (int)soundStream.Length, Flags = SharpDX.XAudio2.BufferFlags.EndOfStream }; wave.Buffer = buffer; wave.DecodedPacketsInfo = soundStream.DecodedPacketsInfo; wave.WaveFormat = soundStream.Format; this.sounds.Add(key, wave); return(buffer); }