Struct RenderBufferLease
- Namespace
- NAudio.CoreAudioApi
- Assembly
- NAudio.Wasapi.dll
Provides zero-copy write access to a WASAPI render buffer.
The buffer pointer is only valid until Dispose/Release is called.
Must be used with using to ensure ReleaseBuffer is called.
public ref struct RenderBufferLease
- Inherited Members
Properties
Buffer
A writable span over the WASAPI render buffer. Write audio data here directly.
public readonly Span<byte> Buffer { get; }
Property Value
Methods
Dispose()
Releases the buffer, discarding its contents if Release(int?, AudioClientBufferFlags) was never called.
public void Dispose()
Remarks
An unreleased lease reaching here means the caller never wrote any audio - typically because an
exception escaped the using block. Releasing the full frame count in that case would hand
WASAPI a buffer of undefined data and leave the stream padded full, so the next
GetBuffer(int) fails with AUDCLNT_E_BUFFER_TOO_LARGE (issue #1442);
releasing zero frames discards the packet instead. Never throws: a dispose running while an
exception is in flight must not replace it with a less useful one.
Release(int?, AudioClientBufferFlags)
Releases the buffer back to WASAPI, telling it how many frames were actually written.
public void Release(int? framesWritten = null, AudioClientBufferFlags flags = AudioClientBufferFlags.None)
Parameters
framesWrittenint?Number of frames written. If omitted, uses the full requested frame count.
flagsAudioClientBufferFlagsBuffer flags (default: None)