Ejemplo n.º 1
0
        // Converts an error code to an error string with additional information.
        string ErrorMessage(string devicename, int frequency, ALFormat bufferformat, int buffersize)
        {
            string   alcerrmsg;
            AlcError alcerrcode = CurrentError;

            switch (alcerrcode)
            {
            case AlcError.OutOfMemory:
                alcerrmsg = alcerrcode.ToString() + ": The specified device is invalid, or can not capture audio.";
                break;

            case AlcError.InvalidValue:
                alcerrmsg = alcerrcode.ToString() + ": One of the parameters has an invalid value.";
                break;

            default:
                alcerrmsg = alcerrcode.ToString();
                break;
            }
            return("The handle returned by Alc.CaptureOpenDevice is null." +
                   "\nAlc Error: " + alcerrmsg +
                   "\nDevice Name: " + devicename +
                   "\nCapture frequency: " + frequency +
                   "\nBuffer format: " + bufferformat +
                   "\nBuffer Size: " + buffersize);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets for the latest OpenAL Error.
        /// </summary>
        /// <returns>Latest OpenAL Error.</returns>
        internal static AlcError GetError(AudioCapture device)
        {
            AlcError errorCode = device.CurrentError;

            LastError = errorCode;

            return(errorCode);
        }
Ejemplo n.º 3
0
        private void method_1()
        {
            AlcError alcError = OpenAL.alcGetError(this.intptr_0);

            if (alcError != AlcError.NoError)
            {
                throw new Exception3(alcError.ToString());
            }
        }
        private void CheckRecorderError(string location)
        {
            AlcError err = r.CurrentError;

            if (err != AlcError.NoError)
            {
                Errorlist.Add(location, err);
            }
        }
Ejemplo n.º 5
0
        static void CheckContextErrors()
        {
            AlcError err = AL.alcGetError(device);

            if (err == AlcError.NoError)
            {
                return;
            }
            throw new AudioException("Error " + err + " when creating OpenAL context");
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="operation"></param>
        /// <returns></returns>
        public bool CheckALError(string operation)
        {
            _lastOpenALError = Alc.GetError(_device);

            if (_lastOpenALError == AlcError.NoError)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 7
0
        private bool CheckALCError(string message)
        {
            AlcError err = Alc.GetError(alDevice);

            if (err == AlcError.NoError)
            {
                return(false);
            }

            throw new Exception(message + " - OpenAL Device Error: " + err.ToString());
        }
Ejemplo n.º 8
0
        // --- initialization and deinitialization ---

        /// <summary>Initializes audio. A call to Deinitialize must be made when terminating the program.</summary>
        /// <returns>Whether initializing audio was successful.</returns>
        internal static bool Initialize()
        {
            Deinitialize();
            switch (Options.Current.SoundRange)
            {
            case SoundRange.Low:
                OuterRadiusFactorMinimum      = 2.0;
                OuterRadiusFactorMaximum      = 8.0;
                OuterRadiusFactorMaximumSpeed = 1.0;
                break;

            case SoundRange.Medium:
                OuterRadiusFactorMinimum      = 4.0;
                OuterRadiusFactorMaximum      = 16.0;
                OuterRadiusFactorMaximumSpeed = 2.0;
                break;

            case SoundRange.High:
                OuterRadiusFactorMinimum      = 6.0;
                OuterRadiusFactorMaximum      = 24.0;
                OuterRadiusFactorMaximumSpeed = 3.0;
                break;
            }
            OuterRadiusFactor      = Math.Sqrt(OuterRadiusFactorMinimum * OuterRadiusFactorMaximum);
            OuterRadiusFactorSpeed = 0.0;
            OpenAlDevice           = Alc.OpenDevice(null);
            if (OpenAlDevice != IntPtr.Zero)
            {
                OpenAlContext = Alc.CreateContext(OpenAlDevice, new int[0]);
                if (OpenAlContext != ContextHandle.Zero)
                {
                    Alc.MakeContextCurrent(OpenAlContext);
                    try {
                        AL.SpeedOfSound(343.0f);
                    } catch {
                        Debug.AddMessage(Debug.MessageType.Error, false, "OpenAL 1.1 is required. You seem to have OpenAL 1.0.");
                    }
                    AL.DistanceModel(ALDistanceModel.None);
                    return(true);
                }
                AlcError error = Alc.GetError(OpenAlDevice);
                Alc.CloseDevice(OpenAlDevice);
                OpenAlDevice = IntPtr.Zero;
                Debug.AddMessage(Debug.MessageType.Error, false, "The OpenAL context could not be created: " + error);
                return(false);
            }
            ALError devError = AL.GetError();

            OpenAlContext = ContextHandle.Zero;
            Debug.AddMessage(Debug.MessageType.Error, false, "The OpenAL sound device could not be opened: " + AL.GetErrorString(devError));
            return(false);
        }
Ejemplo n.º 9
0
        private bool CheckALCError(string message)
        {
            bool     retVal = false;
            AlcError err    = Alc.GetError(alDevice);

            if (err != AlcError.NoError)
            {
                System.Console.WriteLine("OpenAL Error: " + err.ToString());
                retVal = true;
            }

            return(retVal);
        }
Ejemplo n.º 10
0
        private bool CheckALCError(string message)
        {
            AlcError err = Alc.GetError(_device);

            if (err == AlcError.NoError)
            {
                return(false);
            }

            System.Console.WriteLine(message + " - OpenAL Device Error: " + err);

            return(true);
        }
Ejemplo n.º 11
0
        private VoipCapture(string deviceName) : base(GameMain.Client?.ID ?? 0, true, false)
        {
            VoipConfig.SetupEncoding();

            //set up capture device
            captureDevice = Alc.CaptureOpenDevice(deviceName, VoipConfig.FREQUENCY, ALFormat.Mono16, VoipConfig.BUFFER_SIZE * 5);

            if (captureDevice == IntPtr.Zero)
            {
                if (!GUIMessageBox.MessageBoxes.Any(mb => mb.UserData as string == "capturedevicenotfound"))
                {
                    GUI.SettingsMenuOpen = false;
                    new GUIMessageBox(TextManager.Get("Error"),
                                      TextManager.Get("VoipCaptureDeviceNotFound", returnNull: true) ?? "Could not start voice capture, suitable capture device not found.")
                    {
                        UserData = "capturedevicenotfound"
                    };
                }
                GameMain.Config.VoiceSetting = GameSettings.VoiceMode.Disabled;
                Instance?.Dispose();
                Instance = null;
                return;
            }

            ALError  alError  = AL.GetError();
            AlcError alcError = Alc.GetError(captureDevice);

            if (alcError != AlcError.NoError)
            {
                throw new Exception("Failed to open capture device: " + alcError.ToString() + " (ALC)");
            }
            if (alError != ALError.NoError)
            {
                throw new Exception("Failed to open capture device: " + alError.ToString() + " (AL)");
            }

            Alc.CaptureStart(captureDevice);
            alcError = Alc.GetError(captureDevice);
            if (alcError != AlcError.NoError)
            {
                throw new Exception("Failed to start capturing: " + alcError.ToString());
            }

            capturing     = true;
            captureThread = new Thread(UpdateCapture)
            {
                IsBackground = true,
                Name         = "VoipCapture"
            };
            captureThread.Start();
        }
Ejemplo n.º 12
0
        /*
         *      AL.GetError ();
         *      string deviceName = Alc.GetString (IntPtr.Zero, AlcGetString.CaptureDefaultDeviceSpecifier);
         *      Console.WriteLine ("device: " + deviceName);
         *      IntPtr device = Alc.CaptureOpenDevice (deviceName, SRATE, ALFormat.Mono16, SSIZE);
         *      if (Error (device))
         *              return;
         *      Console.WriteLine ("c");
         *      Alc.CaptureStart (device);
         *      if (Error (device))
         *              return;
         *
         *      while (true) {
         *      byte[] buffer = new byte[SRATE];
         *              int sample = 0;
         *              Alc.GetInteger (device, AlcGetInteger.CaptureSamples, sizeof (int), out sample);
         *              if (Error (device))
         *                      return;
         *              Console.WriteLine ("sample: " + sample.ToString ());
         *              Alc.CaptureSamples (device, buffer, sample);
         *              if (Error (device))
         *                      return;
         *              SDL2.SDL.SDL_Delay (100);
         *      }
         *      Alc.CaptureStop (device);
         *      Alc.CaptureCloseDevice (device);
         */
        /*
         * ALCdevice *device = alcCaptureOpenDevice (NULL, SRATE, AL_FORMAT_STEREO16, SSIZE);
         * if (alGetError () != AL_NO_ERROR) {
         * return 0;
         * }
         * alcCaptureStart (device);
         *
         * while (true) {
         * alcGetIntegerv (device, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof (ALint), &sample);
         * alcCaptureSamples (device, (ALCvoid *)buffer, sample);
         *
         * // ... do something with the buffer
         * }
         *
         * alcCaptureStop (device);
         * alcCaptureCloseDevice (device);
         *
         * return 0;
         */

        private static bool Error(IntPtr device)
        {
            AlcError err = Alc.GetError(device);

            if (err != AlcError.NoError)
            {
                Console.WriteLine("Error: " + err.ToString());
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 13
0
		public void CheckALError (string operation)
		{
			_lastOpenALError = Alc.GetError (_device);

			if (_lastOpenALError == AlcError.NoError) {
				return;
			}

			string errorFmt = "OpenAL Error: {0}";
			Console.WriteLine (String.Format ("{0} - {1}",
							operation,
							//string.Format (errorFmt, Alc.GetString (_device, _lastOpenALError))));
							string.Format (errorFmt, _lastOpenALError)));
		}
Ejemplo n.º 14
0
        internal void CheckALCError(string operation)
        {
            AlcError error = Alc.GetError(_captureDevice);

            if (error == AlcError.NoError)
            {
                return;
            }

            string errorFmt = "OpenAL Error: {0}";

            throw new NoMicrophoneConnectedException(String.Format("{0} - {1}",
                                                                   operation,
                                                                   string.Format(errorFmt, error)));
        }
Ejemplo n.º 15
0
        public void CheckALError(string operation)
        {
            _lastOpenALError = Alc.GetError(_device);

            if (_lastOpenALError == AlcError.NoError)
            {
                return;
            }

            string errorFmt = "OpenAL Error: {0}";

            Console.WriteLine(String.Format("{0} - {1}",
                                            operation,
                                            //string.Format (errorFmt, Alc.GetString (_device, _lastOpenALError))));
                                            string.Format(errorFmt, _lastOpenALError)));
        }
        /// <summary>
        /// Checks the error state of the OpenAL driver. If a value that is not AlcError.NoError
        /// is returned, then the operation message and the error code is thrown in an Exception.
        /// </summary>
        /// <param name="operation">the operation message</param>
        public void CheckALError(string operation)
        {
            _lastOpenALError = Alc.GetError(_device);

            if (_lastOpenALError == AlcError.NoError)
            {
                return;
            }

            CleanUpOpenAL();

            string errorFmt = "OpenAL Error: {0}";

            throw new NoAudioHardwareException(String.Format("{0} - {1}",
                                                             operation,
                                                             //string.Format (errorFmt, Alc.GetString (_device, _lastOpenALError))));
                                                             string.Format(errorFmt, _lastOpenALError)));
        }
Ejemplo n.º 17
0
        public void Dispose()
        {
            AlcError error = Alc.GetError(this.Device);

            switch (error)
            {
            case AlcError.InvalidDevice:
                throw new AudioDeviceException(string.Format(AudioDeviceErrorChecker.ErrorString, (object)this.Device, (object)error));

            case AlcError.InvalidContext:
                throw new AudioContextException(string.Format(AudioDeviceErrorChecker.ErrorString, (object)this.Device, (object)error));

            case AlcError.InvalidValue:
                throw new AudioValueException(string.Format(AudioDeviceErrorChecker.ErrorString, (object)this.Device, (object)error));

            case AlcError.OutOfMemory:
                throw new OutOfMemoryException(string.Format(AudioDeviceErrorChecker.ErrorString, (object)this.Device, (object)error));
            }
        }
        public static void checkForErrors()
        {
            {
                IntPtr   device = Alc.GetContextsDevice(Alc.GetCurrentContext());
                AlcError error  = Alc.GetError(device);

                if (error != AlcError.NoError)
                {
                    Trace.WriteLine("ALC ERROR: (" + error + ")  " + Alc.GetString(device, (AlcGetString)error));
                }
            }
            {
                ALError error = AL.GetError();
                if (error != ALError.NoError)
                {
                    Trace.WriteLine("AL ERROR: (" + error + ") " + AL.GetErrorString(error));
                }
            }
        }
Ejemplo n.º 19
0
        static void CheckContextErrors()
        {
            const string format = "Device {0} reported {1}.";
            AlcError     err    = AL.alcGetError(device);

            switch (err)
            {
            case AlcError.OutOfMemory:
                throw new OutOfMemoryException(String.Format(format, device, err));

            case AlcError.InvalidValue:
                throw new AudioException(String.Format(format, device, err));

            case AlcError.InvalidDevice:
                throw new AudioException(String.Format(format, device, err));

            case AlcError.InvalidContext:
                throw new AudioException(String.Format(format, device, err));
            }
        }
Ejemplo n.º 20
0
        private string ErrorMessage(string devicename, int frequency, ALFormat bufferformat, int buffersize)
        {
            AlcError currentError = this.CurrentError;
            string   str;

            switch (currentError)
            {
            case AlcError.InvalidValue:
                str = ((object)currentError).ToString() + ": One of the parameters has an invalid value.";
                break;

            case AlcError.OutOfMemory:
                str = ((object)currentError).ToString() + ": The specified device is invalid, or can not capture audio.";
                break;

            default:
                str = ((object)currentError).ToString();
                break;
            }
            return("The handle returned by Alc.CaptureOpenDevice is null.\nAlc Error: " + (object)str + "\nDevice Name: " + devicename + "\nCapture frequency: " + (string)(object)frequency + "\nBuffer format: " + (string)(object)bufferformat + "\nBuffer Size: " + (string)(object)buffersize);
        }
Ejemplo n.º 21
0
        public static bool InitDevice()
        {
            ALDevice audioDev = ALC.OpenDevice(null);
            AlcError err      = ALC.GetError(audioDev);

            if (err != AlcError.NoError)
            {
                return(false);
            }
            ALContext aLContext = ALC.CreateContext(audioDev, new int[0]);
            bool      makeRs    = ALC.MakeContextCurrent(aLContext);

            err = ALC.GetError(audioDev);
            if (!makeRs || err != AlcError.NoError)
            {
                return(false);
            }

            //ALCdevice* inputDevice = alcCaptureOpenDevice(NULL, FREQ, AL_FORMAT_MONO16, FREQ / 2);
            ALCaptureDevice captureDev = ALC.CaptureOpenDevice(null, FREQ, ALFormat.Mono16, FREQ / 2); // FREQ

            ALC.CaptureStart(captureDev);
            err = ALC.GetError(audioDev);
            if (err != AlcError.NoError)
            {
                return(false);
            }

            int[] buffer = AL.GenBuffers(16);
            err = ALC.GetError(audioDev);
            if (err != AlcError.NoError)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 22
0
        public void Dispose()
        {
            AlcError err = Alc.GetError(Device);

            switch (err)
            {
            case AlcError.OutOfMemory:
                throw new OutOfMemoryException(String.Format(ErrorString, Device, err));

            case AlcError.InvalidValue:
                throw new AudioValueException(String.Format(ErrorString, Device, err));

            case AlcError.InvalidDevice:
                throw new AudioDeviceException(String.Format(ErrorString, Device, err));

            case AlcError.InvalidContext:
                throw new AudioContextException(String.Format(ErrorString, Device, err));

            case AlcError.NoError:
            default:
                // everything went fine, do nothing
                break;
            }
        }
Ejemplo n.º 23
0
        // Loads all available audio devices into the available_*_devices lists.
        static AudioDeviceEnumerator()
        {
            IntPtr        dummy_device  = IntPtr.Zero;
            ContextHandle dummy_context = ContextHandle.Zero;

            try
            {
                Debug.WriteLine("Enumerating audio devices.");
                Debug.Indent();

                // need a dummy context for correct results
                dummy_device  = Alc.OpenDevice(null);
                dummy_context = Alc.CreateContext(dummy_device, (int[])null);
                bool     dummy_success = Alc.MakeContextCurrent(dummy_context);
                AlcError dummy_error   = Alc.GetError(dummy_device);
                if (!dummy_success || dummy_error != AlcError.NoError)
                {
                    throw new AudioContextException("Failed to create dummy Context. Device (" + dummy_device.ToString() +
                                                    ") Context (" + dummy_context.Handle.ToString() +
                                                    ") MakeContextCurrent " + (dummy_success ? "succeeded" : "failed") +
                                                    ", Alc Error (" + dummy_error.ToString() + ") " + Alc.GetString(IntPtr.Zero, (AlcGetString)dummy_error));
                }

                // Get a list of all known playback devices, using best extension available
                if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT"))
                {
                    version = AlcVersion.Alc1_1;
                    if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATE_ALL_EXT"))
                    {
                        available_playback_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.AllDevicesSpecifier));
                        default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultAllDevicesSpecifier);
                    }
                    else
                    {
                        available_playback_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.DeviceSpecifier));
                        default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier);
                    }
                }
                else
                {
                    version = AlcVersion.Alc1_0;
                    Debug.Print("Device enumeration extension not available. Failed to enumerate playback devices.");
                }
                AlcError playback_err = Alc.GetError(dummy_device);
                if (playback_err != AlcError.NoError)
                {
                    throw new AudioContextException("Alc Error occured when querying available playback devices. " + playback_err.ToString());
                }

                // Get a list of all known recording devices, at least ALC_ENUMERATION_EXT is needed too
                if (version == AlcVersion.Alc1_1 && Alc.IsExtensionPresent(IntPtr.Zero, "ALC_EXT_CAPTURE"))
                {
                    available_recording_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.CaptureDeviceSpecifier));
                    default_recording_device = Alc.GetString(IntPtr.Zero, AlcGetString.CaptureDefaultDeviceSpecifier);
                }
                else
                {
                    Debug.Print("Capture extension not available. Failed to enumerate recording devices.");
                }
                AlcError record_err = Alc.GetError(dummy_device);
                if (record_err != AlcError.NoError)
                {
                    throw new AudioContextException("Alc Error occured when querying available recording devices. " + record_err.ToString());
                }

#if DEBUG
                Debug.WriteLine("Found playback devices:");
                foreach (string s in available_playback_devices)
                {
                    Debug.WriteLine(s);
                }

                Debug.WriteLine("Default playback device: " + default_playback_device);

                Debug.WriteLine("Found recording devices:");
                foreach (string s in available_recording_devices)
                {
                    Debug.WriteLine(s);
                }

                Debug.WriteLine("Default recording device: " + default_recording_device);
#endif
            }
            catch (DllNotFoundException e)
            {
                Trace.WriteLine(e.ToString());
                openal_supported = false;
            }
            catch (AudioContextException ace)
            {
                Trace.WriteLine(ace.ToString());
                openal_supported = false;
            }
            finally
            {
                Debug.Unindent();

                if (openal_supported)
                {
                    try
                    {
                        // clean up the dummy context
                        Alc.MakeContextCurrent(ContextHandle.Zero);
                        if (dummy_context != ContextHandle.Zero && dummy_context.Handle != IntPtr.Zero)
                        {
                            Alc.DestroyContext(dummy_context);
                        }
                        if (dummy_device != IntPtr.Zero)
                        {
                            Alc.CloseDevice(dummy_device);
                        }
                    }
                    catch
                    {
                        openal_supported = false;
                    }
                }
            }
        }
Ejemplo n.º 24
0
        static AudioDeviceEnumerator()
        {
            IntPtr        device  = IntPtr.Zero;
            ContextHandle context = ContextHandle.Zero;

            try
            {
                device = Alc.OpenDevice((string)null);
                int num1 = (int)Alc.GetError(device);
                context = Alc.CreateContext(device, (int[])null);
                int      num2   = (int)Alc.GetError(device);
                bool     flag   = Alc.MakeContextCurrent(context);
                AlcError error1 = Alc.GetError(device);
                if (!flag)
                {
                    throw new AudioContextException("Failed to create dummy Context. Device (" + device.ToString() + ") Context (" + context.Handle.ToString() + ") MakeContextCurrent " + (flag ? "succeeded" : "failed") + ", Alc Error (" + ((object)error1).ToString() + ") " + Alc.GetString(IntPtr.Zero, (AlcGetString)error1));
                }
                else
                {
                    if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT"))
                    {
                        AudioDeviceEnumerator.version = AudioDeviceEnumerator.AlcVersion.Alc1_1;
                        if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATE_ALL_EXT"))
                        {
                            AudioDeviceEnumerator.available_playback_devices.AddRange((IEnumerable <string>)Alc.GetString(IntPtr.Zero, AlcGetStringList.AllDevicesSpecifier));
                            AudioDeviceEnumerator.default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultAllDevicesSpecifier);
                        }
                        else
                        {
                            AudioDeviceEnumerator.available_playback_devices.AddRange((IEnumerable <string>)Alc.GetString(IntPtr.Zero, AlcGetStringList.DeviceSpecifier));
                            AudioDeviceEnumerator.default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier);
                        }
                    }
                    else
                    {
                        AudioDeviceEnumerator.version = AudioDeviceEnumerator.AlcVersion.Alc1_0;
                    }
                    AlcError error2 = Alc.GetError(device);
                    if (error2 != AlcError.NoError)
                    {
                        throw new AudioContextException("Alc Error occured when querying available playback devices. " + ((object)error2).ToString());
                    }
                    if (AudioDeviceEnumerator.version == AudioDeviceEnumerator.AlcVersion.Alc1_1 && Alc.IsExtensionPresent(IntPtr.Zero, "ALC_EXT_CAPTURE"))
                    {
                        AudioDeviceEnumerator.available_recording_devices.AddRange((IEnumerable <string>)Alc.GetString(IntPtr.Zero, AlcGetStringList.CaptureDeviceSpecifier));
                        AudioDeviceEnumerator.default_recording_device = Alc.GetString(IntPtr.Zero, AlcGetString.CaptureDefaultDeviceSpecifier);
                    }
                    AlcError error3 = Alc.GetError(device);
                    if (error3 != AlcError.NoError)
                    {
                        throw new AudioContextException("Alc Error occured when querying available recording devices. " + ((object)error3).ToString());
                    }
                }
            }
            catch (DllNotFoundException ex)
            {
                Trace.WriteLine(ex.ToString());
                AudioDeviceEnumerator.openal_supported = false;
            }
            catch (AudioContextException ex)
            {
                Trace.WriteLine(ex.ToString());
                AudioDeviceEnumerator.lastError        = ex.ToString();
                AudioDeviceEnumerator.openal_supported = false;
            }
            finally
            {
                Alc.MakeContextCurrent(ContextHandle.Zero);
                if (context != ContextHandle.Zero && context.Handle != IntPtr.Zero)
                {
                    Alc.DestroyContext(context);
                }
                if (device != IntPtr.Zero)
                {
                    Alc.CloseDevice(device);
                }
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Check for the OpenAL Error.
        /// </summary>
        public static void CheckError(AudioCapture device)
        {
            AlcError errorCode = GetError(device);
            int      frame     = Logger.Instance.StackFrame;

            if (errorCode == AlcError.NoError)
            {
                if (VerboseLevel == VerboseFlags.All)
                {
                    Logger.Instance.StackFrame = @checked ? 2 : 3;
                    Logger.Instance.Log("NoError: AL Operation Success", Logger.Level.Information);
                    Logger.Instance.StackFrame = frame;
                }

                @checked = true;
                return;
            }

            string error       = "Unknown Error.";
            string description = "No Description available.";

            // Decode the error code
            switch (errorCode)
            {
            case AlcError.InvalidDevice:
            {
                error       = "AL_INVALID_DEVICE";
                description = "A bad device name has been specified.";
                break;
            }

            case AlcError.InvalidEnum:
            {
                error       = "AL_INVALID_ENUM";
                description = "An unacceptable value has been specified for an enumerated argument.";
                break;
            }

            case AlcError.InvalidValue:
            {
                error       = "AL_INVALID_VALUE";
                description = "A numeric argument is out of range.";
                break;
            }

            case AlcError.InvalidContext:
            {
                error       = "AL_INVALID_CONTEXT";
                description = "The specified operation is not allowed in the current state of audio context of this thread.";
                break;
            }

            case AlcError.OutOfMemory:
            {
                error       = "AL_OUT_OF_MEMORY";
                description = "There is not enough memory left to execute the command.";
                break;
            }

            default:
            {
                error = errorCode.ToString();
                break;
            }
            }

            Logger.Instance.StackFrame = @checked ? 2 : 3;
            Logger.Instance.Log(error + ": " + description, Logger.Level.Error);
            Logger.Instance.StackFrame = frame;

            @checked = true;
        }
Ejemplo n.º 26
0
        public SoundManager()
        {
            loadedSounds      = new List <Sound>();
            streamingThread   = null;
            categoryModifiers = null;

            alcDevice = Alc.OpenDevice(null);
            if (alcDevice == null)
            {
                DebugConsole.ThrowError("Failed to open an ALC device! Disabling audio playback...");
                Disabled = true;
                return;
            }

            AlcError alcError = Alc.GetError(alcDevice);

            if (alcError != AlcError.NoError)
            {
                //The audio device probably wasn't ready, this happens quite often
                //Just wait a while and try again
                Thread.Sleep(100);

                alcDevice = Alc.OpenDevice(null);

                alcError = Alc.GetError(alcDevice);
                if (alcError != AlcError.NoError)
                {
                    DebugConsole.ThrowError("Error initializing ALC device: " + alcError.ToString() + ". Disabling audio playback...");
                    Disabled = true;
                    return;
                }
            }

            int[] alcContextAttrs = new int[] { };
            alcContext = Alc.CreateContext(alcDevice, alcContextAttrs);
            if (alcContext == null)
            {
                DebugConsole.ThrowError("Failed to create an ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + "). Disabling audio playback...");
                Disabled = true;
                return;
            }

            if (!Alc.MakeContextCurrent(alcContext))
            {
                DebugConsole.ThrowError("Failed to assign the current ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + "). Disabling audio playback...");
                Disabled = true;
                return;
            }

            alcError = Alc.GetError(alcDevice);
            if (alcError != AlcError.NoError)
            {
                DebugConsole.ThrowError("Error after assigning ALC context: " + alcError.ToString() + ". Disabling audio playback...");
                Disabled = true;
                return;
            }

            ALError alError = ALError.NoError;

            sourcePools = new SoundSourcePool[2];
            sourcePools[(int)SourcePoolIndex.Default]     = new SoundSourcePool(SOURCE_COUNT);
            playingChannels[(int)SourcePoolIndex.Default] = new SoundChannel[SOURCE_COUNT];

            sourcePools[(int)SourcePoolIndex.Voice]     = new SoundSourcePool(8);
            playingChannels[(int)SourcePoolIndex.Voice] = new SoundChannel[8];

            AL.DistanceModel(ALDistanceModel.LinearDistanceClamped);

            alError = AL.GetError();
            if (alError != ALError.NoError)
            {
                DebugConsole.ThrowError("Error setting distance model: " + AL.GetErrorString(alError) + ". Disabling audio playback...");
                Disabled = true;
                return;
            }

            ListenerPosition     = Vector3.Zero;
            ListenerTargetVector = new Vector3(0.0f, 0.0f, 1.0f);
            ListenerUpVector     = new Vector3(0.0f, -1.0f, 0.0f);
        }
Ejemplo n.º 27
0
        public SoundManager()
        {
            loadedSounds    = new List <Sound>();
            playingChannels = new SoundChannel[SOURCE_COUNT];

            streamingThread = null;

            categoryModifiers = null;

            alcDevice = Alc.OpenDevice(null);
            if (alcDevice == null)
            {
                throw new Exception("Failed to open an ALC device!");
            }

            AlcError alcError = Alc.GetError(alcDevice);

            if (alcError != AlcError.NoError)
            {
                //The audio device probably wasn't ready, this happens quite often
                //Just wait a while and try again
                Thread.Sleep(100);

                alcDevice = Alc.OpenDevice(null);

                alcError = Alc.GetError(alcDevice);
                if (alcError != AlcError.NoError)
                {
                    throw new Exception("Error initializing ALC device: " + alcError.ToString());
                }
            }

            int[] alcContextAttrs = new int[] { };
            alcContext = Alc.CreateContext(alcDevice, alcContextAttrs);
            if (alcContext == null)
            {
                throw new Exception("Failed to create an ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + ")");
            }

            if (!Alc.MakeContextCurrent(alcContext))
            {
                throw new Exception("Failed to assign the current ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + ")");
            }

            alcError = Alc.GetError(alcDevice);
            if (alcError != AlcError.NoError)
            {
                throw new Exception("Error after assigning ALC context: " + alcError.ToString());
            }

            ALError alError = ALError.NoError;

            alSources = new uint[SOURCE_COUNT];
            for (int i = 0; i < SOURCE_COUNT; i++)
            {
                AL.GenSource(out alSources[i]);
                alError = AL.GetError();
                if (alError != ALError.NoError)
                {
                    throw new Exception("Error generating alSource[" + i.ToString() + "]: " + AL.GetErrorString(alError));
                }

                if (!AL.IsSource(alSources[i]))
                {
                    throw new Exception("Generated alSource[" + i.ToString() + "] is invalid!");
                }

                AL.SourceStop(alSources[i]);
                alError = AL.GetError();
                if (alError != ALError.NoError)
                {
                    throw new Exception("Error stopping newly generated alSource[" + i.ToString() + "]: " + AL.GetErrorString(alError));
                }

                AL.Source(alSources[i], ALSourcef.MinGain, 0.0f);
                alError = AL.GetError();
                if (alError != ALError.NoError)
                {
                    throw new Exception("Error setting min gain: " + AL.GetErrorString(alError));
                }

                AL.Source(alSources[i], ALSourcef.MaxGain, 1.0f);
                alError = AL.GetError();
                if (alError != ALError.NoError)
                {
                    throw new Exception("Error setting max gain: " + AL.GetErrorString(alError));
                }

                AL.Source(alSources[i], ALSourcef.RolloffFactor, 1.0f);
                alError = AL.GetError();
                if (alError != ALError.NoError)
                {
                    throw new Exception("Error setting rolloff factor: " + AL.GetErrorString(alError));
                }
            }

            AL.DistanceModel(ALDistanceModel.LinearDistanceClamped);

            alError = AL.GetError();
            if (alError != ALError.NoError)
            {
                throw new Exception("Error setting distance model: " + AL.GetErrorString(alError));
            }

            if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_EXT_CAPTURE"))
            {
                alcCaptureDeviceNames = new List <string>(Alc.GetString(IntPtr.Zero, AlcGetStringList.CaptureDeviceSpecifier));
            }
            else
            {
                alcCaptureDeviceNames = null;
            }

            listenerOrientation  = new float[6];
            ListenerPosition     = Vector3.Zero;
            ListenerTargetVector = new Vector3(0.0f, 0.0f, 1.0f);
            ListenerUpVector     = new Vector3(0.0f, -1.0f, 0.0f);
        }