Class VirtualAudioWriter
- Namespace
- VisioForge.Core.VirtualCamera.Push
- Assembly
- VisioForge.Core.dll
Pushes raw PCM audio samples to the VisioForge Virtual Audio Card via shared memory, bypassing DirectShow completely. The virtual audio card source filter reads these samples and presents them as a microphone input to consumer applications.
public sealed class VirtualAudioWriter : IDisposableInheritance
Implements
Inherited Members
Remarks
Not thread-safe: do not call Start, Stop or Dispose while a push runs on another thread.
Constructors
VirtualAudioWriter(int, int, int, string, BaseContext)
Creates a new virtual audio writer.
public VirtualAudioWriter(int sampleRate, int channels, int bitsPerSample, string streamName, BaseContext context)Parameters
sampleRateint-
Sample rate in Hz (e.g., 48000).
channelsint-
Number of channels (1=mono, 2=stereo).
bitsPerSampleint-
Bits per sample. Only 16 is supported.
streamNamestring-
Shared memory stream name. Default matches the virtual audio card filter.
contextBaseContext-
SDK logging context. May be null (falls back to Trace).
Exceptions
- ArgumentOutOfRangeException
-
bitsPerSampleis not 16: the stream is described as 16-bit WAVE_FORMAT_PCM, which the virtual audio card is not known to read at another sample size.
Properties
BytesWritten
Total bytes of audio data pushed since Start().
public long BytesWritten { get; }Property Value
Methods
Dispose()
Releases all resources used by the VisioForge.Core.VirtualCamera.Push.VirtualAudioWriter, sending an EOS signal to the virtual audio card before closing shared memory.
public void Dispose()PushSamples(ReadOnlySpan<byte>)
Pushes raw PCM audio data. Size must be a multiple of blockAlign (channels * bitsPerSample / 8). Timestamps are calculated automatically based on accumulated bytes. The virtual audio card holds six buffers of up to one second each. While an application has the microphone open, a chunk is added to the newest buffer the card has not read yet if it fits there, so small chunks share a buffer; otherwise it takes a buffer of its own, one per started second of the chunk. When no buffer is free, the next one replaces the oldest buffer the card has not read, from this call or an earlier one. Audio pushed ahead of real time waits in these buffers and reaches the application that much later: push a live source in real time.
public bool PushSamples(ReadOnlySpan<byte> pcmData)Parameters
pcmDataReadOnlySpan<byte>
Returns
- bool
-
True when every buffer of the chunk was written. False when one could not be written: the part of the chunk before it stays written and is counted in VisioForge.Core.VirtualCamera.Push.VirtualAudioWriter.BytesWritten; to resend the rest, push the chunk from the offset by which VisioForge.Core.VirtualCamera.Push.VirtualAudioWriter.BytesWritten grew during the call.
Start()
Opens shared memory and signals that streaming is starting. Must be called before PushSamples.
public void Start()Exceptions
- InvalidOperationException
-
An application reading the virtual microphone, or an earlier writer that is not disposed, holds the stream with another sample rate, channel count or sample size, or the shared memory could not be opened.
Stop()
Signals end of stream and stops writing.
public void Stop()