Vixen
02b45cc4
csharp
public sealed class LiveSampleProvider

A voice fed by something that arrives when it arrives, rather than something that is read.

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

Remarks

Voice chat is what this is for. Every other source in the engine is a pull: the mixer asks a clip or a decoder for frames and gets them. A remote player's voice is a push — packets land on a network thread, get decoded, and have to go somewhere until the mixer next wants a block. This is that somewhere.

Same ring buffer as the streaming path, and the same rule: the writer may block, the reader may not. If the network is late the mixer finds the ring empty, writes silence, and counts it — which is exactly what a dropped voice packet should sound like.

It never ends on its own. A clip runs out; a person stops talking and starts again. So an empty ring is silence rather than the end of the voice, and the voice lives until somebody calls Complete or stops it. A voice-chat system holds one of these per remote player for as long as that player is in the session, which also means the mixer's spatialisation, the player's bus and its effects all stay put between utterances rather than being rebuilt per packet.

The bus is where an underwater player gets muffled. Effects are per bus, not per voice, so a session with some players submerged and some not routes them to two buses — one with a low-pass and a send to the underwater reverb, one without. That is one bus per environment rather than per player, and it is how a mixer is meant to be used.

Fields and properties (8)

  • public AudioFormat Format

    The rate and channel count of what Read produces.

  • public long FrameCount

    Never known: a live source has no length.

  • public long Position

    Where the next Read will start, in frames.

  • public bool IsLooping

    Never. There is nothing to wrap round to.

  • public long Underruns

    How many times the mixer wanted frames that had not arrived.

  • public long DroppedFrames

    How many frames were pushed and thrown away because the buffer was full.

  • public int BufferedFrames

    How many frames are waiting to be played.

  • public bool IsCompleted

    Whether the writer has said there will be no more.

Methods (5)

  • public LiveSampleProvider(AudioFormat format, int bufferedFrames = 4800)

    A live source at a format.

  • public int Write(ReadOnlySpan<float> samples)

    Adds frames for the mixer to play.

  • public void Complete()

    Says that nothing more will be written.

  • public int Read(Span<float> destination, int frameCount)
  • public void Seek(long frame)

    Starts again from a frame.

Used by (4)

  • AudioRoutingTestsVixen.Audio.Tests
  • LiveSampleProviderTestsVixen.Audio.Tests
  • VoiceReceiverVixen.Audio.Codecs
  • VoiceTestsVixen.Audio.Codecs.Tests