Class WaveInEventArgs
Event args for a recording callback. Carries one chunk of captured PCM data.
public class WaveInEventArgs : EventArgs
- Inheritance
-
WaveInEventArgs
- Inherited Members
Remarks
The data exposed by this type aliases a producer-owned buffer that will be reused on the next recording callback. Consumers must process the data (or copy it) before the event handler returns — retaining Buffer or BufferSpan past the handler is not supported and will see stale or torn data.
Constructors
WaveInEventArgs(byte[], int)
Creates new event args backed by a byte array. The first bytes
bytes of buffer hold the recorded data; bytes beyond that are not
meaningful. Kept for backward compatibility with callers that already own a byte[]
(most notably WinMM WaveIn, whose pinned buffers are native-addressable).
public WaveInEventArgs(byte[] buffer, int bytes)
Parameters
WaveInEventArgs(ReadOnlyMemory<byte>)
Creates new event args backed directly by a ReadOnlyMemory<T>. Intended for producers that can hand over captured audio without first copying into a managed byte array — for example, WASAPI capture wrapping a native buffer pointer in a MemoryManager<T>.
public WaveInEventArgs(ReadOnlyMemory<byte> buffer)
Parameters
bufferReadOnlyMemory<byte>
Remarks
The length of buffer must equal the number of valid recorded bytes.
BytesRecorded returns buffer.Length.
Properties
Buffer
Buffer containing recorded data. Length of the returned array may exceed BytesRecorded — only the first BytesRecorded bytes are valid.
public byte[] Buffer { get; }
Property Value
- byte[]
Remarks
Kept for backward compatibility. Prefer BufferSpan — it is sliced to the recorded length and avoids the array-materialisation fallback described below.
When this event is backed by a non-array ReadOnlyMemory<T> (e.g. a native WASAPI buffer wrapped in a MemoryManager<T>), reading this property allocates a fresh byte[] and copies the data into it (cached on the event for subsequent reads). Consumers on a zero-copy capture path should read BufferSpan instead to avoid that allocation.
BufferSpan
Recorded data as a read-only span, sliced to BytesRecorded.
public ReadOnlySpan<byte> BufferSpan { get; }
Property Value
Remarks
Same aliasing contract as Buffer — the span points at a producer-owned buffer that is reused on the next recording callback. Do not retain past the end of the event handler; copy the data if you need it to outlive the call.
BytesRecorded
The number of recorded bytes. See Buffer, BufferSpan.
public int BytesRecorded { get; }