Parallel tween for fading audio not runing on parallel

Godot Version

4.6

Question

Using a StreamAudioPlayer with a Synchronized assigned and two songs (Song A, Song B), I'm trying make a crossfade between those songs using a Tween
The problem is that the crossfade is not simultaneously, it fades out the Song A and after muting it, the Song B starts fading in.

I crossfade calling this function once:

@onready var music_player: AudioStreamPlayer = $MusicPlayer

func set_music(song: int =-1, crossfade: float = 0.0, position: float = -1.0) -> void:
	
	var sync: AudioStreamSynchronized = music_player.stream
	var old_son: int = active_song
	sync.set_sync_stream_volume(song, -80.0)
	
	active_song = song 
	
	var tween: Tween = create_tween()
	
	tween.set_trans(Tween.TRANS_SINE)
	tween.set_ease(Tween.EASE_IN_OUT)
	
	tween.parallel().tween_method( \
	func(v: float) -> void: sync.set_sync_stream_volume(old_son, v), \
	sync.get_sync_stream_volume(old_son), \
	-80.0, crossfade)
	
	tween.parallel().tween_method( \
	func(v: float) -> void: sync.set_sync_stream_volume(song, v), \
	sync.get_sync_stream_volume(song), \
	0.0, crossfade)

AudioStreamSyncronized is used to play all stream at once (same position), you need to use AudioStreamPlaylist and it already have fade time.

The problem must be is sync.get_sync_stream_volume(song) bugged and return -80.0 instead actual volume you set in AudioStreamPlayer for that stream

The thing is that I need them to be synchronized. I have different areas with the same rythm and I variate between them.

I realized that -80 was a lot for fading, so I’ve reduced it to -20 and then reduced it to -80 when the tween was finished

	var sync: AudioStreamSynchronized = music_player.stream
	var old_song: int = active_song
	
	
	active_song = song 
	
	var tween: Tween = create_tween()
	
	tween.set_trans(Tween.TRANS_SINE)
	tween.set_ease(Tween.EASE_IN_OUT)
	
	tween.parallel().tween_method( \
	func(v: float) -> void: sync.set_sync_stream_volume(old_song, v), \
	sync.get_sync_stream_volume(old_song), \
	-10.0, crossfade)
	
	
	tween.parallel().tween_method( \
	func(v: float) -> void: sync.set_sync_stream_volume(song, v), \
	sync.get_sync_stream_volume(song), \
	0.0, crossfade)
	
	await tween.finished
	sync.set_sync_stream_volume(old_song, -80.0)

Thank you for mentioning the sync.get_sync_stream_volume(song)it made me realize it

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.