How to play Polyphonic Audio through code

Godot Version

v4.1.3.stable.mono.official [f06b6836a]


Hi again, this is a simple question because I haven’t been able to find a single tutorial online on how to use this: the AudioStreamPolyphonic. From older tutorials (I assume for Godot 3), it suggests that the resource should have a “tracks” variable that it doesn’t in Godot 4, not even if I try and access it through GDScript.

If someone could let me know how it works, I’d appreciate it a ton. If I misunderstand how you’re meant to do Polyphony through code, also let me know, because I’d prefer keeping audio sources low and playing them through code for how my game’s architecture is set up.

I’m aware the reason why polyphony through code doesn’t work as expected is because when I try and play a new sound through the same source, I am technically swapping out the stream, cutting the sound of prematurely even if the Max Polyphony property is increased above 1. I assume that variable only is considered when you play the same stream multiple times in the same source.

TL;DR: I’m wondering how to you’d polyphonic playback of multiple different audio streams in a single audio stream player using code (preferably C#, but I could hack together a system cross-script with GDScript too).

Thanks in advance,
Ema Beckett

Are you following this part of the manual? AudioStreamPlaybackPolyphonic — Godot Engine (stable) documentation in English
It seems straightforward. You set the stream, then you can play it multiple times. If you need a different stream, you use a different AudioStream.
What is the use case you need polyphony for?

It doesn’t seem that straight-forward for me? That’s sort-of why I posted this to see if someone could explain it :sweat_smile:. My use case for wanting Polyphony is in order to play multiple sound effects part of the same animation in my game.
Would the solution then be to make multiple sound sources for each unique sound stream?

I think you may be overcomplicating it. If you play different sounds from different AudioStream players, the engine will merge the sounds automatically. The polyphony sound interface is for making something like a tracker that plays the same sound at different pitches, or sounds that may have a complex source, like friction sounds, vehicle sounds, machinery sounds. If you’re just playing two different sounds at different times, that has nothing to do with the polyphony stream.