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(); }
private void ThreadProc() { try { label_28: bool flag = true; this._event.WaitOne(100); while (true) { flag = true; this.Update(); ALOutput.Check(); ALOutput.CommandInst commandInst; lock (this._commands) { if (this._commands.Any <ALOutput.CommandInst>()) { commandInst = this._commands.Dequeue(); } else { goto label_28; } } switch (commandInst.Command) { case ALOutput.Command.Play: for (int index = 0; index < this._sChannels.Length; ++index) { if (this._sChannels[index].Buffer == null) { this._sChannels[index].Buffer = this.GetBuffer(commandInst.Sound.File); this._sChannels[index].OnComplete = commandInst.Sound.OnComplete; AL.Source(this._sChannels[index].Handle, ALSourcei.Buffer, this._sChannels[index].Buffer.Buffer); AL.Source(this._sChannels[index].Handle, ALSourcef.Gain, commandInst.Sound.Volume); Vector3 values = new Vector3((float)((double)commandInst.Sound.Pan * 2.0 - 1.0), 0.0f, 0.0f); AL.Source(this._sChannels[index].Handle, ALSource3f.Position, ref values); if (commandInst.Sound.Loop) { AL.Source(this._sChannels[index].Handle, ALSourceb.Looping, true); } AL.SourcePlay(this._sChannels[index].Handle); ALOutput.Check(); break; } } break; case ALOutput.Command.Stop: for (int index = 0; index < this._sChannels.Length; ++index) { if (this._sChannels[index].Buffer != null && this._sChannels[index].Buffer.File.Equals(commandInst.Sound.File, StringComparison.InvariantCultureIgnoreCase)) { AL.SourceStop(this._sChannels[index].Handle); this.ReleaseBuffer(this._sChannels[index].Buffer); this._sChannels[index].Buffer = (ALOutput.BufferCache)null; ALOutput.Check(); break; } } break; case ALOutput.Command.Reset: for (int index = 0; index < this._sChannels.Length; ++index) { if (this._sChannels[index].Buffer != null) { AL.SourceStop(this._sChannels[index].Handle); this.ReleaseBuffer(this._sChannels[index].Buffer); this._sChannels[index].Buffer = (ALOutput.BufferCache)null; } } break; case ALOutput.Command.Terminate: goto label_18; } } label_18 :; } catch (Exception ex) { this.Log(ex.ToString()); } }