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

AudioPlaybackTrack forces unwanted polyphony and bypasses AudioStreamPlayer3D's max_polyphony limit. #83797

Open
Tracked by #76797
KnightNine opened this issue Oct 22, 2023 · 5 comments

Comments

@KnightNine
Copy link

KnightNine commented Oct 22, 2023

Godot version

4.X

System information

Windows 10

Issue description

I have a looping animation, I want the sound (AudioPlaybackTrack) within that animation to loop when the animation loops.
But if the end_offset of the audio clip exists outside the animation length the audio is not stopped and then overlaps with itself, and it it's practically impossible to set the end_offset to the very end of the animation length.
(Because the adjusting end_offset value manually to get the exact endpoint of the animation using the sound length and the animation length values is finnicky. I also can't snap the end offset to anything by dragging it in the timeline either.)

That aside, this sound overlapping shouldn't even happen anyways if the max_polyphony property of the AudioStreamPlayer3D being used by the audio track is set to 1. It should only be able to play one sound at a time so it should cut the last sound being played when the loop restarts to begin the sound again.


Note:

When the AudioPlaybackTrack makes the AudioStreamPlayer3D play a sound it creates and adds an "AudioStreamPolyphonic" resource to it, I assume that this resource ignores the max_polyphony property of the AudioStreamPlayer.

Steps to reproduce

  • create an AudioStreamPlayer3D and an AnimationPlayer in your scene.
  • create an animation and select the looping button.
  • add an Audio Playback Track to it that is connected to the AudioStreamPlayer3D
  • import and add a sound file to the Audio Playback Track that is longer than the length of the animation
  • set AudioStreamPlayer3D max_polyphony to 1
  • play the animation.

The audio should continue to play and overlap with itself even after the loop ends.

Minimal reproduction project

To be added if necessary.

@TokageItLab
Copy link
Member

TokageItLab commented Oct 23, 2023

Is it just an AudioPlaybackTrack issue, or does this issue also occur when using AudioStreamPolyphonic directly? It is needed to isolate the problem.

If it is the latter, I think it is more of an audio side issue, since on the AnimationMixer side we have set audio_max_polyphony for the audio stream.

In any case, it needs to be tested.

@KnightNine
Copy link
Author

@TokageItLab
tested this code, the issue relates to the AudioStreamPolyphonic directly:

@onready var player:AudioStreamPlayer = get_node("AudioStreamPlayer")
@onready var sound = preload("res://Objective Beam Idle.ogg")
@onready var sound2 = preload("res://Hiss.ogg")


func _ready():
	player.stream = AudioStreamPolyphonic.new()
	player.playing = true
	await get_tree().create_timer(1).timeout
	
	
	print(player.stream)
	var playback = player.get_stream_playback() as AudioStreamPlaybackPolyphonic
	var id = playback.play_stream(sound)
	await get_tree().create_timer(1).timeout
	var id2 = playback.play_stream(sound2) # 1 second later, start another clip
	await get_tree().create_timer(1).timeout
	

max_polyphony is ignored by AudioStreamPolyphonic

@MJacred
Copy link
Contributor

MJacred commented Dec 28, 2023

@KnightNine: could you test #86054, please? Your issue of accidental sound overlapping reminds me of #86053

@KnightNine
Copy link
Author

KnightNine commented Jun 7, 2024

@MJacred Tested #86054 , the issue persists.

@KnightNine
Copy link
Author

KnightNine commented Aug 25, 2024

Just wondering how do I add looping audio to a looping animation (like an in game generator or radio where the noise needs to be constant) if this functionality doesn't work? Is there a workaround in 4.2 or 4.3?

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

3 participants