// 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); }
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(); }
private void method_1() { AlcError alcError = OpenAL.alcGetError(this.intptr_0); if (alcError != AlcError.NoError) { throw new Exception3(alcError.ToString()); } }
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()); }
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); }
/* * 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); } }
// 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; } } } }
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); }
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); }
/// <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; }