private void Init() { ac = new AudioContext(); ALError error = AL.GetError(); if (error != ALError.NoError) { throw new OpenALException(error, "borked audio context init. ALError: " + error.ToString()); } _disposed = false; /* Source = AL.GenSource(); Buffer = AL.GenBuffer(); error = AL.GetError(); if (error != ALError.NoError) { throw new OpenALException(error, "borked generation. ALError: " + error.ToString()); }*/ if(currentInstance == null) { currentInstance = this; } }
public void BindDataBuffer(byte[] dataBuffer, ALFormat format, int size, int sampleRate) { pcmDataBuffer = dataBuffer; openALFormat = format; dataSize = size; this.sampleRate = sampleRate; AL.BufferData(openALDataBuffer, openALFormat, pcmDataBuffer, dataSize, this.sampleRate); int bits, channels; AL.GetBuffer(openALDataBuffer, ALGetBufferi.Bits, out bits); AL.GetBuffer(openALDataBuffer, ALGetBufferi.Channels, out channels); ALError alError = AL.GetError(); if (alError != ALError.NoError) { #if DEBUG Console.WriteLine("Failed to get buffer attributes: ", AL.GetErrorString(alError)); #endif Duration = -1; } else { Duration = (float)(size / ((bits / 8) * channels)) / (float)sampleRate; } //Console.WriteLine("Duration: " + Duration + " / size: " + size + " bits: " + bits + " channels: " + channels + " rate: " + sampleRate); }
public void BindDataBuffer(byte[] dataBuffer, ALFormat format, int size, int sampleRate) { this.pcmDataBuffer = dataBuffer; this.openALFormat = format; this.dataSize = size; this.sampleRate = sampleRate; AL.BufferData <byte>(this.openALDataBuffer, this.openALFormat, this.pcmDataBuffer, this.dataSize, this.sampleRate); int num1; AL.GetBuffer(this.openALDataBuffer, ALGetBufferi.Bits, out num1); int num2; AL.GetBuffer(this.openALDataBuffer, ALGetBufferi.Channels, out num2); ALError error = AL.GetError(); if (error != ALError.NoError) { Console.WriteLine("Failed to get buffer attributes: ", (object)AL.GetErrorString(error)); this.Duration = -1.0; } else { this.Duration = (double)(size / (num1 / 8 * num2)) / (double)sampleRate; } }
private static void Check() { for (ALError error = AL.GetError(); error != ALError.NoError; error = AL.GetError()) { Debug.WriteLine(AL.GetErrorString(error)); } }
private static void throwError(ALError error, string message) { switch (error) { case ALError.NoError: return; case ALError.InvalidEnum: throw new InvalidEnumALException(message); case ALError.InvalidName: throw new InvalidNameALException(message); case ALError.InvalidOperation: throw new InvalidOperationALException(message); case ALError.InvalidValue: throw new InvalidValueALException(message); case ALError.OutOfMemory: throw new OutOfMemoryALException(message); default: throw new ArgumentOutOfRangeException(nameof(error), error, null); } }
public void Play() { if (!hasSourceId) { bufferIds = AL.GenBuffers(BufferCount); sourceId = AL.GenSource(); ALError error = AL.GetError(); if (error != ALError.NoError) { throw new Exception(AL.GetErrorString(error)); } hasSourceId = true; } soundState = SoundState.Playing; if (bufferFillerThread == null) { bufferIdsToFill = bufferIds; currentBufferToFill = 0; OnBufferNeeded(EventArgs.Empty); bufferFillerThread = new Thread(new ThreadStart(BufferFiller)); bufferFillerThread.Start(); } AL.SourcePlay(sourceId); }
public void BindDataBuffer(byte[] dataBuffer, ALFormat format, int size, int sampleRate) { openALFormat = format; dataSize = size; this.sampleRate = sampleRate; AL.BufferData(openALDataBuffer, openALFormat, dataBuffer, dataSize, this.sampleRate); int bits, channels; AL.GetBuffer(openALDataBuffer, ALGetBufferi.Bits, out bits); ALError alError = AL.GetError(); if (alError != ALError.NoError) { Console.WriteLine("Failed to get buffer bits: {0}, format={1}, size={2}, sampleRate={3}", AL.GetErrorString(alError), format, size, sampleRate); Duration = -1; } else { AL.GetBuffer(openALDataBuffer, ALGetBufferi.Channels, out channels); alError = AL.GetError(); if (alError != ALError.NoError) { Console.WriteLine("Failed to get buffer bits: {0}, format={1}, size={2}, sampleRate={3}", AL.GetErrorString(alError), format, size, sampleRate); Duration = -1; } else { Duration = (float)(size / ((bits / 8) * channels)) / (float)sampleRate; } } //Console.WriteLine("Duration: " + Duration + " / size: " + size + " bits: " + bits + " channels: " + channels + " rate: " + sampleRate); }
private void BufferFiller() { bool done = false; while (!done) { var state = AL.GetSourceState(sourceId); if (state == ALSourceState.Stopped || state == ALSourceState.Initial) { AL.SourcePlay(sourceId); } if (bufferIdsToFill != null) { continue; } int buffersProcessed; AL.GetSource(sourceId, ALGetSourcei.BuffersProcessed, out buffersProcessed); ALError error = AL.GetError(); if (error != ALError.NoError) { throw new Exception(AL.GetErrorString(error)); } if (buffersProcessed == 0) { continue; } bufferIdsToFill = AL.SourceUnqueueBuffers(sourceId, buffersProcessed); currentBufferToFill = 0; OnBufferNeeded(EventArgs.Empty); } }
/// <summary> /// Gets for the latest OpenGL Error. /// </summary> /// <returns>Latest OpenGL Error.</returns> internal static ALError GetError() { ALError errorCode = AL.GetError(); LastError = errorCode; return(errorCode); }
private void CheckError(string stage) { ALError error = AL.GetError(); if (error != ALError.NoError) { Debug.LogError("OpenAL ERROR: " + error); } }
// You can define other methods, fields, classes and namespaces here public static void CheckALError(string str) { ALError error = AL.GetError(); if (error != ALError.NoError) { Console.WriteLine($"ALError at '{str}': {AL.GetErrorString(error)}"); } }
private void CheckError(string msg) { ALError e = AL.GetError(); if (e != ALError.NoError) { System.Windows.Forms.MessageBox.Show(msg + AL.GetErrorString(e)); } }
public static void CheckError() { ALError error = GetError(); if (error != ALError.NoError) { throw new Exception(string.Format("OpenAL Error: {0}", error)); } }
public static void CheckLastError() { ALError error = AL.GetError(); if (error != ALError.NoError) { throw new Exception($"OpenAL error: {error}"); } }
void CheckError(string location) { ALError error = AL.alGetError(); if (error != ALError.NoError) { throw new InvalidOperationException("OpenAL error: " + error + " at " + location); } }
public void Load(string filename) { XRamExtension XRam = new XRamExtension(); if (XRam.IsInitialized) { XRam.SetBufferMode(1, ref Buffer, XRamExtension.XRamStorage.Hardware); } BinaryReader br = new BinaryReader(File.OpenRead(filename)); byte[] bytes = new byte[1]; if (new string(br.ReadChars(4)) != "caff") { throw new Exception("input file not caff"); } br.ReadBytes(4); // rest of caf file header cafInfo = new CAFAudioFormat(); do { string type = new string(br.ReadChars(4)); long size = BitConverter.ToInt64(br.ReadBytes(8).Reverse().ToArray(), 0); if (type == "data") { bytes = new byte[size]; bytes = br.ReadBytes((int)size); } else if (type == "desc") { cafInfo.InitWithData(br.ReadBytes((int)size)); } else { br.ReadBytes((int)size); } } while (bytes.Length == 1); br.Close(); IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal(bytes.Length); System.Runtime.InteropServices.Marshal.Copy(bytes, 0, ptr, bytes.Length); AL.BufferData((uint)Buffer, cafInfo.GetALFormat(), ptr, bytes.Length, (int)cafInfo.mSampleRate); ALError error = AL.GetError(); if (error != ALError.NoError) { // respond to load error etc. Console.WriteLine("borked buffer load. ALError: " + error.ToString()); } AL.Source(Source, ALSourcei.Buffer, (int)Buffer); // attach the buffer to a source }
void CheckError(string location) { ALError error = AL.alGetError(); if (error == ALError.NoError) { return; } throw new AudioException("OpenAL error: " + error + " at " + location); }
public void BindDataBuffer(byte[] dataBuffer, ALFormat format, int size, int sampleRate, int alignment = 0) { openALFormat = format; dataSize = size; this.sampleRate = sampleRate; int unpackedSize = 0; #if DESKTOPGL if (alignment > 0) { AL.Bufferi(openALDataBuffer, ALBufferi.UnpackBlockAlignmentSoft, alignment); ALHelper.CheckError("Failed to fill buffer."); } #endif AL.BufferData(openALDataBuffer, openALFormat, dataBuffer, size, this.sampleRate); ALHelper.CheckError("Failed to fill buffer."); int bits, channels; AL.GetBuffer(openALDataBuffer, ALGetBufferi.Bits, out bits); ALError alError = AL.GetError(); if (alError != ALError.NoError) { Console.WriteLine("Failed to get buffer bits: {0}, format={1}, size={2}, sampleRate={3}", AL.GetErrorString(alError), format, size, sampleRate); Duration = -1; } else { AL.GetBuffer(openALDataBuffer, ALGetBufferi.Channels, out channels); alError = AL.GetError(); if (alError != ALError.NoError) { Console.WriteLine("Failed to get buffer channels: {0}, format={1}, size={2}, sampleRate={3}", AL.GetErrorString(alError), format, size, sampleRate); Duration = -1; } else { AL.GetBuffer(openALDataBuffer, ALGetBufferi.Size, out unpackedSize); alError = AL.GetError(); if (alError != ALError.NoError) { Console.WriteLine("Failed to get buffer size: {0}, format={1}, size={2}, sampleRate={3}", AL.GetErrorString(alError), format, size, sampleRate); Duration = -1; } else { Duration = (float)(unpackedSize / ((bits / 8) * channels)) / (float)sampleRate; } } } //Console.WriteLine("Duration: " + Duration + " / size: " + size + " bits: " + bits + " channels: " + channels + " rate: " + sampleRate); }
private void CheckALError() { ALError err = AL.GetError(); if (err == ALError.NoError) { return; } System.Console.WriteLine("OpenAL Error: " + err); }
protected bool CheckLastError() { m_LastError = m_Device.Context.GetError(); switch (m_LastError) { case ALError.OutOfMemory: throw new OutOfMemoryException(); case ALError.InvalidOperation: throw new InvalidOperationException(); } return(m_LastError == ALError.NoError); }
public OALSoundBuffer() { AL.GetError(); AL.GenBuffers(1, out this.openALDataBuffer); ALError error = AL.GetError(); if (error == ALError.NoError) { return; } Console.WriteLine("Failed to generate OpenAL data buffer: ", (object)AL.GetErrorString(error)); }
// --- 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); }
public void Dispose() { for (int i = 0; i < ALSources.Length; i++) { AL.DeleteSource(ref ALSources[i]); ALError alError = AL.GetError(); if (alError != ALError.NoError) { throw new Exception("Failed to delete ALSources[" + i.ToString() + "]: " + AL.GetErrorString(alError)); } } ALSources = null; }
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(); }
public static bool checkError(string str) { ALError err = AL.GetError(); if (err != ALError.NoError) { Warn.print(str + ": " + AL.GetErrorString(err)); //there was some kind of error return(false); } //everything was ok return(true); }
public string GetError() { if (_context == null) { return(null); } ALError error = AL.GetError(); if (error == ALError.NoError) { return(null); } return(error.ToString()); }
/// <summary> /// Generate an audio source and return its ID /// Note that 3D audio effects might only be available for mono file formats /// </summary> /// <returns> ID of the source, save it for source manipulations and play </returns> public int GenSource() { int src = AL.GenSource(); sourceCount++; ALError err = AL.GetError(); if (err != ALError.NoError) { Console.WriteLine("Generating " + sourceCount + "th source, encountered error: " + AL.GetErrorString(err)); } return(src); }
//SoundEffect DeafLoop; //public ActiveSound DeafNoise = null; /// <summary> /// Checks for audio errors. /// </summary> /// <param name="inp">The location.</param> public void CheckError(string inp) { #if AUDIO_ERROR_CHECK if (AudioInternal == null) { ALError err = AL.GetError(); if (err != ALError.NoError) { SysConsole.Output(OutputType.WARNING, "Found audio error " + err + " for " + inp); //init(TheClient, CVars); return; } } #endif }
public void Update(Location position, Location forward, Location up, Location velocity, bool selected) { ALError err = AL.GetError(); if (err != ALError.NoError) { SysConsole.Output(OutputType.WARNING, "Found audio error " + err + ", rebuilding audio..."); Init(TheClient, CVars); return; } bool sel = CVars.a_quietondeselect.ValueB ? selected : true; Selected = sel; for (int i = 0; i < PlayingNow.Count; i++) { if (!PlayingNow[i].Exists || AL.GetSourceState(PlayingNow[i].Src) == ALSourceState.Stopped) { PlayingNow[i].Destroy(); PlayingNow.RemoveAt(i); i--; } else if (!sel && PlayingNow[i].IsBackground && !PlayingNow[i].Backgrounded) { AL.Source(PlayingNow[i].Src, ALSourcef.Gain, 0.0001f); PlayingNow[i].Backgrounded = true; } else if (sel && PlayingNow[i].Backgrounded) { AL.Source(PlayingNow[i].Src, ALSourcef.Gain, PlayingNow[i].Gain); PlayingNow[i].Backgrounded = false; } } if (Microphone != null) { Microphone.Tick(); } Vector3 pos = ClientUtilities.Convert(position); Vector3 forw = ClientUtilities.Convert(forward); Vector3 upvec = ClientUtilities.Convert(up); Vector3 vel = ClientUtilities.Convert(velocity); AL.Listener(ALListener3f.Position, ref pos); AL.Listener(ALListenerfv.Orientation, ref forw, ref upvec); AL.Listener(ALListener3f.Velocity, ref vel); float globvol = CVars.a_globalvolume.ValueF; AL.Listener(ALListenerf.Gain, globvol <= 0 ? 0.001f: (globvol > 1 ? 1: globvol)); }
public SoundSourcePool(int sourceCount = SoundManager.SOURCE_COUNT) { ALError alError = ALError.NoError; ALSources = new uint[sourceCount]; for (int i = 0; i < sourceCount; 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)); } } }
public static string GetErrorString(ALError param) { return Marshal.PtrToStringAnsi(GetStringPrivate((ALGetString)param)); }
public OpenALException (ALError error) : base(AL.GetErrorString(error)) { }