public static Source[] Generate(int count) { OpenAL.DebugFormat("Generating {0} sources", count); if (count > MaxSources) { OpenAL.Log.ErrorFormat("Requested {0} sources which is more than maximum {1}", count, MaxSources); throw new InvalidOperationException(); } Source[] sources = new Source[count]; uint[] sourceIDs = new uint[count]; alGenSources(count, sourceIDs); OpenAL.ErrorCheck(); for (int i = 0; i < count; ++i) { OpenAL.DebugFormat("Generated source {0}", sourceIDs[i]); sources[i] = new Source(sourceIDs[i]); } return(sources); }
private unsafe byte[] GetSamples(int numSamples, bool block) { ThrowIfDisposed(); int bytesPerSample = (int)Format.GetBytesPerSample(); byte[] samples = new byte[numSamples * bytesPerSample]; while (this.capturing && block && this.AvailableSamples < numSamples) { Thread.Sleep(0); } int diff = numSamples - this.AvailableSamples; if (diff > 0) { numSamples -= diff; for (int i = diff * bytesPerSample; i < samples.Length; i++) { samples[i] = 0; samples[++i] = 0; } } fixed(byte *pcmPtr = pcm) alcCaptureSamples(this.Handle, new IntPtr(pcmPtr), numSamples); OpenAL.ErrorCheck(this); Buffer.BlockCopy(pcm, 0, samples, 0, samples.Length); return(samples); }
public void Pause() { OpenAL.DebugFormat("Pausing source {0}", this.sourceID); alSourcePause(this.sourceID); OpenAL.ErrorCheck(); }
public void Stop() { OpenAL.DebugFormat("Stopping source {0}", this.sourceID); alSourceStop(this.sourceID); OpenAL.ErrorCheck(); }
public static SourceBuffer[] Generate(int count) { OpenAL.DebugFormat("Generating {0} source buffers", count); lock (lck) { if (Buffers == null) { Buffers = new Dictionary <uint, SourceBuffer> (count); } SourceBuffer[] buffers = new SourceBuffer[count]; uint[] bufferIDs = new uint[count]; alGenBuffers(count, bufferIDs); OpenAL.ErrorCheck(); for (int i = 0; i < count; ++i) { OpenAL.DebugFormat("Generated source buffer {0}", bufferIDs[i]); buffers[i] = new SourceBuffer(bufferIDs[i]); Buffers.Add(buffers[i].bufferID, buffers[i]); } return(buffers); } }
internal static void SetPropertyF(uint sourceID, FloatSourceProperty property, float value) { OpenAL.DebugFormat("Setting source {0} property {1} to {2}", sourceID, property, value); alSourcef(sourceID, property, value); OpenAL.ErrorCheck(); }
protected void Queue(uint[] bufferIDs) { OpenAL.DebugFormat("Enqueuing buffers {0} to source {1}", bufferIDs.Implode(", "), this.sourceID); alSourceQueueBuffers(this.sourceID, bufferIDs.Length, bufferIDs); OpenAL.ErrorCheck(); }
public void Activate() { OpenAL.DebugFormat("Activating context {1} for device {0}", this.Device.Name, Handle); alcMakeContextCurrent(this.Handle); CurrentContext = this; OpenAL.ErrorCheck(this.Device); }
// ReSharper restore InconsistentNaming internal static float GetPropertyF(uint sourceID, FloatSourceProperty property) { float value; alGetSourcef(sourceID, property, out value); OpenAL.ErrorCheck(); return(value); }
private int GetSamplesAvailable() { ThrowIfDisposed(); int samples; OpenAL.alcGetIntegerv(this.Handle, ALCEnum.ALC_CAPTURE_SAMPLES, 4, out samples); OpenAL.ErrorCheck(this); return(samples); }
protected void PlayCore(bool check) { if (check && this.IsPlaying) { return; } OpenAL.DebugFormat("Playing source {0}", this.sourceID); alSourcePlay(this.sourceID); OpenAL.ErrorCheck(); }
// ReSharper restore InconsistentNaming public static Context Create(PlaybackDevice device) { OpenAL.DebugFormat("Creating context for {0}", device.Name); Context c = new Context(alcCreateContext(device.Handle, IntPtr.Zero), device); OpenAL.ErrorCheck(device); device.Context = c; return(c); }
/// <summary> /// Stops capturing. /// </summary> public void StopCapture() { if (!IsOpen) { throw new InvalidOperationException("Device not open"); } ThrowIfDisposed(); OpenAL.DebugFormat("Stopping capture for {0}", Name); this.capturing = false; alcCaptureStop(this.Handle); OpenAL.ErrorCheck(this); }
internal static bool GetIsExtensionPresent(string extension) { sbyte result; if (extension.StartsWith("ALC")) { result = alcIsExtensionPresent(IntPtr.Zero, extension); } else { result = alIsExtensionPresent(extension); OpenAL.ErrorCheck(); } return(result == 1); }
internal static bool GetIsExtensionPresent(Device device, string extension) { sbyte result; if (extension.StartsWith("ALC")) { result = alcIsExtensionPresent(device.Handle, extension); OpenAL.ErrorCheck(device); } else { result = alIsExtensionPresent(extension); OpenAL.ErrorCheck(); } return(result == 1); }
/// <summary> /// Opens the capture device with the specified <paramref name="frequency"/> and <paramref name="format"/>. /// </summary> /// <param name="frequency">The frequency to open the capture device with.</param> /// <param name="format">The audio format to open the device with.</param> /// <returns>Returns <c>this</c>.</returns> public CaptureDevice Open(uint frequency, OpenALAudioFormat format) { ThrowIfDisposed(); OpenAL.DebugFormat("Opening capture device {0} at {1} {2}", Name, frequency, format); this.Format = format; this.Frequency = frequency; uint bufferSize = format.GetBytes(format.GetSamplesPerSecond(frequency)) * 2; this.Handle = alcCaptureOpenDevice(this.Name, frequency, format, (int)bufferSize); OpenAL.ErrorCheck(this); pcm = new byte[bufferSize]; return(this); }
public SourceBuffer[] Dequeue(int buffers) { OpenAL.DebugFormat("Dequeing {0} buffers for source {1}", buffers, this.sourceID); uint[] bufferIDs = new uint[buffers]; alSourceUnqueueBuffers(this.sourceID, buffers, bufferIDs); OpenAL.ErrorCheck(); SourceBuffer[] dequeued = new SourceBuffer[bufferIDs.Length]; for (int i = 0; i < bufferIDs.Length; ++i) { OpenAL.DebugFormat("Dequeued source buffer {0} for source {1}", bufferIDs[i], this.sourceID); dequeued[i] = SourceBuffer.GetBuffer(bufferIDs[i]); } return(dequeued); }
/// <summary> /// Opens the device. /// </summary> /// <returns>Returns <c>this</c>.</returns> public PlaybackDevice Open() { ThrowIfDisposed(); OpenAL.DebugFormat("Opening playback device {0}", Name); this.Handle = alcOpenDevice(this.Name); if (this.Handle == IntPtr.Zero) { throw new Exception("Device failed to open for an unknown reason."); } else { OpenAL.ErrorCheck(this); } return(this); }
public void Buffer(byte[] data, OpenALAudioFormat format, uint frequency) { alBufferData(this.bufferID, format, data, data.Length, frequency); OpenAL.ErrorCheck(); }