stechyo / godot-steam-audio

Immersive spatial audio extension for Godot, using Valve's SteamAudio
MIT License
347 stars 9 forks source link

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

Open H2xDev opened 1 month ago

H2xDev commented 1 month ago

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 commented 1 month ago

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 commented 3 weeks ago

@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 commented 3 weeks ago

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 commented 3 weeks ago

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.