public AudioDevice() { _device = ALC10.alcOpenDevice(null); Check(); _context = ALC10.alcCreateContext(_device, new int[0]); Check(); ALC10.alcMakeContextCurrent(_context); Check(); AL10.alGetError(); // Clear error code for subsequent callers }
public AudioSystem(Game game) : base(game) { _device = ALC10.alcOpenDevice(""); alcCheckError(); _context = ALC10.alcCreateContext(_device, null); alcCheckError(); ALC10.alcMakeContextCurrent(_context); alcCheckError(); _sources = new List <AudioSource>(); _files = new Dictionary <string, AudioBuffer>(); switch (game.ContentManager.SageGame) { case SageGame.Ra3: case SageGame.Ra3Uprising: case SageGame.Cnc4: // TODO break; default: game.ContentManager.IniDataContext.LoadIniFile(@"Data\INI\AudioSettings.ini"); game.ContentManager.IniDataContext.LoadIniFile(@"Data\INI\SoundEffects.ini"); game.ContentManager.IniDataContext.LoadIniFile(@"Data\INI\MiscAudio.ini"); break; } _settings = game.ContentManager.IniDataContext.AudioSettings; }
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); EFX.alGenFilters(1, out INTERNAL_alFilter); // FIXME: Remove for FNA 16.11! -flibit if (!AL10.alIsExtensionPresent("AL_SOFT_gain_clamp_ex")) { FNALoggerEXT.LogWarn("AL_SOFT_gain_clamp_ex not found!"); FNALoggerEXT.LogWarn("Update your OpenAL Soft library!"); } }
public AudioSystem(Game game) : base(game) { _device = ALC10.alcOpenDevice(""); alcCheckError(); _context = ALC10.alcCreateContext(_device, null); alcCheckError(); ALC10.alcMakeContextCurrent(_context); alcCheckError(); _sources = new List <AudioSource>(); _files = new Dictionary <string, AudioBuffer>(); }
public OpenAlSoundEngine() { Console.WriteLine("Using OpenAL sound engine"); if (Game.Settings.Sound.Device != null) { Console.WriteLine("Using device `{0}`", Game.Settings.Sound.Device); } else { Console.WriteLine("Using default device"); } device = ALC10.alcOpenDevice(Game.Settings.Sound.Device); if (device == IntPtr.Zero) { Console.WriteLine("Failed to open device. Falling back to default"); device = ALC10.alcOpenDevice(null); if (device == IntPtr.Zero) { throw new InvalidOperationException("Can't create OpenAL device"); } } var ctx = ALC10.alcCreateContext(device, null); if (ctx == IntPtr.Zero) { throw new InvalidOperationException("Can't create OpenAL context"); } ALC10.alcMakeContextCurrent(ctx); for (var i = 0; i < PoolSize; i++) { var source = 0U; AL10.alGenSources(new IntPtr(1), out source); if (AL10.alGetError() != AL10.AL_NO_ERROR) { Log.Write("sound", "Failed generating OpenAL source {0}", i); return; } sourcePool.Add(source, new PoolSlot() { IsActive = false }); } }
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); }
public static void Initialize() { // Populate the device lists PlaybackDevice.PopulateDeviceList(); if (PlaybackDevice.Devices.Count == 0) { throw new AudioException("There are no audio playback devices available"); } LDEBUG("Available audio playback devices:"); foreach (var dev in PlaybackDevice.Devices) { LDEBUG($" {dev.Identifier}"); } // Open the default playback device Device = ALC10.alcOpenDevice(PlaybackDevice.Devices[0].Identifier); ALUtils.CheckALCError(); if (Device == IntPtr.Zero) { throw new AudioException("Unable to open default audio playback device"); } // Create the al context and set it as active Context = ALC10.alcCreateContext(Device, new int[2] { 0, 0 }); // Two 0s tell OpenAL no special attribs ALUtils.CheckALCError(); if (Context == IntPtr.Zero) { throw new AudioException("Unable to create audio context"); } ALC10.alcMakeContextCurrent(Context); ALUtils.CheckALCError(); // Generate audio sources AL10.alGenSources(MAX_SOURCE_COUNT, s_allSources); ALUtils.CheckALError("unable to generate audio sources"); foreach (var src in s_allSources) { s_availableSources.Push(src); } // Report LINFO("Started OpenAL audio engine."); LINFO($" Device: {PlaybackDevice.Devices[0].Identifier}."); }
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>(); }
/// <summary> /// Create a managed wrapper for the specified audio playback device. /// Available devices can be queried with <see cref="GetDevices"/>. /// </summary> /// <param name="deviceName">Name of the device.</param> /// <exception cref="Exception">If opening the device or creating the context fails.</exception> private AlDevice(string deviceName) { Name = deviceName ?? DefaultDeviceName; _handle = ALC10.alcOpenDevice(deviceName); if (_handle == IntPtr.Zero) { throw new Exception("Failed to open device."); } _contexts = new List <AlContext>(); _buffers = new List <uint>(); var ctxHandle = ALC10.alcCreateContext(_handle, new int[0]); if (ctxHandle == IntPtr.Zero) { ALC10.alcCloseDevice(_handle); throw new Exception("Failed to create context."); } var ctx = new AlContext(this, ctxHandle); _contexts.Add(ctx); }