Vixen
02b45cc4
csharp
public sealed class VoiceSender

The microphone end of a voice channel: capture in, packets out.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

It knows nothing about a network. Packets are pulled out of it with TryRead and handed to whatever is doing the sending — Channel.Sequenced over Vixen.Net, a loopback in a test, a file. Taking a transport dependency here would mean a game that wants voice over its own socket layer cannot use any of this, to save it four lines.

The gate is the bandwidth decision, not just an effect. It runs before the encoder, so room tone is not encoded and not transmitted; and its IsOpen decides whether the frame is sent at all. A player not talking costs nothing — not a small packet, nothing — which is the difference between a thirty-two player voice channel being affordable and being a feature people turn off.

The hold is what makes that safe. Speech drops below any useful threshold between syllables; a gate without a hold would cut the first consonant off every word after a pause. HoldSeconds defaults to 150 ms for that reason, and the gate is exposed rather than wrapped so it can be tuned against a real microphone.

Pull, not push. A callback would either allocate a closure per packet or make the caller implement an interface to avoid it. A ring the caller drains costs neither, and it means the send can happen on the caller's schedule rather than inside a capture callback.

Fields and properties (12)

  • public const int Backlog

    How many encoded packets are held before the oldest is dropped.

  • public AudioFormat Format

    What it encodes at.

  • public int FrameSize

    The frame length, in frames.

  • public GateEffect Gate

    The gate, which is both the noise gate and the voice-activity detector. Tune it; it is exposed on purpose.

  • public bool IsTransmitting

    Whether the gate is currently letting audio through, for a name plate to light up from.

  • public bool SendWhileSilent

    Whether to send frames the gate closed on anyway.

  • public long Sent

    How many packets have been encoded and made available.

  • public long Suppressed

    How many frames the gate suppressed instead of encoding.

  • public long Overrun

    How many encoded packets were dropped because the caller was not draining.

  • public int Available

    How many packets are waiting to be read.

  • public int Bitrate

    Bits a second, changeable while running.

  • public int ExpectedPacketLoss

    How lossy the link is, and with it whether to carry error correction.

Methods (6)

  • public VoiceSender(int channels = 1, int frameMilliseconds = 20, int bitrate = 24000)

    A sender over an encoder of its own.

  • public VoiceSender(OpusPacketEncoder encoder)

    A sender over an encoder somebody else configured.

  • public int Write(ReadOnlySpan<float> pcm)

    Takes captured audio, and encodes whatever whole frames it completes.

  • public bool TryRead(Span<byte> destination, out VoicePacketHeader header, out int length)

    Takes the oldest packet waiting.

  • public void Reset()

    Drops anything held, for a talker who stopped.

  • public void Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Used by (2)

  • PeerVoiceChat
  • VoiceTestsVixen.Audio.Codecs.Tests