
OpenAL EFX Reverb example
Posted Saturday, 14 March, 2009 - 00:09 by snocrash inHere is an example of how to create a reverb effect with OpenAL. This is a very useful effect for adding ambiance to an environment. For example a cave, large room, etc...
In order for it to work you need to add a sound file to your data/audio folder, and change the file name 'APACHE.wav' to the name of your sound.
using System; using System.Threading; using System.IO; using OpenTK.Audio; namespace Examples { public class ReverbExample { static readonly string filename = Path.Combine(Path.Combine("Data", "Audio"), "APACHE.wav"); public static void Main() { using (AudioContext context = new AudioContext()) using (AudioReader sound = new AudioReader(filename)) { Console.WriteLine("Testing WaveReader({0}).ReadToEnd()", filename); EffectsExtension EFX = new EffectsExtension(); int buffer = AL.GenBuffer(); int source = AL.GenSource(); int state; int[] slots = new int[1]; int[] effects = new int[1]; EFX.GenAuxiliaryEffectSlots(1, out slots[0]); EFX.BindEffect(effects[0], EfxEffectType.Reverb); EFX.Effect(effects[0], EfxEffectf.ReverbDecayTime, 3.0f); EFX.Effect(effects[0], EfxEffectf.ReverbDecayHFRatio, 0.91f); EFX.Effect(effects[0], EfxEffectf.ReverbDensity, 0.7f); EFX.Effect(effects[0], EfxEffectf.ReverbDiffusion, 0.9f); EFX.Effect(effects[0], EfxEffectf.ReverbRoomRolloffFactor, 3.1f); EFX.Effect(effects[0], EfxEffectf.ReverbReflectionsGain, 0.723f); EFX.Effect(effects[0], EfxEffectf.ReverbReflectionsDelay, 0.03f); EFX.Effect(effects[0], EfxEffectf.ReverbGain, 0.23f); EFX.AuxiliaryEffectSlot(slots[0], EfxAuxiliaryi.EffectslotEffect, effects[0]); AL.BufferData(buffer, sound.ReadToEnd()); AL.Source(source, ALSourcef.ConeOuterGain, 1.0f); AL.Source(source, ALSourcei.Buffer, buffer); AL.SourcePlay(source); Console.Write("Playing"); // Query the source to find out when it stops playing. do { Thread.Sleep(250); Console.Write("."); AL.GetSource(source, ALGetSourcei.SourceState, out state); } while ((ALSourceState)state == ALSourceState.Playing); Console.WriteLine(); AL.SourceStop(source); AL.DeleteSource(source); AL.DeleteBuffer(buffer); EFX.DeleteEffects(effects); EFX.DeleteAuxiliaryEffectSlots(slots); } } } }


Comments
Re: OpenAL EFX Reverb example
Thanks for the code, do you mind if I add it to Examples.exe?
Re: OpenAL EFX Reverb example
Please do. And more to come.
Re: OpenAL EFX Reverb example
Great, just committed to SVN.