Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 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
 }
Exemplo n.º 3
0
        private void ReleaseUnmanagedResources()
        {
            if (_disposed)
            {
                return;
            }

            ALC10.alcMakeContextCurrent(MainContext.Handle);
            for (var i = 0; i < _buffers.Count; i++)
            {
                var buf = _buffers[i];
                AL10.alDeleteBuffers(_buffers.Count, ref buf);
            }
            _buffers.Clear();

            ALC10.alcMakeContextCurrent(IntPtr.Zero);
            foreach (var ctx in _contexts)
            {
                ctx.Destroy();
            }

            ALC10.alcCloseDevice(_handle);

            _disposed = true;
        }
Exemplo n.º 4
0
 internal void DestroyContext(AlContext ctx)
 {
     if (!_contexts.Remove(ctx))
     {
         throw new InvalidOperationException("Device does not own given context.");
     }
     ALC10.alcMakeContextCurrent(IntPtr.Zero);
     ctx.Destroy();
 }
Exemplo n.º 5
0
        /// <summary>
        /// Create an <see cref="AlStaticSource"/> for this context.
        /// </summary>
        public AlStaticSource CreateStaticSource()
        {
            ALC10.alcMakeContextCurrent(Handle);
            AL10.alGenSources(1, out var name);
            AlHelper.AlAlwaysCheckError("Call to alGenSources failed.");
            var source = new AlStaticSource(name, this);

            _sources.Add(source);
            return(source);
        }
Exemplo n.º 6
0
        protected override void Dispose(bool disposeManagedResources)
        {
            base.Dispose(disposeManagedResources);
            _sources.Clear();
            _files.Clear();


            ALC10.alcMakeContextCurrent(IntPtr.Zero);
            ALC10.alcDestroyContext(_context);
            ALC10.alcCloseDevice(_device);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Create a number of OpenAL buffers for this device.
 /// </summary>
 /// <param name="buffers">Array to fill with buffer names.</param>
 /// <param name="n">Number of buffers to generate.</param>
 public void CreateBuffers(uint[] buffers, int n)
 {
     CheckDisposed();
     ALC10.alcMakeContextCurrent(MainContext.Handle);
     AL10.alGenBuffers(n, buffers);
     AlHelper.AlAlwaysCheckError("Failed to generate buffers.");
     for (var i = 0; i < n; i++)
     {
         _buffers.Add(buffers[i]);
     }
 }
Exemplo n.º 8
0
        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!");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Delete a buffer.
        /// </summary>
        /// <param name="name">Name of the buffer.</param>
        /// <exception cref="InvalidOperationException">If the buffer is not owned by this device.</exception>
        public void DeleteBuffer(uint name)
        {
            CheckDisposed();

            if (!_buffers.Remove(name))
            {
                throw new InvalidOperationException("Device does not own given buffer.");
            }

            ALC10.alcMakeContextCurrent(MainContext.Handle);
            AL10.alDeleteBuffers(1, ref name);
            AlHelper.AlCheckError("alDeleteBuffers call failed.");
        }
Exemplo n.º 10
0
 public void Dispose()
 {
     ALC10.alcMakeContextCurrent(IntPtr.Zero);
     if (alContext != IntPtr.Zero)
     {
         ALC10.alcDestroyContext(alContext);
         alContext = IntPtr.Zero;
     }
     if (alDevice != IntPtr.Zero)
     {
         ALC10.alcCloseDevice(alDevice);
         alDevice = IntPtr.Zero;
     }
 }
Exemplo n.º 11
0
        public void Dispose()
        {
            if (_context != IntPtr.Zero)
            {
                ALC10.alcMakeContextCurrent(IntPtr.Zero); Check();
                ALC10.alcDestroyContext(_context); Check();
            }

            if (_device != IntPtr.Zero)
            {
                ALC10.alcCloseDevice(_device);
                Check();
            }
        }
Exemplo n.º 12
0
        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>();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Create an OpenAL buffer for this device.
        /// </summary>
        public uint CreateBuffer()
        {
            CheckDisposed();
            ALC10.alcMakeContextCurrent(MainContext.Handle);
            AL10.alGenBuffers(1, out var name);
            if (name == 0)
            {
                AlHelper.AlCheckError("alGenBuffer call failed.");
                throw new Exception("Failed to create buffer.");
            }

            _buffers.Add(name);
            return(name);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Delete a collection of buffers.
        /// </summary>
        /// <param name="buffers">Array to delete buffers from, starting at index 0.</param>
        /// <param name="n">Number of buffers to delete.</param>
        /// <remarks>
        /// Buffers that are not owned by this device are ignored.
        /// </remarks>
        /// <exception cref="IndexOutOfRangeException">
        /// If <paramref name="n"/> is larger than or equal to <code>buffers.Length</code>.
        /// </exception>
        public void DeleteBuffers(uint[] buffers, int n)
        {
            CheckDisposed();
            ALC10.alcMakeContextCurrent(MainContext.Handle);

            for (var i = 0; i < n; i++)
            {
                var buffer = buffers[i];
                if (_buffers.Remove(buffer))
                {
                    AL10.alDeleteBuffers(1, ref buffer);
                }
            }
            AlHelper.AlCheckError("alDeleteBuffers call failed.");
        }
Exemplo n.º 15
0
        void Dispose(bool disposing)
        {
            if (context != IntPtr.Zero)
            {
                ALC10.alcMakeContextCurrent(IntPtr.Zero);
                ALC10.alcDestroyContext(context);
                context = IntPtr.Zero;
            }

            if (device != IntPtr.Zero)
            {
                ALC10.alcCloseDevice(device);
                device = IntPtr.Zero;
            }
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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
                });
            }
        }
Exemplo n.º 18
0
        public void Dispose()
        {
            EFX.alDeleteFilters(1, ref INTERNAL_alFilter);

            ALC10.alcMakeContextCurrent(IntPtr.Zero);
            if (alContext != IntPtr.Zero)
            {
                ALC10.alcDestroyContext(alContext);
                alContext = IntPtr.Zero;
            }
            if (alDevice != IntPtr.Zero)
            {
                ALC10.alcCloseDevice(alDevice);
                alDevice = IntPtr.Zero;
            }
        }
Exemplo n.º 19
0
        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}.");
        }
Exemplo n.º 20
0
        void InnerDispose()
        {
            if (_disposed)
            {
                return;
            }

            if (_context != IntPtr.Zero)
            {
                ALC10.alcMakeContextCurrent(IntPtr.Zero); Check();
                ALC10.alcDestroyContext(_context); Check();
            }

            if (_device != IntPtr.Zero)
            {
                ALC10.alcCloseDevice(_device);
                Check();
            }

            _disposed = true;
        }
Exemplo n.º 21
0
        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>();
        }
Exemplo n.º 22
0
        public static void Shutdown()
        {
            // Destroy the sources
            AL10.alDeleteSources(MAX_SOURCE_COUNT, s_allSources);
            ALUtils.CheckALError("unable to free audio sources");
            s_availableSources.Clear();
            s_usedSources.Clear();

            // Destroy the context, and then close the device
            ALC10.alcMakeContextCurrent(IntPtr.Zero);
            ALUtils.CheckALCError();
            ALC10.alcDestroyContext(Context);
            ALUtils.CheckALCError();
            Context = IntPtr.Zero;
            ALC10.alcCloseDevice(Device);
            ALUtils.CheckALCError();
            Device = IntPtr.Zero;

            IsShutdown = true;

            // Report
            LINFO("Shutdown OpenAL audio engine.");
        }
Exemplo n.º 23
0
 internal void MakeCurrent()
 {
     ALC10.alcMakeContextCurrent(Handle);
 }