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

Sound effects break off and stop working after a while #75

Open
H2xDev opened this issue Oct 11, 2024 · 4 comments
Open

Sound effects break off and stop working after a while #75

H2xDev opened this issue Oct 11, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@H2xDev
Copy link

H2xDev commented Oct 11, 2024

Are you using the provided fork of Godot?
Yes

Godot-steam-audio version
0.2.2

Steam-Audio version
Included in the version i used

Operating System
Windows 11

Describe the bug
Sound effects break off and stop working after a while. To play some sound effects, I instantiate SteamAudioPlayer with parameters at a specified position and remove it after 5 seconds once playback finishes.

Here's a video:
https://github.com/user-attachments/assets/7f42bd76-e2ca-4baf-9e7e-5cda7dce653b

I suppose i could do something wrong here.

Expected behavior
To hear sound effects completely.

Example project, code snippet, or screenshots

## Play a sound at a given position
func play_sound(position: Vector3, sound: AudioStream, volume: float = 1.0, pitch: float = 1.0) -> SteamAudioPlayer:
	var sound_player = SteamAudioPlayer.new();

	get_tree().get_current_scene().add_child(sound_player);

	sound_player.global_transform.origin = position;
	sound_player.attenuation_model = 3;
	sound_player.distance_attenuation = true;
	sound_player.min_attenuation_distance = 0.0;
	sound_player.max_distance = 20.0;
	sound_player.reflection = true;
	sound_player.play_stream(sound, 0.0, linear_to_db(volume), pitch);

	sound_player.finished.connect(func():
		get_tree().create_timer(5.0).timeout.connect(func():
			sound_player.stop();
			sound_player.queue_free();
		);
	);

	return sound_player;

P.S. Thank you for this addon.

@stechyo stechyo added the bug Something isn't working label Oct 12, 2024
@stechyo
Copy link
Owner

stechyo commented Oct 19, 2024

Hi, so it seems like each footstep is cutting off before the sound is done, right? Does the same not happen a regular AudioStreamPlayer3D? Your code looks reasonable at a glance but this kind of issue seems like it would happen in both cases.

BTW, the way I've handled footsteps in my game is for there to be a single player stuck to the player's feet with a single AudioStreamPolyphonic. When you want to play a footstep sound, you just run:

audio_player.get_inner_stream_playback().play_stream(your_footstep_stream)

And you don't have to worry about setting up timers and allocating tons of audio players (sure, doing it like I described means your footsteps are technically moving along with you, but I doubt that anyone will notice).

@H2xDev
Copy link
Author

H2xDev commented Oct 24, 2024

@stechyo Thank you for answer.

Does the same not happen a regular AudioStreamPlayer3D?

No. With AudioStreamPlayer3D it work as expected. The reason i added the timer it that i thought that effect might break because of instant remove the AudioPlayer before the effect performed completely.

BTW, the way I've handled footsteps in my game is for there to be a single player stuck to the player's feet with a single AudioStreamPolyphonic.

It makes sense, but i suppose there's no implemented SteamAudioPlayerPolyphonic yet, right? :)

@stechyo
Copy link
Owner

stechyo commented Oct 24, 2024

There doesn’t need to be a SteamAudioPlayerPolyphonic. You create a SteamAudioPlayer and assign to it an AudioStreamPolyphonic on the editor, or through code. Then when you want to play the streams you use the code in my example.

@H2xDev
Copy link
Author

H2xDev commented Oct 24, 2024

There doesn’t need to be a SteamAudioPlayerPolyphonic. You create a SteamAudioPlayer and assign to it an AudioStreamPolyphonic on the editor, or through code. Then when you want to play the streams you use the code in my example.

Got you. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants