public static audioData GetSound(string name, bool cache = true) { if (Soundcache.ContainsKey(name)) { return(Soundcache[name]); } try { int channels, bits_per_sample, sample_rate; byte[] sound_data = s_audio.LoadWave(filesystem.Open(name + ".wav"), out channels, out bits_per_sample, out sample_rate); audioData data = new audioData { loaded = true, channels = channels, bits_per_sample = bits_per_sample, sample_rate = sample_rate, data = sound_data, sound_format = s_audio.GetSoundFormat(channels, bits_per_sample) }; if (cache) { Soundcache.Add(name, data); } return(data); } catch { log.WriteLine("failed to load sound file: \"" + name + "\"", log.LogMessageType.Error); return(new audioData { loaded = false }); } }
public void PlaySFX(string name) { if (s_audio.noSound) { return; } Stop(); AL.DeleteBuffer(buffer); buffer = AL.GenBuffer(); audioData data = cache.GetSound(name); if (!data.loaded) { log.WriteLine("audio file not loaded (" + name + ")"); return; } AL.BufferData(buffer, data.sound_format, data.data, data.data.Length, data.sample_rate); AL.Source(s_audio.source, ALSourcei.Buffer, buffer); AL.SourcePlay(s_audio.source); log.WriteLine("playing sfx (" + name + ")"); }