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 keyframe is silent if the AudioClip starts at an negative time position #85088

Closed
Tracked by #83401 ...
carringtonevent opened this issue Nov 19, 2023 · 4 comments · Fixed by #86661
Closed
Tracked by #83401 ...

Comments

@carringtonevent
Copy link

carringtonevent commented Nov 19, 2023

Godot version

v4.2.rc1.mono.official [ad72de5]

System information

Godot v4.2.rc1.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated GeForce GTX 1070 () - Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz (12 Threads)

Issue description

4.1 Behaviour: If an AudioClip is positioned at an negative number inside the animation player. The Audio plays Exact at the 0 position.

Screenshot 2023-11-19 150448

4.2 Behaviour: The clip is silence if played. Also if played by the play button of the animation player

This bug is not critical because it can be worarround by cutting the animation clip inside the player so it does not need to be positioned at an negative number. But on large projects it requirest many refactors.

Steps to reproduce

Create an Scene with an AnimationPlayer Node and an AudioStreamPlayer Node.
Create a new Animation.
Drag and Drop an Audio File inside the animation player and place its start below zero.
In my Case the Audio file was mp3

Minimal reproduction project

NA, Because i did not know how to upload it. But it is easy to reproduce

@TokageItLab
Copy link
Member

TokageItLab commented Nov 26, 2023

To be precise, since 4.2, if the current position is in the middle of an audio track key, there is no longer the ability to playback the key currently on it during playback. Probably this was the case with AnimationTree prior to 4.2.

BTW, The behavior of AudioTrack and AnimationPlaybackTrack is very similar; They are basically based on the "firing playback at the beginning of the key" feature.

Since before 4.2, AnimationPlaybackTrack does not handle playback from the middle of the key, but only for AudioTrack , the playback in the middle of the key feature was hard-coded into AnimationPlayer, but now AudioTrack has followed AnimationPlaybackTrack and this problem has occurred.

In order to handle playback from the middle of the tracks correctly, the algorithm for retrieving those keys will need to be reworked, which will take a bit of time.

What could be implemented immediately would be a trimming shortcut such as

  • [: move the in point of the key to current position
  • ]: move the out point of the key to current position
  • Alt + [: set start offset
  • Alt + ]: set end offset

to set the offset immediately. This would provide a workaround to allow the user to easily set the offset by selecting a key with a negative position and trimming it with the current position set to 0.

@amberlandeveloper
Copy link

Well this was very annoying. Happened to be working on a project that relied heavily on being able to play certain sections of AudioTracks at certain keyframes, and now it seems like I will be unable to continue my project because I have made progress in the 4.2 version and the 4.2 project is not backwards compatible with the 4.1.3 version.

And it apparently hasn't been fixed within weeks of the stable being released.

@amberlandeveloper
Copy link

amberlandeveloper commented Dec 8, 2023

For those like me who are impatient and require a workaround, editor tool script is here to save the day!

Below is a quick and dirty work around which utilizes the power of @tool and another scene to get an AudioStreamPlayer to run at the position of where your keyframes are in an animationplayer! All you must do is simply choose your animation player node and your audio stream player node, set enabled to true, attach the script to a scene or a node and voila.

Until this gets fixed, this is good enough for me, this is my Hopeful Tool, because I was hopeful that it would work and it did.

@tool
extends Node

@export var animationplayer : NodePath
@export var audiostreamer : NodePath
@export var enabled = true
@export var debug_prints = false

var animationplayernode
var audiostreamernode

var check = false # this is unneccesary but for some reason i feel like its not good to have AudioStreamPlayer.stop()
# run every single frame

func _notification(what):
	if Engine.is_editor_hint():
		match what:
			NOTIFICATION_EDITOR_POST_SAVE:
				if get_node_or_null(animationplayer) != null:
					if get_node_or_null(audiostreamer) != null:
						animationplayernode = get_node(animationplayer)
						audiostreamernode = get_node(audiostreamer)
						# Just to make sure that im not overconnecting it
						for i in animationplayernode.get_signal_connection_list("animation_started"):
							animationplayernode.disconnect("animation_started",i.callable)
							print("Hopeful Tool Signal Info: " + str(i))
						animationplayernode.connect("animation_started", 
						
						func started(animation):
							if enabled:
								check = true
								if Engine.is_editor_hint():
									audiostreamernode.play()
									audiostreamernode.seek(animationplayernode.get_current_animation_position())
								if debug_prints:
									print("Hopeful Tool: Starting Audio Test Track"))
						if debug_prints:
							print("Hopeful Tool has been updated.")

func _process(delta):
	if Engine.is_editor_hint():
		if enabled:
			if animationplayernode != null:
				if !animationplayernode.is_playing():
					if check:
						audiostreamernode.stop()
						if debug_prints:
							print("Hopeful Tool: Audio test track has been stopped.")
						check = false
				pass

@TokageItLab
Copy link
Member

Perhaps in 4.2.1 playback from the middle is temporarily allowed, but that is causing problems and I am not sure what will become of it in 4.2.2.

In conclusion, playback from the middle should be allowed, but negative time keys should not be obtained. I think #86661 should provide the fine workaround possible at this time for this problem.

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