Vixen
02b45cc4
csharp
public sealed class AudioMixer

The bus tree, the voice pool, and the loop that turns them into a block of samples.

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

Remarks

Vixen mixes in software and hands the result to the device. That is the decision everything else here follows from, and it was not the obvious one: OpenAL will spatialise and mix for you, WebAudio has a whole node graph with panners and convolvers in it, and both were rejected. Three reasons.

One, the same sound on every platform. OpenAL Soft's panner, a browser's panner and a phone's mixer disagree about attenuation curves, about what a cone does at its edge, and about how a stereo source is placed. A game mixed on a desktop would have to be re-mixed for the web. Here the backend receives finished interleaved frames and its only job is to get them to the hardware.

Two, it is testable. docs/plan/12 says audio correctness is tested at buffer level, and that is only possible if there is a buffer to test — Render is a function from a world state to samples, and every claim in this assembly's tests is an assertion about numbers it returned.

Three, effects and buses would have to be written twice otherwise, once against EFX and once against WebAudio's node graph, and neither maps onto the other.

The cost is CPU: a hundred voices at 48 kHz is a few per cent of one core, which is the price every engine that owns its mixer pays and none of them regret.

Fields and properties (7)

  • public AudioBus Master

    The bus everything eventually reaches.

  • public IReadOnlyList<AudioBus> Buses

    Every bus, master first, in the order they were created.

  • public AudioFormat Format

    What it is rendering into. Not valid until Prepare.

  • public int MaxFrames

    The most frames one Render will be asked for.

  • public int VoiceCapacity

    How many voices there are in total.

  • public bool UseHrtf

    Whether spatial sounds are panned through a head model instead of between speakers.

  • public int ActiveVoices

    How many were doing something in the last block.

Methods (6)

  • public AudioMixer(int voiceCapacity = 64)

    A mixer with a fixed number of voices.

  • public AudioBus CreateBus(string name, AudioBus? parent = null)

    Adds a bus.

  • public AudioBus? FindBus(string name)

    Finds a bus by name.

  • public void Prepare(in AudioFormat deviceFormat, int frames)

    Sizes every buffer for a device.

  • public void Render(Span<float> destination, int frameCount, in AudioListenerSet listeners, long blockStart = 0)

    Renders one block.

  • public void StopAll()

    Stops every voice at once, without a fade.

Used by (11)

  • AudioBusVixen.Audio
  • AudioEffectTestsVixen.Audio.Tests
  • AudioEngineVixen.Audio
  • AudioEventBuilderVixen.Audio
  • LayeredEventTestsVixen.Audio.Tests
  • MixControlVixen.Audio
  • MixControlTestsVixen.Audio.Tests
  • MixerBuilderVixen.Audio
  • MixerParametersVixen.Audio
  • MixerSnapshotsVixen.Audio
  • AudioMixerDocumentVixen.Editor.AssetEditors