/// <summary> /// Creates an audio context /// </summary> /// <param name="device">Name of the device to use</param> /// <returns></returns> static public bool Create(string device) { if (Context != null) { Release(); } // No context if (string.IsNullOrEmpty(device)) { Trace.WriteLine("[AudioManager] Create() : Empty device name."); return(false); } Trace.WriteLine("[AudioManager] : Creating a new context on \"{0}\"", device); try { Context = new OpenTK.Audio.AudioContext(device); } catch (Exception e) { Trace.WriteLine("[AudioManager] Create() : " + e.Message); return(false); } IsInit = true; Trace.WriteLine("[AudioManager] : Created on device \"{0}\"", Context.CurrentDevice); Diagnostic(); return(true); }
private void Dispose(bool manually) { if (!this.disposed) { this.disposed = true; DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged; // Shut down the streaming thread if (this.streamWorker != null) { this.streamWorkerEnd = true; if (!this.streamWorker.Join(1000)) { this.streamWorker.Abort(); } this.streamWorkerQueueEvent.Dispose(); this.streamWorkerEnd = false; this.streamWorkerQueueEvent = null; this.streamWorkerQueue = null; this.streamWorker = null; } try { // Clear all playing sounds foreach (SoundInstance inst in this.sounds) { inst.Dispose(); } this.sounds.Clear(); // Clear all audio related Resources ContentProvider.RemoveAllContent <AudioData>(); ContentProvider.RemoveAllContent <Sound>(); // Clear OpenAL source pool foreach (int alSource in this.alSourcePool) { AL.DeleteSource(alSource); } // Shut down OpenAL context if (this.context != null) { this.context.Dispose(); this.context = null; } AudioLibraryLoader.UnloadAudioLibrary(); } catch (Exception e) { Log.Core.WriteError("An error occured while shutting down OpenAL: {0}", Log.Exception(e)); } } }
public SoundDevice() { Log.Core.Write("Initializing OpenAL..."); Log.Core.PushIndent(); try { AudioLibraryLoader.LoadAudioLibrary(); Log.Core.Write("Available devices:" + Environment.NewLine + "{0}", AudioContext.AvailableDevices.ToString(d => d == AudioContext.DefaultDevice ? d + " (Default)" : d, "," + Environment.NewLine)); // Create OpenAL audio context this.context = new AudioContext(); Log.Core.Write("Current device: {0}", this.context.CurrentDevice); // Generate OpenAL source pool while (true) { int newSrc = AL.GenSource(); if (!DualityApp.CheckOpenALErrors(true)) { this.alSourcePool.Push(newSrc); } else { break; } } this.maxAlSources = this.alSourcePool.Count; Log.Core.Write("{0} sources available", this.alSourcePool.Count); } catch (Exception e) { Log.Core.WriteError("An error occured while initializing OpenAL: {0}", Log.Exception(e)); } Log.Core.PopIndent(); // Set up the streaming thread this.streamWorkerEnd = false; this.streamWorkerQueue = new List <SoundInstance>(); this.streamWorkerQueueEvent = new AutoResetEvent(false); this.streamWorker = new Thread(ThreadStreamFunc); this.streamWorker.IsBackground = true; this.streamWorker.Start(); DualityApp.AppDataChanged += this.DualityApp_AppDataChanged; }
public SoundDevice() { Log.Core.Write("Initializing OpenAL..."); Log.Core.PushIndent(); try { AudioLibraryLoader.LoadAudioLibrary(); Log.Core.Write("Available devices:" + Environment.NewLine + "{0}", AudioContext.AvailableDevices.ToString(d => d == AudioContext.DefaultDevice ? d + " (Default)" : d, "," + Environment.NewLine)); // Create OpenAL audio context this.context = new AudioContext(); Log.Core.Write("Current device: {0}", this.context.CurrentDevice); // Generate OpenAL source pool while (true) { int newSrc = AL.GenSource(); if (!DualityApp.CheckOpenALErrors(true)) { this.alSourcePool.Push(newSrc); } else { break; } } this.maxAlSources = this.alSourcePool.Count; Log.Core.Write("{0} sources available", this.alSourcePool.Count); } catch (Exception e) { Log.Core.WriteError("An error occured while initializing OpenAL: {0}", Log.Exception(e)); } Log.Core.PopIndent(); DualityApp.AppDataChanged += this.DualityApp_AppDataChanged; }
private void Dispose(bool manually) { if (!this.disposed) { this.disposed = true; DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged; foreach (SoundInstance inst in this.sounds) { inst.Dispose(); } this.sounds.Clear(); ContentProvider.RemoveAllContent <Sound>(); if (this.context != null) { this.context.Dispose(); this.context = null; } } }
public SoundDevice() { Log.Core.Write("Initializing OpenAL..."); Log.Core.PushIndent(); try { AudioLibraryLoader.LoadAudioLibrary(); Log.Core.Write("Available devices:" + Environment.NewLine + "{0}", AudioContext.AvailableDevices.ToString(d => d == AudioContext.DefaultDevice ? d + " (Default)" : d, "," + Environment.NewLine)); // Create OpenAL audio context this.context = new AudioContext(); Log.Core.Write("Current device: {0}", this.context.CurrentDevice); // Generate OpenAL source pool while (true) { int newSrc = AL.GenSource(); if (!DualityApp.CheckOpenALErrors(true)) this.alSourcePool.Push(newSrc); else break; } this.maxAlSources = this.alSourcePool.Count; Log.Core.Write("{0} sources available", this.alSourcePool.Count); } catch (Exception e) { Log.Core.WriteError("An error occured while initializing OpenAL: {0}", Log.Exception(e)); } Log.Core.PopIndent(); DualityApp.AppDataChanged += this.DualityApp_AppDataChanged; }
private void Dispose(bool manually) { if (!this.disposed) { this.disposed = true; DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged; foreach (SoundInstance inst in this.sounds) inst.Dispose(); this.sounds.Clear(); ContentProvider.RemoveAllContent<Sound>(); try { if (this.context != null) { this.context.Dispose(); this.context = null; } AudioLibraryLoader.UnloadAudioLibrary(); } catch (Exception e) { Log.Core.WriteError("An error occured while shutting down OpenAL: {0}", Log.Exception(e)); } } }
internal AudioContext(string deviceName, int sampleRate, int refresh) { context = new OpenTK.Audio.AudioContext(deviceName, sampleRate, refresh); resourceManager = new ResourceManager(); }
private void Dispose(bool manually) { if (!this.disposed) { this.disposed = true; DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged; foreach (SoundInstance inst in this.sounds) inst.Dispose(); this.sounds.Clear(); ContentProvider.RemoveAllContent<Sound>(); if (this.context != null) { this.context.Dispose(); this.context = null; } } }
private AudioContext(AudioConfig config) { this.Config = config; this.ctx = new ALContext(); }
private void Dispose(bool manually) { if (!this.disposed) { this.disposed = true; DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged; try { // Clear all playing sounds foreach (SoundInstance inst in this.sounds) inst.Dispose(); this.sounds.Clear(); // Clear all audio related Resources ContentProvider.RemoveAllContent<AudioData>(); ContentProvider.RemoveAllContent<Sound>(); // Clear OpenAL source pool foreach (int alSource in this.alSourcePool) { AL.DeleteSource(alSource); } // Shut down OpenAL context if (this.context != null) { this.context.Dispose(); this.context = null; } AudioLibraryLoader.UnloadAudioLibrary(); } catch (Exception e) { Log.Core.WriteError("An error occured while shutting down OpenAL: {0}", Log.Exception(e)); } } }
protected virtual void OnDisposed(bool manually) { foreach (SoundInstance inst in this.sounds) inst.Dispose(); this.sounds.Clear(); ContentProvider.UnregisterAllContent<Sound>(); this.context.Dispose(); this.context = null; }
public SoundDevice() { this.context = new AudioContext(); // Generate OpenAL source pool while (true) { int newSrc = AL.GenSource(); if (!DualityApp.CheckOpenALErrors(true)) this.alSourcePool.Push(newSrc); else break; } this.maxAlSources = this.alSourcePool.Count; Log.Core.Write( "OpenAL initialized. {0} sound sources available", this.alSourcePool.Count); DualityApp.AppDataChanged += this.DualityApp_AppDataChanged; }
public SoundDevice() { Log.Core.Write("Initializing OpenAL..."); Log.Core.PushIndent(); try { AudioLibraryLoader.LoadAudioLibrary(); Log.Core.Write("Available devices:" + Environment.NewLine + "{0}", AudioContext.AvailableDevices.ToString(d => d == AudioContext.DefaultDevice ? d + " (Default)" : d, "," + Environment.NewLine)); // Create OpenAL audio context this.context = new AudioContext(); Log.Core.Write("Current device: {0}", this.context.CurrentDevice); // Generate OpenAL source pool while (true) { int newSrc = AL.GenSource(); if (!DualityApp.CheckOpenALErrors(true)) this.alSourcePool.Push(newSrc); else break; } this.maxAlSources = this.alSourcePool.Count; Log.Core.Write("{0} sources available", this.alSourcePool.Count); } catch (Exception e) { Log.Core.WriteError("An error occured while initializing OpenAL: {0}", Log.Exception(e)); } Log.Core.PopIndent(); // Set up the streaming thread this.streamWorkerEnd = false; this.streamWorkerQueue = new List<SoundInstance>(); this.streamWorkerQueueEvent = new AutoResetEvent(false); this.streamWorker = new Thread(ThreadStreamFunc); this.streamWorker.IsBackground = true; this.streamWorker.Start(); DualityApp.AppDataChanged += this.DualityApp_AppDataChanged; }