public void Dispose() { if (!disposed) { devicecount--; disposed = true; GC.SuppressFinalize(this); try { Alc.MakeContextCurrent(new ContextHandle(IntPtr.Zero)); } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body catch #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body { } if (_hContext.Handle != IntPtr.Zero) { Alc.DestroyContext(_hContext); } if (_hDevice != IntPtr.Zero) { Alc.CloseDevice(_hDevice); } } }
public SID_OpenAL() : base() { ALDevice = Alc.OpenDevice(null); int[] attribs = null; context = Alc.CreateContext(ALDevice, attribs); Alc.MakeContextCurrent(context); }
public AccelerometerMusicBuffer() { _sampleRate = 44100; _device = Alc.OpenDevice(null); _context = Alc.CreateContext(_device, (int *)null); Alc.MakeContextCurrent(_context); //AL.GenBuffers(1, out uint buffers); _buffers = AL.GenBuffers(8); AL.GenBuffer(out uint bassABuffer); //_buffers = buffers; AL.GenSource(out _sourceOne); AL.GenSource(out _sourceTwo); AL.GenSource(out _sourceThree); AL.GenSource(out _sourceFour); AL.GenSource(out _sourceFive); var bassWave = ResolveSineWave(0.25 * short.MaxValue, 110); AL.BufferData((int)bassABuffer, ALFormat.Mono16, bassWave, bassWave.Length, _sampleRate); AL.Source(_sourceFive, ALSourceb.Looping, true); AL.SourceQueueBuffer((int)_sourceFive, (int)bassABuffer); AL.SourcePlay(_sourceFive); _leftHandData = new List <int>(); _rightHandData = new List <int>(); }
/// <summary> /// Open the sound device, sets up an audio context, and makes the new context /// the current context. Note that this method will stop the playback of /// music that was running prior to the game start. If any error occurs, then /// the state of the controller is reset. /// </summary> /// <returns>True if the sound controller was setup, and false if not.</returns> private bool OpenSoundController() { #if MACOSX || IOS alcMacOSXMixerOutputRate(PREFERRED_MIX_RATE); #endif _device = Alc.OpenDevice(string.Empty); if (CheckALError("Could not open AL device")) { return(false); } if (_device != IntPtr.Zero) { int[] attribute = new int[0]; _context = Alc.CreateContext(_device, attribute); if (CheckALError("Could not open AL context")) { CleanUpOpenAL(); return(false); } if (_context != ContextHandle.Zero) { Alc.MakeContextCurrent(_context); if (CheckALError("Could not make AL context current")) { CleanUpOpenAL(); return(false); } return(true); } } return(false); }
public static OpenALAudioAdapter TryCreate(PlatformBase _) { var newCtx = new OpenALAudioAdapter(); newCtx.AudioDevice = Alc.OpenDevice(null); if (newCtx.AudioDevice == IntPtr.Zero) { Engine.Log.Error("Couldn't find an OpenAL device.", MessageSource.OpenAL); return(null); } var attr = new int[0]; newCtx.AudioContext = Alc.CreateContext(newCtx.AudioDevice, attr); if (newCtx.AudioContext == IntPtr.Zero) { Engine.Log.Error("Couldn't create OpenAL context.", MessageSource.OpenAL); return(null); } bool success = Alc.MakeContextCurrent(newCtx.AudioContext); if (!success) { Engine.Log.Error("Couldn't make OpenAL context current.", MessageSource.OpenAL); return(null); } return(newCtx); }
protected void Dispose(bool bManagedDispose) { this.e出力デバイス = ESoundDeviceType.Unknown; // まず出力停止する(Dispose中にクラス内にアクセスされることを防ぐ) if (bManagedDispose) { #region [ 経緯時間計測用サウンドバッファを解放。] //----------------- if (this.sd経過時間計測用サウンドバッファ != null) { this.sd経過時間計測用サウンドバッファ.tサウンドを停止する(); C共通.tDisposeする(ref this.sd経過時間計測用サウンドバッファ); } //----------------- #endregion #region [ 単位繰り上げ用スレッド停止。] //----------------- if (this.th経過時間測定用スレッド != null) { this.th経過時間測定用スレッド.Abort(); this.th経過時間測定用スレッド = null; } //----------------- #endregion C共通.tDisposeする(this.tmシステムタイマ); } if (ctimer != null) { C共通.tDisposeする(ref this.ctimer); } //使わなくなったデータをクリーンアップ Alc.MakeContextCurrent(ContextHandle.Zero); Alc.DestroyContext(this.context); Alc.CloseDevice(this.device); }
private OpenALSoundController() { alcMacOSXMixerOutputRate(PREFERRED_MIX_RATE); _device = Alc.OpenDevice(string.Empty); CheckALError("Could not open AL device"); if (_device != IntPtr.Zero) { int[] attribute = new int[0]; _context = Alc.CreateContext(_device, attribute); CheckALError("Could not open AL context"); if (_context != ContextHandle.Zero) { Alc.MakeContextCurrent(_context); CheckALError("Could not make AL context current"); } } else { return; } allSourcesArray = new int[MAX_NUMBER_OF_SOURCES]; AL.GenSources(allSourcesArray); availableSourcesCollection = new HashSet <int> (); inUseSourcesCollection = new HashSet <OALSoundBuffer> (); playingSourcesCollection = new HashSet <OALSoundBuffer> (); for (int x = 0; x < MAX_NUMBER_OF_SOURCES; x++) { availableSourcesCollection.Add(allSourcesArray [x]); } }
protected void Dispose(bool bManagedDispose) { this.eOutputDevice = ESoundDeviceType.Unknown; // まず出力停止する(Dispose中にクラス内にアクセスされることを防ぐ) if (bManagedDispose) { #region [ 経緯時間計測用サウンドバッファを解放。] //----------------- if (this.sd経過時間計測用サウンドバッファ != null) { this.sd経過時間計測用サウンドバッファ.tサウンドを停止する(); CCommon.tDispose(ref this.sd経過時間計測用サウンドバッファ); } //----------------- #endregion CCommon.tDispose(this.tmSystemTimer); } if (ctimer != null) { CCommon.tDispose(ref this.ctimer); } //使わなくなったデータをクリーンアップ Alc.MakeContextCurrent(ContextHandle.Zero); Alc.DestroyContext(this.context); Alc.CloseDevice(this.device); }
public static void Main(string[] args) { var device = Alc.OpenDevice(null); var context = Alc.CreateContext(device, null); Console.WriteLine(Alc.MakeContextCurrent(context)); }
public static void InitialSetup() { // FOR THE LOVE OF GOD PLEASE LET THIS WORK AudioDevice = Alc.OpenDevice(null); // Default device if (AudioDevice != null) { AudioCtx = Alc.CreateContext(AudioDevice, (int[])null); if (AudioCtx != ContextHandle.Zero) { Alc.GetError(AudioDevice); if (Alc.MakeContextCurrent(AudioCtx)) { //LoadWaveFile ("camprespite_loop", "camprespite_loop.wav"); LoadWaveFile("last_human_loop", "last_human_loop_limited.wav"); //.DurationAdjust(0.01); LoadWaveFile("induction_loop", "induction_loop.wav"); LoadWaveFile("sfx_bullet_impact", "sfx_bullet_impact.wav"); LoadWaveFile("sfx_player_land_two_feet", "sfx_player_land_two_feet.wav"); LoadWaveFile("sfx_shoot_gun", "sfx_shoot_gun.wav"); LoadWaveFile("win", "win.wav"); } else { throw new Exception("Failed to set current audio context"); } } else { throw new Exception("Failed to create audio context."); } } else { throw new Exception("Failed to open default audio device."); } }
private bool INTERNAL_initSoundController() { #if IOS alcMacOSXMixerOutputRate(44100); #endif try { _device = Alc.OpenDevice(string.Empty); } catch { return(false); } if (CheckALCError("Could not open AL device") || _device == IntPtr.Zero) { return(false); } int[] attribute = new int[0]; _context = Alc.CreateContext(_device, attribute); if (CheckALCError("Could not create OpenAL context") || _context == ContextHandle.Zero) { Dispose(true); return(false); } Alc.MakeContextCurrent(_context); if (CheckALCError("Could not make OpenAL context current")) { Dispose(true); return(false); } return(true); }
public ALOutput(DataSource data) { this._source = data; this._dev = Alc.OpenDevice((string)null); if (this._dev.Equals((object)IntPtr.Zero)) { throw new AudioException("Failed to init OpenAL"); } Alc.MakeContextCurrent(Alc.CreateContext(this._dev, new int[2] { 4103, 44100 })); float[] values = new float[6] { 0.0f, 0.0f, 1f, 0.0f, 1f, 0.0f }; AL.Listener(ALListener3f.Position, 0.0f, 0.0f, 0.0f); AL.Listener(ALListener3f.Velocity, 0.0f, 0.0f, 0.0f); AL.Listener(ALListenerfv.Orientation, ref values); AL.DistanceModel(ALDistanceModel.None); this._sChannels = new ALOutput.Channel[16]; for (int index = 0; index < this._sChannels.Length; ++index) { this._sChannels[index].Handle = AL.GenSource(); } ALOutput.Check(); new Thread(new ThreadStart(this.ThreadProc)).Start(); }
public static IAudio LoadWave(string filePath) { if (_disposables.ContainsKey(filePath)) { return((IAudio)_disposables[filePath]); } IntPtr device = Alc.OpenDevice(null); ContextHandle handle = Alc.CreateContext(device, (int[])null); Alc.MakeContextCurrent(handle); int buffer = AL.GenBuffer(); int source = AL.GenSource(); WaveFileReader reader = new WaveFileReader(filePath); byte[] data = new byte[reader.Length]; reader.Read(data, 0, data.Length); AL.BufferData(buffer, GetSoundFormat(reader.WaveFormat.Channels, reader.WaveFormat.BitsPerSample), data, data.Length, reader.WaveFormat.SampleRate); AL.Source(source, ALSourcei.Buffer, buffer); IAudio audio = new WaveAudio(filePath, source, buffer, handle); _disposables.TryAdd(filePath, audio); return(audio); }
private void Release_Resources(object sender, EventArgs e) { AL.SourceStop(_source); AL.DeleteSource(_source); AL.DeleteBuffer(_buffer); Alc.MakeContextCurrent(ContextHandle.Zero); _context.Dispose(); }
public AudioSource([NotNull] AudioContext context) { Context = context; Alc.MakeContextCurrent(context.NativeContext); _source = AL.GenSource(); context.ManageSource(this); }
public static void EnsureContext() { if (AudioContext == IntPtr.Zero) { throw new NullReferenceException("OpenAL context was prematurely destroyed. Please don't do that."); } Alc.MakeContextCurrent(AudioContext); }
public void Dispose() { AL.DeleteSources(1, ref _source); Alc.MakeContextCurrent(ContextHandle.Zero); Alc.DestroyContext(_context); Alc.CloseDevice(_device); }
internal static void Cleanup() { Window.Close(); GraphicsContext.Dispose(); Alc.MakeContextCurrent(ContextHandle.Zero); Alc.DestroyContext(AudioContext); Alc.CloseDevice(AudioDevice); }
private static void TryInitAudio() { int tries = 0; while (mAudioOn == false && tries < 10) { try { mDeviceID = Alc.OpenDevice(null); KWLogger.Log("Initializing OpenAL (Attempt #" + tries + ")", "GLAudioEngine::TryInitAudio"); Console.WriteLine("Initializing audio engine OpenAL (Attempt #" + tries + ")... "); int[] attributes = new int[0]; mContext = Alc.CreateContext(mDeviceID, attributes); Alc.MakeContextCurrent(mContext); var version = AL.Get(ALGetString.Version); var vendor = AL.Get(ALGetString.Vendor); if (version == null) { KWLogger.Log("No Audio devices found.", "GLAudioEngine::TryInitAudio", LogLevel.Error); throw new Exception("No Audio devices found."); } Console.Write('\t' + version + " " + vendor); Console.WriteLine(" Init complete."); KWLogger.Log("Audio initialized: " + version + " " + vendor, "GLAudioEngine::TryInitAudio"); mAudioOn = true; } catch (Exception) { mAudioOn = false; } if (mAudioOn == false) { tries++; Thread.Sleep(500); } } IsInitializing = false; if (mAudioOn) { for (int i = 0; i < mChannels; i++) { GLAudioSource s = new GLAudioSource(); mSources.Add(s); } } else { Console.WriteLine("\t\t(Giving up on initializing the audio engine. Sorry.)"); KWLogger.Log("Giving up on initializing the audio engine. Sorry.", "GLAudioEngine::TryInitAudio", LogLevel.Error); } }
void shutDownAudio() { ContextHandle alContext = Alc.GetCurrentContext(); IntPtr alDevice = Alc.GetContextsDevice(alContext); ContextHandle emptyContext = ContextHandle.Zero; Alc.MakeContextCurrent(emptyContext); Alc.DestroyContext(alContext); Alc.CloseDevice(alDevice); }
protected override void DisposeBase() { if (object.ReferenceEquals(current, this)) { Alc.MakeContextCurrent(ContextHandle.Zero); } current = null; Alc.DestroyContext(Handle); handle = ContextHandle.Zero; }
public void CleanAndExit() { ContextHandle alContext = Alc.GetCurrentContext(); IntPtr alDevice = Alc.GetContextsDevice(alContext); ContextHandle emptyContext = ContextHandle.Zero; Alc.MakeContextCurrent(emptyContext); Alc.DestroyContext(alContext); Alc.CloseDevice(alDevice); }
static ContextManager() { var device = Alc.OpenDevice(null); if (device != IntPtr.Zero) { AudioContext = Alc.CreateContext(device, null); Alc.MakeContextCurrent(AudioContext); } }
public static void Init() { var deviceName = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultAllDevicesSpecifier); Console.WriteLine(deviceName); _device = Alc.OpenDevice(deviceName); _context = Alc.CreateContext(_device, (int[])null); Alc.MakeContextCurrent(_context); CheckError(); }
public AlPlayer(IMusicPlayer player, int rate) { _player = player; _rate = rate; _device = Alc.OpenDevice(null); _context = Alc.CreateContext(_device, null); Console.WriteLine(Alc.GetString(IntPtr.Zero, Alc.AllDevicesSpecifier)); Alc.MakeContextCurrent(_context); }
/// \internal /// <summary>Makes the specified AudioContext current in the calling thread.</summary> /// <param name="context">The osuTK.Audio.AudioContext to make current, or null.</param> /// <exception cref="ObjectDisposedException"> /// Occurs if this function is called after the AudioContext has been disposed. /// </exception> /// <exception cref="AudioContextException"> /// Occurs when the AudioContext could not be made current. /// </exception> private static void MakeCurrent(AudioContext context) { lock (audio_context_lock) { if (!Alc.MakeContextCurrent(context != null ? context.context_handle : ContextHandle.Zero)) { throw new AudioContextException(String.Format("ALC {0} error detected at {1}.", Alc.GetError(context != null ? (IntPtr)context.context_handle : IntPtr.Zero).ToString(), context != null ? context.ToString() : "null")); } } }
static int[] Initialize(out IntPtr device, out ContextHandle context, out int source) { device = Alc.OpenDevice(null); context = Alc.CreateContext(device, (int[])null); Alc.MakeContextCurrent(context); var buffers = AL.GenBuffers(BuffersCount); AL.GenSources(1, out source); return(buffers); }
private static void _CreateAudioContext() { IntPtr d = Alc.OpenDevice(OpenTK.Audio.AudioContext.DefaultDevice); OpenTK.ContextHandle c = Alc.CreateContext(d, new int[0]); Alc.MakeContextCurrent(c); AL.Listener(ALListener3f.Position, 0, 0, 0); AL.Listener(ALListener3f.Velocity, 0, 0, 0); float[] vs = new float[] { 0, 0, -1, 0, 1, 0 }; AL.Listener(ALListenerfv.Orientation, ref vs); }
// --- 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); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var device = Alc.OpenDevice(null); var context = Alc.CreateContext(device, (int[])null); Alc.MakeContextCurrent(context); Application.Run(new MainWindow()); Alc.MakeContextCurrent(OpenTK.ContextHandle.Zero); Alc.DestroyContext(context); Alc.CloseDevice(device); }