-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
Add AudioStreamPolyphonic to simplify sound playback from code #71855
Conversation
098a537
to
ee478b2
Compare
Does the AnimationPlayer's audio playback tracks support this new stream? I've tried to use AnimationPlayer with AudioStreamPlayer as part of a demo project recently, but found that it didn't support polyphony (old sounds were replaced by new sounds as they were played, even if Max Polyphony was increased above 1 on the AudioStreamPlayer). |
ee478b2
to
b77a533
Compare
@Calinou So far this PR does not change animation code, but the idea is that it blends the audio from one animation to another (or lets it finish instead of killing it). Currently only one stream can be played at the same time always. |
Previously, the streams in AudioTrack were set directly to AudioStreamPlayer. If I understand correctly, after this PR, we can just set AudioStreamPolyphonic which is made by AnimationPlayer/Tree internally to AudioStreamPlayer once. Then AnimationPlayer/Tree will handle the AudioStreamPolyphonic via AudioStreamPolyphonicPlayback to play multiple streams. @reduz Is it right? If no problem, I will try to work on it later. |
@TokageItLab that sounds great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have been explained this implementation at ContributorsChat and I think that it seems there is no missing for solving #69758.
After this is merged, AnimationPlayer and AnimationTree will need to be changed to use this.
…from code * This new audio stream allows to play multiple sounds and control them over time from code. * It greatly simplifies tasks such as generative music (music generated from code) or audio. This new type of stream was added with the goal of fixing audio blending in AnimationPlayer and AnimationTree, but can be used by others for their regular audio needs. Does not fix anything currently, but should help implement godotengine#69758 properly. Some demo code of how to use this: ```GDScript var player = $SomeNode as AudioStreamPlayer player.stream = AudioStreamPolyphonic.new() var playback = player.get_stream_playback() as AudioStreamPlaybackPolyphonic var id = playback.play_stream(preload("res://Clip1.ogg")) await get_tree().create_timer(1).timeout playback.set_stream_volume(id,-12) # Set volume to half after one second await get_tree().create_timer(2).timeout var id2 = playback.play_stream(preload("res://Clip2.ogg")) # 2 seconds later, start another clip await get_tree().create_timer(1).timeout playback.stop_stream(id) # 1 second later, kill the first clip playback.set_stream_pitch_scale(id2,1.5) # Make the second clip go 50% faster ```
b77a533
to
f18d408
Compare
Thanks! |
This new type of stream was added with the goal of fixing audio blending in AnimationPlayer and AnimationTree, but can be used by others for their regular audio needs.
Does not fix anything currently, but should help implement #69758 properly.
Some demo code of how to use this: