Vixen
02b45cc4
csharp
public sealed class VoiceReceiver

The far end of a voice channel: packets in, a sample provider the engine can play.

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

Remarks

One of these per talker. Opus is stateful — the decoder carries pitch and spectrum between packets, and concealment extrapolates from them — so two talkers through one decoder would each be extrapolating from the other's voice. The mixer was always going to want them as separate voices anyway, which is what makes a talker positionable and what lets one of them be underwater while another is not.

The buffer is the whole trade. Packets sent every 20 ms do not arrive every 20 ms; holding a few before playing them is what turns jitter into latency instead of into gaps. Depth is that choice, in packets, and there is no right answer — only a local link, where two is generous, and a bad one, where five is not enough.

A gap is not automatically a loss. The sender's gate stops transmitting when nobody is talking, so most gaps are silence. VoicePacketHeader carries both a sequence and a timestamp precisely so this can tell them apart: concealment runs for packets that went missing, and never for a pause.

When a packet really is missing, its successor is handed to the decoder too. If the far end was spending bitrate on redundancy, that successor carries a coarse copy of the missing frame and the decoder reconstructs from it rather than extrapolating. If it was not, the decoder extrapolates and says nothing about the difference — which is why this is one call and not a choice made here.

Fields and properties (10)

  • public const int Window

    How many out-of-order packets can be held at once.

  • public const int MaxSilenceFrames

    The longest deliberate silence that is played out as silence rather than skipped over.

  • public LiveSampleProvider Provider

    What comes out, and what to hand AudioEngine.Play.

  • public AudioFormat Format

    What it decodes to.

  • public int Depth

    How many packets are held before playing.

  • public long Received

    How many packets have been taken in.

  • public long Late

    How many arrived after their moment had passed, and were dropped.

  • public long Reordered

    How many arrived out of order and were put back in it.

  • public long Concealed

    How many frames had to be produced without the packet for them.

  • public long Silences

    How many deliberate silences were played through rather than concealed.

Methods (7)

  • public VoiceReceiver(int channels = 1, int frameMilliseconds = 20, int depth = 2)

    A receiver for one talker.

  • public VoiceReceiver(OpusPacketDecoder decoder, int depth = 2)

    A receiver over a decoder somebody else configured.

  • public bool Receive(in VoicePacketHeader header, ReadOnlySpan<byte> packet)

    Takes a packet off the wire.

  • public int Pump()

    Decodes whatever is ready, and writes it out.

  • public int Flush()

    Plays out everything held, for a talker who has stopped and is not coming back.

  • public void Reset()

    Forgets the talker entirely.

  • public void Dispose()

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

Used by (2)

  • PeerVoiceChat
  • VoiceTestsVixen.Audio.Codecs.Tests