Example #1
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
 }
Example #2
0
        internal static void AlAlwaysCheckError(string message = "")
        {
            var error = AL10.alGetError();

            if (error != AL10.AL_NO_ERROR)
            {
                throw new InvalidOperationException(message + $" ({error})");
            }
        }
Example #3
0
        internal static void alCheckError()
        {
            int error;

            error = AL10.alGetError();

            if (error != AL10.AL_NO_ERROR)
            {
                throw new InvalidOperationException("AL error!");
            }
        }
Example #4
0
        private void CheckALError()
        {
            int err = AL10.alGetError();

            if (err == AL10.AL_NO_ERROR)
            {
                return;
            }

            System.Console.WriteLine("OpenAL Error: {0:X}", err);
        }
Example #5
0
        private void CheckALError()
        {
            int err = AL10.alGetError();

            if (err == AL10.AL_NO_ERROR)
            {
                return;
            }

            System.Console.WriteLine("OpenAL Error: " + err.ToString());
        }
Example #6
0
 public static void CheckALError(
     string message = null,
     [CallerMemberName] string name = "",
     [CallerLineNumber] int line    = 0
     )
 {
     LastALError = AL10.alGetError();
     if (LastALError != AL10.AL_NO_ERROR)
     {
         string error = GetALErrorString(LastALError);
         throw new AudioException($"AL Error ({LastALError}) at [{name}:{line}]: {error} {(String.IsNullOrWhiteSpace(message) ? "" : $"({message})")}");
     }
Example #7
0
        private void CheckALError()
        {
            int err = AL10.alGetError();

            if (err == AL10.AL_NO_ERROR)
            {
                return;
            }

            FNALoggerEXT.LogError("OpenAL Error: " + err.ToString("X4"));
#if VERBOSE_AL_DEBUGGING
            throw new InvalidOperationException("OpenAL Error!");
#endif
        }
Example #8
0
        private void CheckALError()
        {
            int err = AL10.alGetError();

            if (err == AL10.AL_NO_ERROR)
            {
                return;
            }

            System.Console.WriteLine("OpenAL Error: {0:X}", err);
#if VERBOSE_AL_DEBUGGING
            throw new InvalidOperationException("OpenAL Error!");
#endif
        }
Example #9
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
                });
            }
        }
Example #10
0
        protected static void Check()
        {
            int error = AL10.alGetError();

            switch (error)
            {
            case AL10.AL_NO_ERROR: return;

            case AL10.AL_INVALID_NAME: throw new AudioException("a bad name (ID) was passed to an OpenAL function");

            case AL10.AL_INVALID_VALUE: throw new AudioException("an invalid value was passed to an OpenAL function");

            case AL10.AL_INVALID_OPERATION: throw new AudioException("the requested operation is not valid");

            case AL10.AL_OUT_OF_MEMORY: throw new AudioException("the requested operation resulted in OpenAL running out of memory");
            }
        }
Example #11
0
        static string[] QueryDevices(string label, int type)
        {
            // Clear error bit
            AL10.alGetError();

            // Returns a null separated list of strings, terminated by two nulls.
            var devicesPtr = ALC10.alcGetString(IntPtr.Zero, type);

            if (devicesPtr == IntPtr.Zero || AL10.alGetError() != AL10.AL_NO_ERROR)
            {
                Log.Write("sound", "Failed to query OpenAL device list using {0}", label);
                return(new string[0]);
            }

            var devices = new List <string>();
            var buffer  = new List <byte>();
            var offset  = 0;

            while (true)
            {
                var b = Marshal.ReadByte(devicesPtr, offset++);
                if (b != 0)
                {
                    buffer.Add(b);
                    continue;
                }

                // A null indicates termination of that string, so add that to our list.
                devices.Add(Encoding.UTF8.GetString(buffer.ToArray()));
                buffer.Clear();

                // Two successive nulls indicates the end of the list.
                if (Marshal.ReadByte(devicesPtr, offset) == 0)
                {
                    break;
                }
            }

            return(devices.ToArray());
        }
Example #12
0
        static string[] QueryDevices(string label, int type)
        {
            // Clear error bit
            AL10.alGetError();

            var devices = new List <string>();
            var next    = ALC10.alcGetString(IntPtr.Zero, type);

            if (next == IntPtr.Zero || AL10.alGetError() != AL10.AL_NO_ERROR)
            {
                Log.Write("sound", "Failed to query OpenAL device list using {0}", label);
                return(new string[] { });
            }

            do
            {
                var str = Marshal.PtrToStringAuto(next);
                next += UnicodeEncoding.Default.GetByteCount(str) + 1;
                devices.Add(str);
            } while (Marshal.ReadByte(next) != 0);

            return(devices.ToArray());
        }
Example #13
0
 // Simply clears any AL error without reporting it
 public static void ClearALError()
 {
     AL10.alGetError();
 }