private void CreateContext(string device, int freq, int refresh, bool sync, bool enableEfx, AudioContext.MaxAuxiliarySends efxAuxiliarySends) { if (!AudioDeviceEnumerator.IsOpenALSupported) { throw new DllNotFoundException("soft_oal.dll"); } if (AudioDeviceEnumerator.Version == AudioDeviceEnumerator.AlcVersion.Alc1_1 && AudioDeviceEnumerator.AvailablePlaybackDevices.Count == 0) { throw new NotSupportedException("No audio hardware is available."); } if (this.context_exists) { throw new NotSupportedException("Multiple AudioContexts are not supported."); } if (freq < 0) { throw new ArgumentOutOfRangeException("freq", (object)freq, "Should be greater than zero."); } if (refresh < 0) { throw new ArgumentOutOfRangeException("refresh", (object)refresh, "Should be greater than zero."); } if (!string.IsNullOrEmpty(device)) { this.device_name = device; this.device_handle = Alc.OpenDevice(device); } if (this.device_handle == IntPtr.Zero) { this.device_name = "IntPtr.Zero (null string)"; this.device_handle = Alc.OpenDevice((string)null); } if (this.device_handle == IntPtr.Zero) { this.device_name = AudioContext.DefaultDevice; this.device_handle = Alc.OpenDevice(AudioContext.DefaultDevice); } if (this.device_handle == IntPtr.Zero) { this.device_name = "None"; throw new AudioDeviceException(string.Format("Audio device '{0}' does not exist or is tied up by another application.", string.IsNullOrEmpty(device) ? (object)"default" : (object)device)); } else { this.CheckErrors(); List <int> list = new List <int>(); if (freq != 0) { list.Add(4103); list.Add(freq); } if (refresh != 0) { list.Add(4104); list.Add(refresh); } list.Add(4105); list.Add(sync ? 1 : 0); if (enableEfx && Alc.IsExtensionPresent(this.device_handle, "ALC_EXT_EFX")) { int data; switch (efxAuxiliarySends) { case AudioContext.MaxAuxiliarySends.One: case AudioContext.MaxAuxiliarySends.Two: case AudioContext.MaxAuxiliarySends.Three: case AudioContext.MaxAuxiliarySends.Four: data = (int)efxAuxiliarySends; break; default: Alc.GetInteger(this.device_handle, AlcGetInteger.EfxMaxAuxiliarySends, 1, out data); break; } list.Add(131075); list.Add(data); } list.Add(0); this.context_handle = Alc.CreateContext(this.device_handle, list.ToArray()); if (this.context_handle == ContextHandle.Zero) { Alc.CloseDevice(this.device_handle); throw new AudioContextException("The audio context could not be created with the specified parameters."); } else { this.CheckErrors(); if (AudioDeviceEnumerator.AvailablePlaybackDevices.Count > 0) { this.MakeCurrent(); } this.CheckErrors(); this.device_name = Alc.GetString(this.device_handle, AlcGetString.DeviceSpecifier); lock (AudioContext.audio_context_lock) { AudioContext.available_contexts.Add(this.context_handle, this); this.context_exists = true; } } } }
public AudioContext(string device, int freq, int refresh, bool sync, bool enableEfx, AudioContext.MaxAuxiliarySends efxMaxAuxSends) { this.CreateContext(device, freq, refresh, sync, enableEfx, efxMaxAuxSends); }