本文整理汇总了C#中OpenTK.Audio.AudioContext类的典型用法代码示例。如果您正苦于以下问题:C# AudioContext类的具体用法?C# AudioContext怎么用?C# AudioContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AudioContext类属于OpenTK.Audio命名空间,在下文中一共展示了AudioContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MusicPlayer
/// <summary>
/// MusicPlayer クラスの新しいインスタンスを初期化します。
/// </summary>
public MusicPlayer(MusicOptions options)
{
if (options == null)
throw new ArgumentNullException("options");
this.bufferSize = options.BufferSize;
this.bufferCount = options.BufferCount;
this.samplingRate = options.SamplingRate;
this.updateInterval = options.UpdateInterval;
this.context = new AudioContext();
this.master = new Master(options.SamplingRate, 23);
this.preset = new Preset();
this.layer = new Dictionary<string, SequenceLayer>();
this.source = AL.GenSource();
this.buffers = AL.GenBuffers(this.bufferCount);
this.sbuf = new short[this.bufferSize];
this.fbuf = new float[this.bufferSize];
foreach (int buffer in this.buffers)
this.FillBuffer(buffer);
AL.SourceQueueBuffers(this.source, this.buffers.Length, this.buffers);
AL.SourcePlay(this.source);
this.Updater = Task.Factory.StartNew(this.Update);
}
示例2: Sound
//int NextPlayingBuffer;
//int numPLayedBuffer;
/// <summary>
/// Constructor for Sound class
/// </summary>
/// <param name="StartThread">Are we starting the sound thread?</param>
public Sound(bool StartThread)
{
disposed = false;
SoundList = new Dictionary<string, SoundType>();
context = new AudioContext(); // default audio device
lock (context)
{
context.MakeCurrent();
}
//XRamExtension XRam = new XRamExtension();
/*SoundBuffers = AL.GenBuffers(4); // number of buffers
SoundSource = AL.GenSource();
SoundStreamSource = AL.GenSource();*/
RunSoundThread = true;
isPlaying = false;
NowPlayingName = string.Empty;
//NowPlayingBuffer = -1;
NextPlayingName = string.Empty;
//NextPlayingBuffer = -1;
//numPLayedBuffer = 0; //??
/*OpenTK.Vector3 v3 = new OpenTK.Vector3(1, 1, 1);
AL.Source(AL.GenBuffer(), ALSource3f.Position, ref v3);*/
//Debug.WriteLine(AL.Get(ALGetString.Version));
tr = new System.Threading.Thread(new ThreadStart(PlayThread));
if (StartThread)
{
RunThread();
}
}
示例3: OpenTKAudioCue
internal OpenTKAudioCue(Stream data, AudioContext ac)
{
this.ac = ac;
buffer = AL.GenBuffer();
ac.CheckErrors();
source = AL.GenSource();
ac.CheckErrors();
AL.Source(source, ALSourcef.Gain, (float)this.Volume);
ac.CheckErrors();
using (AudioReader ar = new AudioReader(data))
{
SoundData d = ar.ReadToEnd();
AL.BufferData(source, d);
ac.CheckErrors();
}
AL.Source(source, ALSourcei.Buffer, buffer);
ac.CheckErrors();
this.VolumeChanged += new VolumeChangedEventHandler(OpenTKAudioCue_VolumeChanged);
this.BalanceChanged += new BalanceChangedEventHandler(OpenTKAudioCue_BalanceChanged);
this.FadeChanged += new FadeChangedEventHandler(OpenTKAudioCue_FadeChanged);
}
示例4: Init
public void Init(Client tclient, ClientCVar cvar)
{
if (Context != null)
{
Context.Dispose();
}
TheClient = tclient;
CVars = cvar;
Context = new AudioContext(AudioContext.DefaultDevice, 0, 0, false, true);
Context.MakeCurrent();
try
{
if (Microphone != null)
{
Microphone.StopEcho();
}
Microphone = new MicrophoneHandler(this);
}
catch (Exception ex)
{
SysConsole.Output("Loading microphone handling", ex);
}
if (Effects != null)
{
foreach (SoundEffect sfx in Effects.Values)
{
sfx.Internal = -2;
}
}
Effects = new Dictionary<string, SoundEffect>();
PlayingNow = new List<ActiveSound>();
Noise = LoadSound(new DataStream(Convert.FromBase64String(NoiseDefault.NoiseB64)), "noise");
}
示例5: Player
public Player()
{
_context = new AudioContext();
for (int i = 0; i < 10; ++i)
_freeSources.Enqueue(AL.GenSource());
}
示例6: Sound
static Sound()
{
App.Init();
audio = new AudioContext();
AL.DistanceModel(ALDistanceModel.ExponentDistanceClamped);
Listener = Vec2.Zero;
}
示例7: Init
public static void Init ()
{
if (context != null)
return;
context = new AudioContext ();
}
示例8: Main
public static void Main()
{
using (AudioContext context = new AudioContext())
{
int buffer = AL.GenBuffer();
int source = AL.GenSource();
int state;
int channels, bits_per_sample, sample_rate;
byte[] sound_data = LoadWave(File.Open(filename, FileMode.Open), out channels, out bits_per_sample, out sample_rate);
AL.BufferData(buffer, GetSoundFormat(channels, bits_per_sample), sound_data, sound_data.Length, sample_rate);
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);
}
}
示例9: WaveSoundPlayer
public WaveSoundPlayer(WaveFile w, bool loop)
{
ac = new AudioContext ();
bufferlist = new List<int> (NUM_BUFFERS);
bufferlist.AddRange (AL.GenBuffers (NUM_BUFFERS));
source = AL.GenSource ();
this._PlayState = PlayState.NotLoaded;
wfile = w;
bufferlist.ForEach (x => {
byte[] buf = new byte[BUFFER_SIZE];
buf = wfile.DataBinary.ReadBytes(BUFFER_SIZE);
AL.BufferData(x,wfile.SoundFormat,buf,buf.Length,wfile.SampleRate);
});
AL.SourceQueueBuffers (source, NUM_BUFFERS, bufferlist.ToArray ());
if (loop)
AL.Source (source, ALSourceb.Looping, true);
System.Diagnostics.Debug.WriteLine (AL.GetSourceState(source).ToString());
this._PlayState = PlayState.Stopped;
}
示例10: PlaySound
public override void PlaySound(string assetName)
{
if (audioContext == null)
audioContext = new AudioContext ();
Thread soundThread = new Thread (() => this.PlaySoundThread (assetName, false));
soundThread.Start ();
}
示例11: Initialize
public void Initialize(OpenTK.GameWindow window) {
if (isInitialized) {
Error("Trying to double initialize sound manager!");
}
context = new AudioContext();
managedSounds = new List<SoundInstance>();
isInitialized = true;
}
示例12: AudioOutputAL
public AudioOutputAL()
{
try {
context = new AudioContext();
} catch( Exception e ) {
Console.WriteLine( e );
}
}
示例13: WavePlayer
/// <summary>
/// Initializes a new instance of the <see cref="WavePlayer"/> class.
/// </summary>
private WavePlayer()
{
this.context = new AudioContext();
this.buffer = AL.GenBuffer();
this.source = AL.GenSource();
this.thread = new Thread(new ThreadStart(this.SourceStateListen));
this.thread.Start();
}
示例14: Main
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);
}
}
示例15: EngineWindow
public EngineWindow()
: base(1200, 800, new GraphicsMode(32, 24, 8, 4), "OpenTK", GameWindowFlags.Default, DisplayDevice.Default, 3, 1, GraphicsContextFlags.ForwardCompatible)
{
Global.window = this;
string versionOpenGL = GL.GetString(StringName.Version);
string shaderVersion = GL.GetString(StringName.ShadingLanguageVersion);
Console.WriteLine("OpenGL: " + versionOpenGL);
Console.WriteLine("GLSL: " + shaderVersion);
AC = new AudioContext();
}