Vixen
02b45cc4
csharp
public sealed class AudioOcclusion

Keeps every voice's occlusion up to date, without casting a ray for each of them.

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

Remarks

Two problems, and neither of them is the raycast. Asking whether a wall is in the way is one call. Doing it for every audible voice every frame is sixty-four calls a frame, and taking the answer at face value makes sound flicker — a source near the edge of a doorway alternates between blocked and clear as either end moves a few centimetres, and the ear hears that as a stutter far more clearly than it hears the occlusion itself.

So the queries are rationed and the answers are smoothed. Budget casts per frame, handed out round-robin, so the cost is fixed no matter how many voices there are — a voice simply keeps last frame's answer until its turn comes round. SeekSeconds is how long a full swing from clear to blocked takes, so the flicker at a boundary becomes a slow settle instead.

What it does with the number is nothing. The value is written onto the voice and that is the end of it; turning "0.8 blocked" into a level and a cutoff is Occlusion and an authored curve, exactly like distance. A muffling that sounded right for a stone corridor and wrong for a canvas tent is then an asset edit rather than a constant in here.

Only voices that are spatial and not virtual are asked about. A 2D sound has no position for a ray to start at, and a virtualised one is not being heard — spending the frame's budget on it would be taking casts away from something audible.

Fields and properties (4)

  • public IAudioOcclusionProvider? Provider

    Who answers the question. Null turns the whole thing off.

  • public int Budget

    How many voices are asked about per frame.

  • public float SeekSeconds

    How long a swing from wide open to fully blocked takes, in seconds.

  • public long Queries

    How many queries have been made, for a profiler to look at.

Methods (2)

  • public AudioOcclusion(int capacity)

    An occlusion pass over a voice pool.

  • public void Reset()

    Forgets everything, for a scene change.

Used by (2)

  • AudioEngineVixen.Audio
  • OcclusionTestsVixen.Audio.Tests