protected AudioFilter() { ID = alGenFilter(); Audio.CheckALError("Could not create Filter"); Audio.Filters.Add(this); }
public void Start() { if (Active) { alcCaptureStart(ptr); Audio.CheckALError("Could not start capture for CaptureDevice"); IsRecording = true; } }
public void Stop() { if (Active) { alcCaptureStop(ptr); Audio.CheckALError("Could not stop capture for CaptureDevice"); IsRecording = false; } }
public void Destroy() { if (Active) { Stop(); alcCaptureCloseDevice(ptr); Audio.CheckALError("Could not close CaptureDevice"); ptr = IntPtr.Zero; Audio.CaptureDevices.Remove(this); } }
internal AudioStream(AudioBuffer buffer, AudioSource source) { this.source = source; codec = new AudioCodec(buffer.File); format = Audio.GetalBufferFormat(codec.Channels, codec.BitDepth); alGenBuffers(bufferIDs.Length, bufferIDs); Audio.CheckALError("Could not create Buffers"); fillInitialBuffers(); Audio.Streams.Add(this); }
internal void Destroy() { codec.Destroy(); alDeleteBuffers(bufferIDs.Length, bufferIDs); Audio.CheckALError("Could not destroy Buffers"); for (int i = 0; i < bufferIDs.Length; i++) { bufferIDs[i] = default; } Audio.Streams.Remove(this); }
public void Destroy() { for (int i = Sources.Count - 1; i >= 0; i--) { Sources[i].Buffer = null; } if (!Streamed) { alDeleteBuffer(ID); Audio.CheckALError("Could not destroy Buffer"); ID = default; } Audio.Buffers.Remove(this); destroyed = true; }
public void Destroy() { for (int i = Sources.Count - 1; i >= 0; i--) { Sources[i].Filter = null; } for (int i = Channels.Count - 1; i >= 0; i--) { Channels[i].Filter = null; } alDeleteFilter(ID); Audio.CheckALError("Could not destroy Filter"); ID = default; Audio.Filters.Remove(this); }
private void fillInitialBuffers() { for (int i = 0; i < bufferIDs.Length; i++) { byte[] bytes = codec.GetData(bufferSize, source.Looping); if (bytes.Length == 0) { return; } alBufferData(bufferIDs[i], format, bytes, bytes.Length, codec.SampleRate); Audio.CheckALError("Could not set Buffer Data"); alSourceQueueBuffers(source.ID, bufferIDs[i]); Audio.CheckALError("Could not queue Buffer"); } }
public AudioBuffer(byte[] data, int channels, int bitDepth, int sampleRate) { File = ""; Streamed = false; ID = alGenBuffer(); Audio.CheckALError("Could not create Buffer"); Size = data.Length; Samples = Size / channels / (bitDepth / 8); Length = (float)Samples / sampleRate; // Debug //Output.WriteLine($"Buffer: Size: {Size} Samples: {Samples} sampleRate: {sampleRate} Length: {Length}s channels: {channels} bitDepth: {bitDepth}"); alBufferData(ID, Audio.GetalBufferFormat(channels, bitDepth), data, data.Length, sampleRate); Audio.CheckALError("Could not set Buffer Data"); Audio.Buffers.Add(this); }
internal void Update() { while (source.BuffersProcessed > 1) { alSourceUnqueueBuffers(source.ID, out uint bufferID); Audio.CheckALError("Could not unqueue Buffer"); byte[] bytes = codec.GetData(bufferSize, source.Looping); if (bytes.Length == 0) { continue; } alBufferData(bufferID, format, bytes, bytes.Length, codec.SampleRate); Audio.CheckALError("Could not set Buffer Data"); alSourceQueueBuffers(source.ID, bufferID); Audio.CheckALError("Could not queue Buffer"); } }
public AudioBuffer(string file, bool streamed = false) { if (!System.IO.File.Exists(file)) { throw new FileNotFoundException("Audio file not found.", file); } File = file; Streamed = streamed; if (Streamed) { AudioCodec codec = new AudioCodec(file); Size = codec.Size; Samples = codec.Samples; Length = codec.Length; codec.Destroy(); } else { ID = alGenBuffer(); Audio.CheckALError("Could not create Buffer"); byte[] bytes = AudioCodec.Decode(file, out float length, out int channels, out int samples, out int sampleRate, out int bitDepth); Size = bytes.Length; Samples = samples; Length = length; alBufferData(ID, Audio.GetalBufferFormat(channels, bitDepth), bytes, bytes.Length, sampleRate); Audio.CheckALError("Could not set Buffer Data"); } // Debug //Output.WriteLine($"Buffer: Size: {Size} Samples: {Samples} Length: {Length}s"); Audio.Buffers.Add(this); }
public HighpassFilter() : base() { alFilteri(ID, AL_FILTER_TYPE, AL_FILTER_HIGHPASS); Audio.CheckALError("Could not set Filter Type"); Apply(); }
public EchoEffect() : base() { alEffecti(ID, AL_EFFECT_TYPE, AL_EFFECT_ECHO); Audio.CheckALError("Could not set Effect Type"); Apply(); }
private void UnqueueBuffers() { // This is more robust than alSourceUnqueueBuffers alSourcei(source.ID, alSourceiParameter.Buffer, AL_NONE); Audio.CheckALError("Could not set AudioSource.Buffer in AudioStream.UnqueueBuffers()"); }
public ChorusEffect() : base() { alEffecti(ID, AL_EFFECT_TYPE, AL_EFFECT_CHORUS); Audio.CheckALError("Could not set Effect Type"); Apply(); }
public DistortionEffect() : base() { alEffecti(ID, AL_EFFECT_TYPE, AL_EFFECT_DISTORTION); Audio.CheckALError("Could not set Effect Type"); Apply(); }