mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-28 05:58:25 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
1 changed files with 784842 additions and 0 deletions
92
Brutal.OpenAl/Manual/CaptureDevice.cs
Normal file
92
Brutal.OpenAl/Manual/CaptureDevice.cs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
namespace Brutal.OpenAlApi;
|
||||
|
||||
public sealed partial class CaptureDevice : IDisposable, INullable
|
||||
{
|
||||
public AlcCaptureDevice Handle { get; private set; }
|
||||
|
||||
// Bytes per sample frame of the capture format; bounds Samples().
|
||||
private readonly int _bytesPerFrame;
|
||||
|
||||
private string? _specifier;
|
||||
|
||||
internal CaptureDevice(AlcCaptureDevice handle, int bytesPerFrame)
|
||||
{
|
||||
Handle = handle;
|
||||
_bytesPerFrame = bytesPerFrame;
|
||||
}
|
||||
|
||||
private AlcCaptureDevice CheckedHandle
|
||||
{
|
||||
get
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(IsNull(), this);
|
||||
return Handle;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsNull() => Handle.IsNull();
|
||||
|
||||
public string? Specifier
|
||||
{
|
||||
get
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(IsNull(), this);
|
||||
return _specifier ??= Alc.GetString(Handle, AlcGetString.CaptureDeviceSpecifier);
|
||||
}
|
||||
}
|
||||
|
||||
public int AvailableSamples => Alc.GetInteger(CheckedHandle, AlcInteger.CaptureSamples);
|
||||
|
||||
public AlcError GetError()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(IsNull(), this);
|
||||
return Alc.GetError(Handle);
|
||||
}
|
||||
|
||||
public void ThrowIfError()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(IsNull(), this);
|
||||
Alc.ThrowIfError(Handle);
|
||||
}
|
||||
|
||||
public void Start() => Alc.PInvoke.CaptureStart(CheckedHandle);
|
||||
|
||||
public void Stop() => Alc.PInvoke.CaptureStop(CheckedHandle);
|
||||
|
||||
public void Samples(Span<byte> buffer, int samples)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(IsNull(), this);
|
||||
CheckBufferLength(_bytesPerFrame, samples, buffer.Length);
|
||||
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* p = buffer)
|
||||
Alc.PInvoke.CaptureSamples(Handle, p, samples);
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(IsNull(), this);
|
||||
if (!CloseCore())
|
||||
throw new AlcException(Alc.GetError(), "alcCaptureCloseDevice failed.");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsNull())
|
||||
return;
|
||||
|
||||
// Dispose must not throw; Close() is the path that reports a failed close.
|
||||
CloseCore();
|
||||
}
|
||||
|
||||
private bool CloseCore()
|
||||
{
|
||||
var closed = Alc.PInvoke.CaptureCloseDevice(Handle);
|
||||
Handle = AlcCaptureDevice.Null;
|
||||
return closed;
|
||||
}
|
||||
|
||||
public static implicit operator AlcCaptureDevice(CaptureDevice capture) => capture.Handle;
|
||||
}
|
||||
Loading…
Reference in a new issue