public OpenALDevice() { string envDevice = Environment.GetEnvironmentVariable("FNA_AUDIO_DEVICE_NAME"); if (String.IsNullOrEmpty(envDevice)) { /* Be sure ALC won't explode if the variable doesn't exist. * But, fail if the device name is wrong. The user needs to know * if their environment variable was incorrect. * -flibit */ envDevice = String.Empty; } alDevice = ALC10.alcOpenDevice(envDevice); if (CheckALCError() || alDevice == IntPtr.Zero) { throw new InvalidOperationException("Could not open audio device!"); } int[] attribute = new int[0]; alContext = ALC10.alcCreateContext(alDevice, attribute); if (CheckALCError() || alContext == IntPtr.Zero) { Dispose(); throw new InvalidOperationException("Could not create OpenAL context"); } ALC10.alcMakeContextCurrent(alContext); if (CheckALCError()) { Dispose(); throw new InvalidOperationException("Could not make OpenAL context current"); } float[] ori = new float[] { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }; AL10.alListenerfv(AL10.AL_ORIENTATION, ori); AL10.alListener3f(AL10.AL_POSITION, 0.0f, 0.0f, 0.0f); AL10.alListener3f(AL10.AL_VELOCITY, 0.0f, 0.0f, 0.0f); AL10.alListenerf(AL10.AL_GAIN, 1.0f); // We do NOT use automatic attenuation! XNA does not do this! AL10.alDistanceModel(AL10.AL_NONE); EFX.alGenFilters(1, out INTERNAL_alFilter); }
private OpenALDevice() { alDevice = ALC10.alcOpenDevice(string.Empty); if (CheckALCError("Could not open AL device") || alDevice == IntPtr.Zero) { throw new Exception("Could not open audio device!"); } int[] attribute = new int[0]; alContext = ALC10.alcCreateContext(alDevice, attribute); if (CheckALCError("Could not create OpenAL context") || alContext == IntPtr.Zero) { Dispose(); throw new Exception("Could not create OpenAL context"); } ALC10.alcMakeContextCurrent(alContext); if (CheckALCError("Could not make OpenAL context current")) { Dispose(); throw new Exception("Could not make OpenAL context current"); } float[] ori = new float[] { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }; AL10.alListenerfv(AL10.AL_ORIENTATION, ori); AL10.alListener3f(AL10.AL_POSITION, 0.0f, 0.0f, 0.0f); AL10.alListener3f(AL10.AL_VELOCITY, 0.0f, 0.0f, 0.0f); AL10.alListenerf(AL10.AL_GAIN, 1.0f); // We do NOT use automatic attenuation! XNA does not do this! AL10.alDistanceModel(AL10.AL_NONE); instancePool = new List <SoundEffectInstance>(); dynamicInstancePool = new List <DynamicSoundEffectInstance>(); }