public OpenAlAudioManager(ContentManager content, string audioDirectoryName) { if (content == null) { throw new ArgumentNullException("content"); } if (audioDirectoryName == null) { throw new ArgumentNullException("audioDirectoryName"); } _content = content; _audioDirectoryName = audioDirectoryName; // destroy previous context, specifically because monogame creates one var context = Alc.GetCurrentContext(); Alc.DestroyContext(context); _context = new AudioContext(); _context.MakeCurrent(); _efx = new EffectsExtension(); _sounds = new Dictionary <string, Sound>(); _effects = new Dictionary <string, AudioEffect>(); if (_efx.IsInitialized) { _effects.Add("lowpassfilter", new LowPassFilterAudioEffect(_efx)); } }
private void InitializeFilters() { effects = new EffectsExtension(); filter = effects.GenFilter(); effects.Filter(filter, EfxFilteri.FilterType, (int)EfxFilterType.Lowpass); effects.Filter(filter, EfxFilterf.LowpassGain, 0.9f); effects.Filter(filter, EfxFilterf.LowpassGainHF, 0.75f); }
private void InitializeFilters() { effects = new EffectsExtension(); filter = effects.GenFilter(); effects.Filter(filter, EfxFilteri.FilterType, (int)EfxFilterType.Lowpass); effects.Filter(filter, EfxFilterf.LowpassGain, 0.9f); effects.Filter(filter, EfxFilterf.LowpassGainHF, 0.75f); AL.Source(source, ALSourcei.EfxDirectFilter, filter); }
void IDualityBackend.Init() { AudioLibraryLoader.LoadAudioLibrary(); // Initialize OpenTK, if not done yet DefaultOpenTKBackendPlugin.InitOpenTK(); 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); // Create extension interfaces try { this.extFx = new EffectsExtension(); if (!this.extFx.IsInitialized) { this.extFx = null; } } catch (Exception) { this.extFx = null; } activeInstance = this; // Log all OpenAL specs for diagnostic purposes LogOpenALSpecs(); // Generate OpenAL source pool for (int i = 0; i < 256; i++) { int newSrc = AL.GenSource(); if (!Backend.DefaultOpenTK.AudioBackend.CheckOpenALErrors(true)) { this.sourcePool.Push(newSrc); } else { break; } } this.availSources = this.sourcePool.Count; Log.Core.Write("{0} sources available", this.sourcePool.Count); // Set up the streaming thread this.streamWorkerEnd = false; this.streamWorkerQueue = new List <NativeAudioSource>(); this.streamWorkerQueueEvent = new AutoResetEvent(false); this.streamWorker = new Thread(ThreadStreamFunc); this.streamWorker.IsBackground = true; this.streamWorker.Start(); }
public void Dispose() { // Obtain EFX entry points EffectsExtension EFX = OpenALDevice.Instance.EFX; // Delete EFX data EFX.DeleteAuxiliaryEffectSlot(Handle); EFX.DeleteEffect(effectHandle); }
public DSPEffect() { // Obtain EFX entry points EffectsExtension EFX = OpenALDevice.Instance.EFX; // Generate the EffectSlot and Effect Handle = EFX.GenAuxiliaryEffectSlot(); effectHandle = EFX.GenEffect(); }
public static void Main() { using (AudioContext context = new AudioContext()) { Trace.WriteLine("Testing WaveReader({0}).ReadToEnd()", filename); EffectsExtension efx = new EffectsExtension(); int buffer = AL.GenBuffer(); int source = AL.GenSource(); int state; int effect = efx.GenEffect(); int slot = efx.GenAuxiliaryEffectSlot(); efx.BindEffect(effect, EfxEffectType.Reverb); efx.Effect(effect, EfxEffectf.ReverbDecayTime, 3.0f); efx.Effect(effect, EfxEffectf.ReverbDecayHFRatio, 0.91f); efx.Effect(effect, EfxEffectf.ReverbDensity, 0.7f); efx.Effect(effect, EfxEffectf.ReverbDiffusion, 0.9f); efx.Effect(effect, EfxEffectf.ReverbRoomRolloffFactor, 3.1f); efx.Effect(effect, EfxEffectf.ReverbReflectionsGain, 0.723f); efx.Effect(effect, EfxEffectf.ReverbReflectionsDelay, 0.03f); efx.Effect(effect, EfxEffectf.ReverbGain, 0.23f); efx.AuxiliaryEffectSlot(slot, EfxAuxiliaryi.EffectslotEffect, effect); int channels, bits, rate; byte[] data = Playback.LoadWave(File.Open(filename, FileMode.Open), out channels, out bits, out rate); AL.BufferData(buffer, Playback.GetSoundFormat(channels, bits), data, data.Length, rate); AL.Source(source, ALSourcef.ConeOuterGain, 1.0f); AL.Source(source, ALSourcei.Buffer, buffer); AL.SourcePlay(source); Trace.Write("Playing"); // Query the source to find out when it stops playing. do { Thread.Sleep(250); Trace.Write("."); AL.GetSource(source, ALGetSourcei.SourceState, out state); } while ((ALSourceState)state == ALSourceState.Playing); Trace.WriteLine(""); AL.SourceStop(source); AL.DeleteSource(source); AL.DeleteBuffer(buffer); efx.DeleteEffect(effect); efx.DeleteAuxiliaryEffectSlot(slot); } }
public static void Main() { using (AudioContext context = new AudioContext()) { Trace.WriteLine("Testing WaveReader({0}).ReadToEnd()", filename); EffectsExtension efx = new EffectsExtension(); int buffer = AL.GenBuffer(); int source = AL.GenSource(); int state; int effect = efx.GenEffect(); int slot = efx.GenAuxiliaryEffectSlot(); efx.BindEffect(effect, EfxEffectType.Reverb); efx.Effect(effect, EfxEffectf.ReverbDecayTime, 3.0f); efx.Effect(effect, EfxEffectf.ReverbDecayHFRatio, 0.91f); efx.Effect(effect, EfxEffectf.ReverbDensity, 0.7f); efx.Effect(effect, EfxEffectf.ReverbDiffusion, 0.9f); efx.Effect(effect, EfxEffectf.ReverbRoomRolloffFactor, 3.1f); efx.Effect(effect, EfxEffectf.ReverbReflectionsGain, 0.723f); efx.Effect(effect, EfxEffectf.ReverbReflectionsDelay, 0.03f); efx.Effect(effect, EfxEffectf.ReverbGain, 0.23f); efx.AuxiliaryEffectSlot(slot, EfxAuxiliaryi.EffectslotEffect, effect); int channels, bits, rate; byte[] data = Playback.LoadWave(File.Open(filename, FileMode.Open), out channels, out bits, out rate); AL.BufferData(buffer, Playback.GetSoundFormat(channels, bits), data, data.Length, rate); AL.Source(source, ALSourcef.ConeOuterGain, 1.0f); AL.Source(source, ALSourcei.Buffer, buffer); AL.SourcePlay(source); Trace.Write("Playing"); // Query the source to find out when it stops playing. do { Thread.Sleep(250); Trace.Write("."); AL.GetSource(source, ALGetSourcei.SourceState, out state); }while ((ALSourceState)state == ALSourceState.Playing); Trace.WriteLine(""); AL.SourceStop(source); AL.DeleteSource(source); AL.DeleteBuffer(buffer); efx.DeleteEffect(effect); efx.DeleteAuxiliaryEffectSlot(slot); } }
/// <summary> /// Initializes the audio manager. /// </summary> /// <param name="channels">The number of channels to use.</param> /// <param name="buffersPerChannel">The number of buffers each channel will contain.</param> /// <param name="bytesPerBuffer">The number of bytes in each buffer.</param> /// <param name="launchThread">If true, a separate thread will be launched to handle updating the sound manager. /// Otherwise, a thread will not be launched and manual calls to Update() will be required.</param> public AudioManager(int channels, int buffersPerChannel, int bytesPerBuffer, bool launchThread) { if (instance != null) throw new Exception("Can't create more than one instances of AudioManager"); if(AudioContext.CurrentContext == null) new AudioContext(); Efx = new EffectsExtension(); XRam = new XRamExtension(); Init(channels, buffersPerChannel, bytesPerBuffer, launchThread); }
protected AudioEffect(EffectsExtension efx, EfxFilterType type) { if (efx == null) { throw new ArgumentNullException("efx"); } Efx = efx; FilterId = efx.GenFilter(); efx.Filter(FilterId, EfxFilteri.FilterType, (int)type); ALHelpers.CheckError(); Dirty = true; }
public DSPReverbEffect(DSPParameter[] parameters) : base() { // Obtain EFX entry points EffectsExtension EFX = OpenALDevice.Instance.EFX; // Set up the Reverb Effect EFX.BindEffect(effectHandle, EfxEffectType.EaxReverb); // TODO: Use DSP Parameters on EAXReverb Effect. They don't bind very cleanly. :/ // Bind the Effect to the EffectSlot. XACT will use the EffectSlot. EFX.BindEffectToAuxiliarySlot(Handle, effectHandle); }
void IDualityBackend.Init() { AudioLibraryLoader.LoadAudioLibrary(); // Initialize OpenTK, if not done yet DefaultOpenTKBackendPlugin.InitOpenTK(); 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); // Create extension interfaces try { this.extFx = new EffectsExtension(); if (!this.extFx.IsInitialized) this.extFx = null; } catch (Exception) { this.extFx = null; } activeInstance = this; // Log all OpenAL specs for diagnostic purposes LogOpenALSpecs(); // Generate OpenAL source pool for (int i = 0; i < 256; i++) { int newSrc = AL.GenSource(); if (!Backend.DefaultOpenTK.AudioBackend.CheckOpenALErrors(true)) this.sourcePool.Push(newSrc); else break; } this.availSources = this.sourcePool.Count; Log.Core.Write("{0} sources available", this.sourcePool.Count); // Set up the streaming thread this.streamWorkerEnd = false; this.streamWorkerQueue = new List<NativeAudioSource>(); this.streamWorkerQueueEvent = new AutoResetEvent(false); this.streamWorker = new Thread(ThreadStreamFunc); this.streamWorker.IsBackground = true; this.streamWorker.Start(); }
private AudioManager() { this.context = new AudioContext(); this.efx = new EffectsExtension(); OggStreamer.Initialize(); this.sourceManager = new SourceManager(); this.masterVolume = 1; this.musicVolume = 1; this.effectsVolume = 1; this.pitch = 1; this.lowPassGain = 1; }
public void SetGain(float value) { // Obtain EFX entry points EffectsExtension EFX = OpenALDevice.Instance.EFX; // Apply the value to the effect EFX.Effect( effectHandle, EfxEffectf.EaxReverbGain, value ); // Apply the newly modified effect to the effect slot EFX.BindEffectToAuxiliarySlot(Handle, effectHandle); }
/// <summary> /// Initialize the <see cref="SoundSystem"/>. /// </summary> /// <param name="bufferSize"></param> public void Initialize(int bufferSize = DEFAULT_BUFFER_SIZE) { if (_context == null) { _context = new ALContext(); } BufferSize = bufferSize; XRam = new XRamExtension(); Efx = new EffectsExtension(); // Init empty sources _sources = AL.GenSources(MAXIMUM_NUMBER_OF_SOURCES); ALChecker.CheckError(); }
public EfxDiagnostic() { Trace.WriteLine("--- Efx related errors ---"); EffectsExtension Efx = new EffectsExtension(); Trace.Assert(Efx.IsInitialized); #region Test for available Effects uint effect; Efx.GenEffect(out effect); AL.GetError(); foreach (EfxEffectType e in EffectNames) { Efx.BindEffect(effect, e); Effects.Add(e.ToString(), AL.GetError() == ALError.NoError); } Efx.DeleteEffect(ref effect); #endregion Test for available Effects #region Test for available Filters uint filter; Efx.GenFilter(out filter); AL.GetError(); foreach (EfxFilterType f in FilterNames) { Efx.Filter(filter, EfxFilteri.FilterType, (int)f); Filters.Add(f.ToString(), AL.GetError() == ALError.NoError); } Efx.DeleteFilter(ref filter); #endregion Test for available Filters AL.GetError(); uint[] dummy_slots = new uint[MaxAuxiliaryEffectSlotsLimit]; for (MaxAuxiliaryEffectSlots = 0; MaxAuxiliaryEffectSlots < MaxAuxiliaryEffectSlotsLimit; MaxAuxiliaryEffectSlots++) { Efx.GenAuxiliaryEffectSlot(out dummy_slots[MaxAuxiliaryEffectSlots]); if (AL.GetError() != ALError.NoError) { break; } } for (uint i = 0; i < MaxAuxiliaryEffectSlots; i++) { Efx.DeleteAuxiliaryEffectSlot(ref dummy_slots[i]); } }
public OpenALDevice() { if (Instance != null) { throw new Exception("OpenALDevice already created!"); } alDevice = Alc.OpenDevice(string.Empty); if (CheckALCError("Could not open AL device") || alDevice == IntPtr.Zero) { throw new Exception("Could not open AL device!"); } int[] attribute = new int[0]; alContext = Alc.CreateContext(alDevice, attribute); if (CheckALCError("Could not create OpenAL context") || alContext == ContextHandle.Zero) { Dispose(); throw new Exception("Could not create OpenAL context"); } Alc.MakeContextCurrent(alContext); if (CheckALCError("Could not make OpenAL context current")) { Dispose(); throw new Exception("Could not make OpenAL context current"); } EFX = new EffectsExtension(); float[] ori = new float[] { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }; AL.Listener(ALListenerfv.Orientation, ref ori); AL.Listener(ALListener3f.Position, 0.0f, 0.0f, 0.0f); AL.Listener(ALListener3f.Velocity, 0.0f, 0.0f, 0.0f); AL.Listener(ALListenerf.Gain, 1.0f); // We do NOT use automatic attenuation! XNA does not do this! AL.DistanceModel(ALDistanceModel.None); instancePool = new List <SoundEffectInstance>(); dynamicInstancePool = new List <DynamicSoundEffectInstance>(); Instance = this; }
public override void Start() { _sceneAudioListener = gameElement.ParentScene.AudioListener.GetComponent <AudioListener>(); EfxAuxiliarySendFilterGainAuto = !IsBackgroundSound; EfxAuxiliarySendFilterGainHighFrequencyAuto = !IsBackgroundSound; EfxDirectFilterGainHighFrequencyAuto = !IsBackgroundSound; SourceRelative = false; Effects = new EffectsExtension(); Transform defT = gameElement.WorldTransform; Vector3f defPos = defT.Translation, defAt = defT.ForwardVector, defUp = defT.UpVector; AL.Source(SourceHandle, ALSource3f.Position, ref defPos); AL.Source(SourceHandle, ALSource3f.Direction, ref defAt); if (AutoPlay) { PlaySound(); } gameElement.LocalTransform.OnPositionChange += ((_old, _new) => { Vector3f pos = gameElement.WorldTransform.Translation; AL.Source(SourceHandle, ALSource3f.Position, ref pos); }); gameElement.LocalTransform.OnRotationChange += ((_old, _new) => { Vector3f _forward = gameElement.WorldTransform.ForwardVector; AL.Source(SourceHandle, ALSource3f.Direction, ref _forward); }); _lastPos = defPos; }
/// <summary> /// Sets up the hardware resources used by the controller. /// </summary> private ALController() { if (AL.NativeLibrary == IntPtr.Zero) { throw new DllNotFoundException( "Couldn't initialize OpenAL because the native binaries couldn't be found."); } if (!Open()) { throw new AudioHardwareException( "OpenAL device could not be initialized, see console output for details."); } Efx = new EffectsExtension(Device); if (ALC.IsExtensionPresent(Device, "ALC_EXT_CAPTURE")) { Microphone.PopulateCaptureDevices(); } // We have hardware here and it is ready _allSources = new uint[MaxNumberOfSources]; AL.GenSources(_allSources); ALHelper.CheckError("Failed to generate sources."); // TODO: allow more effects if (Efx.IsAvailable) { Filter = Efx.GenFilter(); } _availableSources = new Queue <uint>(_allSources); _sourcesInUse = new HashSet <uint>(); }
public static void GetEaxFromEfxEax(ref EffectsExtension.EaxReverb input, out EffectsExtension.EfxEaxReverb output) { output.AirAbsorptionGainHF = 0.995f; output.RoomRolloffFactor = input.RoomRolloffFactor; output.Density = 1f; output.Diffusion = 1f; output.DecayTime = input.DecayTime; output.DecayHFLimit = 1; output.DecayHFRatio = input.DecayHFRatio; output.DecayLFRatio = input.DecayLFRatio; output.EchoDepth = input.EchoDepth; output.EchoTime = input.EchoTime; output.Gain = 0.32f; output.GainHF = 0.89f; output.GainLF = 1f; output.LFReference = input.LFReference; output.HFReference = input.HFReference; output.LateReverbDelay = input.ReverbDelay; output.LateReverbGain = 1.26f; output.LateReverbPan = input.ReverbPan; output.ModulationDepth = input.ModulationDepth; output.ModulationTime = input.ModulationTime; output.ReflectionsDelay = input.ReflectionsDelay; output.ReflectionsGain = 0.05f; output.ReflectionsPan = input.ReflectionsPan; }
public EfxDiagnostic() { Trace.WriteLine("--- Efx related errors ---"); EffectsExtension Efx = new EffectsExtension(); Trace.Assert(Efx.IsInitialized); #region Test for available Effects uint effect; Efx.GenEffect(out effect); AL.GetError(); foreach (EfxEffectType e in EffectNames) { Efx.BindEffect(effect, e); Effects.Add(e.ToString(), AL.GetError() == ALError.NoError); } Efx.DeleteEffect(ref effect); #endregion Test for available Effects #region Test for available Filters uint filter; Efx.GenFilter(out filter); AL.GetError(); foreach (EfxFilterType f in FilterNames) { Efx.Filter(filter, EfxFilteri.FilterType, (int)f); Filters.Add(f.ToString(), AL.GetError() == ALError.NoError); } Efx.DeleteFilter(ref filter); #endregion Test for available Filters AL.GetError(); uint[] dummy_slots = new uint[MaxAuxiliaryEffectSlotsLimit]; for (MaxAuxiliaryEffectSlots = 0; MaxAuxiliaryEffectSlots < MaxAuxiliaryEffectSlotsLimit; MaxAuxiliaryEffectSlots++) { Efx.GenAuxiliaryEffectSlot(out dummy_slots[MaxAuxiliaryEffectSlots]); if (AL.GetError() != ALError.NoError) break; } for (uint i = 0; i < MaxAuxiliaryEffectSlots; i++) Efx.DeleteAuxiliaryEffectSlot(ref dummy_slots[i]); }
public LowPassFilterAudioEffect(EffectsExtension efx) : base(efx, EfxFilterType.Lowpass) { _gain = 1f; }