Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioStreamPlayer and polyphony? #23541

Closed
Zylann opened this issue Nov 6, 2018 · 7 comments
Closed

AudioStreamPlayer and polyphony? #23541

Zylann opened this issue Nov 6, 2018 · 7 comments

Comments

@Zylann
Copy link
Contributor

Zylann commented Nov 6, 2018

The old Godot 2 sample players had the ability to play multiple sounds at once, using the same node.
Now, in Godot 3, one AudioStreamPlayerXX can only play one stream at a time. This is kind of nice in the sense that it looks very much like one audio track you have control on from the editor. But, if you don't want the voice to be stolen by the next sound (and cause clipping), it encourages to create one node for every sound a scene can play, and even more if they can be played multiple times at once. The amount of required nodes is then piling up quickly and stuff like volume and attenuation model has to be copy/pasted over and over...

I see two main use cases to fulfill with polyphony:

  • Some sounds may have many variants. Footsteps, gunshots, grunts, often come in packs of 5 and played randomly at random pitch to create variety. The current system encourages to either have 5 AudioStreamPlayers with only one being used most of the time, or swap the stream with a script at the risk of cutting off an already-playing sound.

  • Some sounds may just play very often, at the point they intentionally overlap. GUI hover sounds, shoot'em up turrets, music notes, may play repeatedly from the same source. Or just simply to re-use the same player's configuration, which is not possible without "stealing" the playing voice. So your only choice is to copy the player as many times as overlapping voice.

Note 1: this doesn't apply for looping sounds, which may often have their own source. This issue is mostly about "one-shots".

Note 2: I understand as well that bringing back the Godot 2 polyphony would mean that for example changing the pitch of a player would affect all voices, unless we have a way to access all playing voices and not just the last played one?

Note 3: I came up with this issue because I ended up re-implementing this with scripts when converting my game from Godot 2 to Godot 3, and even felt tempted to implement a layer like Fabric in Unity3D where players are allocated on the fly based on simple events, which kinds of defeats the point of having an audio engine^^" I could have created voices using AudioServer but these no longer exist.

@NewNodeGames
Copy link

Why the old sample player disappeared in Godot 3, any reason?

@Aaron-Fleisher
Copy link

Aaron-Fleisher commented Nov 22, 2018

AFAIK reduz talked about this (remember seeing it on a fb post months ago)

Why the old sample player disappeared in Godot 3, any reason?

I think just because of the new audio system. Don't believe it was intentionally removed, but I'm sure it will be back. For now, adding just a couple Audio nodes and cycling through them in a play method to play the one that is not playing; should hold us over until then. I currently do this and I think it's hilarious, but it works quite well xD

@KoBeWi
Copy link
Member

KoBeWi commented Apr 10, 2019

Some sounds may have many variants. Footsteps, gunshots, grunts, often come in packs of 5 and played randomly at random pitch to create variety. The current system encourages to either have 5 AudioStreamPlayers with only one being used most of the time, or swap the stream with a script at the risk of cutting off an already-playing sound.

There's AudioStreamRandomPitch for that.

@Zylann
Copy link
Contributor Author

Zylann commented Apr 10, 2019

@KoBeWi Indeed, but it only addresses random pitch, the rest is still an issue.

@avahe-kellenberger
Copy link

Any updates on this? Just now finding out Godot cannot play overlapping sounds effects, haven't found a way to do so.

@KoBeWi
Copy link
Member

KoBeWi commented Jan 11, 2020

Any updates on this?

Only as much as you can see. There's no PR so far.

haven't found a way to do so.

I'm using code like this to spawn audio players to play sounds. It also has an advantage of not disappearing with the source object. Use it with autoload singleton.

func play_sample(sample: String, source: Vector2):
	var player := AudioStreamPlayer2D.new()
        player.stream = load(sample)
        add_child(player)
        player.global_position = source
	player.play()

Performance-wise, you should be fine even with tens of them at once.

@clayjohn
Copy link
Member

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants