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

AudioStreamRandomPitch doesn't play correct sounds when instanced fast #48354

Open
Tracked by #76797
jkulawik opened this issue May 1, 2021 · 2 comments
Open
Tracked by #76797

Comments

@jkulawik
Copy link

jkulawik commented May 1, 2021

Godot version: 3.3

OS/device including version: Windows 7

Issue description:
When instancing AudioStreamPlayer3D that use AudioStreamRandomPitch as their stream, and then trying to assign different audio streams to the AudioStreamRandomPitch.stream fields, they play the same sound when instanced within the same function call.

I am using set-up similar to the minimal reproduction project one in a bigger project. It never caused any issues when the nodes were instanced in separate function calls. When directly changing the AudioStreamPlayer3D.stream property to an AudioStream, this bug doesn't occur.

Steps to reproduce:
Open the minimal reproduction project and run it. You should hear only one sound, but played twice (sounds a bit like a delay effect).

To see that the instances behave as intended when instanced slowly, do this: In main.gd, comment out one of the instance_audio function calls and restart the program to hear the singular sound. You can do the same with both sounds.

To see that the bug doesn't occur when changing the AudioStreamPlayer3D.stream property directly, uncomment the only commented line in AudioPlayer.gd and comment out the one above it, then restart the program .

Minimal reproduction project:
MinimalReproductionProject.zip

@Calinou
Copy link
Member

Calinou commented May 1, 2021

As a workaround, use an AutoLoad that creates new AudioStreamPlayer nodes with random pitch properties and frees the nodes as needed: https://github.com/Calinou/escape-space/blob/master/autoload/sound.gd

This also allows for polyphony (playing multiple sounds at the same time).

@jkulawik
Copy link
Author

jkulawik commented May 2, 2021

Thanks, that's a very elegant workaround so I'll run with it! Honestly I feel silly for not coming up with it myself ;P

PS. Just in case and to be clear, in the example the instanced nodes are freed

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

2 participants