Skip to content

Audio accumulates infinitely when ambisonics is disabled #128

Description

@rrisque

Godot-steam-audio version
master (commit 8742aa3)

Operating System
macOS (Apple Silicon)

Describe the bug
When is_ambisonics_on is false, the output buffer (bufs.out) is never cleared between mix frames. iplAudioBufferMix adds into the destination buffer rather than replacing it, so each frame's audio accumulates on top of the previous frame's data. The result is audio that gets progressively louder and never decays.

When ambisonics is on, iplAmbisonicsDecodeEffectApply writes (replaces) into bufs.out, so the problem doesn't occur.

Root cause
In stream.cpp line ~135, the non-ambisonics path:

iplAudioBufferMix(gs->ctx, &ls->bufs.direct, &ls->bufs.out);

needs bufs.out to be zeroed before the mix, e.g.:

for (int i = 0; i < ls->bufs.out.numChannels; i++) {
    memset(ls->bufs.out.data[i], 0, ls->bufs.out.numSamples * sizeof(float));
}
iplAudioBufferMix(gs->ctx, &ls->bufs.direct, &ls->bufs.out);

To Reproduce

  1. Set is_ambisonics_on = false on a SteamAudioPlayer (currently requires code change since the property isn't exposed in the inspector on master)
  2. Play audio
  3. Audio gets louder each frame and never stops

Note
This bug is currently hard to trigger since is_ambisonics_on has no inspector property or GDScript binding on master. It becomes easily reproducible if #127 lands (which exposes the ambisonics toggle).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions