Changing the pitch of a sound played via the SamplePlayer2D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robster
:warning: Old Version Published before Godot 3 was released.

Hi all,

I want to change the pitch of a sound each time it’s played, so it increments.

I had a look at the docs and came across voice_set_pitch_scale but after some playing can’t seem to fully understand how it works enough to actually make it work. :-/

Has anyone had any experience with it? I’ve tried things like:


…but can hear no difference.

Any advice would be greatly appreciated.

:bust_in_silhouette: Reply From: Robster

OK I figured it out, I’ll put it here to help someone in the future. The key point is the pitch scale change changes the currently PLAYING sound, so it must be used after the play command.

I now have this:'success01')

Basically in voice_set_pitch_scale(0,1.2) the first argument (which I have as 0) is the index of the sound that’s playing, so in my case, the first (and only) sound.

The second argument, which I’m testing with 1.2 is the scale change, so 20% higher in this case.

I hope that helps someone in the future.

Almost exactly a year later…one addendum about that first argument :slight_smile: To be more robust you should say:

var voice ='success01')
soundSamplePlayer.voice_set_pitch_scale(voice, 1.2)

(You can also set the relative volume using voice_set_volume_scale_db)

Max Aller | 2017-10-21 21:06