protected virtual void Dispose(bool disposing) { if (disposing) { _stillRunning = false; int sessionCount = 0; // NOTE: This is done in a way to avoid possible situations when the OpenALHardwareDeviceSession is already being dispose in another thread but doesn't hold the lock and tries to Unregister. do { lock (_lock) { if (_sessions.Count == 0) { break; } OpenALHardwareDeviceSession session = _sessions[_sessions.Count - 1]; session.Dispose(); sessionCount = _sessions.Count; } }while (sessionCount > 0); ALC.DestroyContext(_context); ALC.CloseDevice(_device); } }
protected virtual void Dispose(bool disposing) { if (!_isDisposed) { // Delete the buffer AL.DeleteBuffer(_bufferId); AL.DeleteSource(_sourceId); if (_context != ALContext.Null) { ALC.MakeContextCurrent(ALContext.Null); ALC.DestroyContext(_context); } _context = ALContext.Null; if (_device != IntPtr.Zero) { ALC.CloseDevice(_device); } _device = ALDevice.Null; _isDisposed = true; } }
public void Destroy() { ALC.MakeContextCurrent(ALContext.Null); ALC.DestroyContext(_context); _context = ALContext.Null; ALC.CloseDevice(_device); _device = ALDevice.Null; }
internal void Close() { foreach (var bufferedAudioSource in _bufferedAudioSources) { bufferedAudioSource.Close(); } ALC.DestroyContext(_alContext); ALC.CloseDevice(_alDevice); }
protected virtual void Dispose(bool disposing) { if (disposing) { _stillRunning = false; foreach (OpenALHardwareDeviceSession session in _sessions.Keys) { session.Dispose(); } ALC.DestroyContext(_context); ALC.CloseDevice(_device); } }
public void Dispose() { if (context != ALContext.Null) { ALC.MakeContextCurrent(ALContext.Null); ALC.DestroyContext(context); } context = ALContext.Null; if (device != IntPtr.Zero) { ALC.CloseDevice(device); } device = ALDevice.Null; }
/// <summary> /// Destroys the AL context and closes the device, when they exist. /// </summary> private void DestroyContexts() { ALC.MakeContextCurrent(IntPtr.Zero); if (_context != IntPtr.Zero) { ALC.DestroyContext(_context); _context = IntPtr.Zero; } if (Device != IntPtr.Zero) { ALC.CloseDevice(Device); Device = IntPtr.Zero; } }
protected override void OnUnload() { GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindVertexArray(0); GL.UseProgram(0); GL.DeleteBuffer(_vertexBufferObject); GL.DeleteBuffer(_elementBufferObject); GL.DeleteVertexArray(_vertexArrayObject); ALC.DestroyContext(context); ALC.CloseDevice(device); base.OnUnload(); }
private bool isDisposed; // To detect redundant calls private void dispose(bool disposing) { if (isDisposed) { return; } if (disposing) { // Dispose managed state (managed objects). } ALC.DestroyContext(ctx); ALC.CloseDevice(device); isDisposed = true; instance = null; }
public void Dispose() { if (!initialized) { return; } foreach (var source in MiscSources) { source.Dispose(); } foreach (var source in GameSources) { source.Dispose(); } ALC.DestroyContext(context); ALC.CloseDevice(device); }
protected override void OnStop() { // Cleanup: nuke our context if we have it. This is hacky and bad - we should really destroy // our buffers and sources. I have _no_ idea if OpenAL will leak memory. if (_context != null) { XPlane.Trace.WriteLine($"[OpenAL Sample] Deleting my context 0x{(ulong)_context.Handle:X8}"); ALC.DestroyContext(_context); _context = default; } if (_device != null) { ALC.CloseDevice(_device); _device = default; } _flightLoop.Dispose(); _flightLoop = null; Menu.PluginsMenu.Dispose(); }
protected virtual void Dispose(bool disposing) { if (disposing) { lock (_lock) { _stillRunning = false; _updaterThread.Join(); // Loop against all sessions to dispose them (they will unregister themself) while (_sessions.Count > 0) { OpenALHardwareDeviceSession session = _sessions[0]; session.Dispose(); } } ALC.DestroyContext(_context); ALC.CloseDevice(_device); } }
private static void UnloadOpenAL() { ALC.DestroyContext(audioContext); ALC.CloseDevice(audioDevice); }
public void Shutdown() { ALC.MakeContextCurrent(ALContext.Null); ALC.CloseDevice(this.device); ALC.DestroyContext(this.context); }
public override void Dispose() { ALC.DestroyContext(_context); }
static void Main(string[] args) { Console.WriteLine("Starting OpenAL!"); var devices = ALC.GetStringList(GetEnumerationStringList.DeviceSpecifier); // Get the default device, then go though all devices and select the AL soft device if it exists. string deviceName = ALC.GetString(ALDevice.Null, AlcGetString.DefaultDeviceSpecifier); foreach (var d in devices) { if (d.Contains("OpenAL Soft")) { deviceName = d; } } var device = ALC.OpenDevice(deviceName); var context = ALC.CreateContext(device, (int[])null); ALC.MakeContextCurrent(context); CheckALError("Start"); // Playback the recorded data CheckALError("Before data"); AL.GenBuffer(out int alBuffer); AL.GenBuffer(out int backBuffer); AL.Listener(ALListenerf.Gain, 0.1f); AL.GenSource(out int alSource); AL.Source(alSource, ALSourcef.Gain, 1f); // var get samples from map var map = @"D:\H2vMaps\01a_tutorial.map"; var factory = new MapFactory(Path.GetDirectoryName(map)); var h2map = factory.Load(Path.GetFileName(map)); if (h2map is not H2vMap scene) { throw new NotSupportedException("Only Vista maps are supported in this tool"); } var soundMapping = scene.GetTag(scene.Globals.SoundInfos[0].SoundMap); var soundTags = scene.GetLocalTagsOfType <SoundTag>(); var maxSoundId = soundTags.Max(s => s.SoundEntryIndex); // TODO: multiplayer sounds are referencing the wrong ugh! tag var i = 0; foreach (var snd in soundTags) { var enc = snd.Encoding switch { EncodingType.ImaAdpcmMono => AudioEncoding.MonoImaAdpcm, EncodingType.ImaAdpcmStereo => AudioEncoding.StereoImaAdpcm, _ => AudioEncoding.Mono16, }; var sr = snd.SampleRate switch { Core.Tags.SampleRate.hz22k05 => Audio.SampleRate._22k05, Core.Tags.SampleRate.hz44k1 => Audio.SampleRate._44k1, _ => Audio.SampleRate._44k1 }; if (enc != AudioEncoding.Mono16) { continue; } var name = snd.Name.Substring(snd.Name.LastIndexOf("\\", snd.Name.LastIndexOf("\\") - 1) + 1).Replace('\\', '_'); Console.WriteLine($"[{i++}] {snd.Option1}-{snd.Option2}-{snd.Option3}-{snd.SampleRate}-{snd.Encoding}-{snd.Format2}-{snd.Unknown}-{snd.UsuallyMaxValue}-{snd.UsuallyZero} {name}"); var filenameFormat = $"{name}.{snd.SampleRate}-{snd.Encoding}-{snd.Format2}-{snd.Unknown}-{snd.UsuallyZero}-{snd.UsuallyMaxValue}.{{0}}.sound"; var soundEntry = soundMapping.SoundEntries[snd.SoundEntryIndex]; for (var s = 0; s < soundEntry.NamedSoundClipCount; s++) { var clipIndex = soundEntry.NamedSoundClipIndex + s; var clipInfo = soundMapping.NamedSoundClips[clipIndex]; var clipFilename = string.Format(filenameFormat, s); var clipSize = 0; for (var c = 0; c < clipInfo.SoundDataChunkCount; c++) { var chunk = soundMapping.SoundDataChunks[clipInfo.SoundDataChunkIndex + c]; clipSize += (int)(chunk.Length & 0x3FFFFFFF); } Span <byte> clipData = new byte[clipSize]; var clipDataCurrent = 0; for (var c = 0; c < clipInfo.SoundDataChunkCount; c++) { var chunk = soundMapping.SoundDataChunks[clipInfo.SoundDataChunkIndex + c]; var len = (int)(chunk.Length & 0x3FFFFFFF); var chunkData = scene.ReadData(chunk.Offset.Location, chunk.Offset, len); chunkData.Span.CopyTo(clipData.Slice(clipDataCurrent)); clipDataCurrent += len; } Interlocked.Exchange(ref backBuffer, Interlocked.Exchange(ref alBuffer, backBuffer)); AL.SourceStop(alSource); BufferData(enc, sr, clipData.Slice(96), alBuffer); CheckALError("After buffer"); AL.Source(alSource, ALSourcei.Buffer, alBuffer); AL.SourcePlay(alSource); while (AL.GetSourceState(alSource) == ALSourceState.Playing) { Thread.Sleep(100); } // Only play first variant break; } } ALC.MakeContextCurrent(ALContext.Null); ALC.DestroyContext(context); ALC.CloseDevice(device); Console.WriteLine("done"); Console.ReadLine(); }