0 votes

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:

soundSamplePlayer.voice_set_pitch_scale(100,100)
soundSamplePlayer.play('success01')

...but can hear no difference.

Any advice would be greatly appreciated.

in Engine by (810 points)

1 Answer

+2 votes
Best answer

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:

soundSamplePlayer.play('success01')
soundSamplePlayer.voice_set_pitch_scale(0,1.2)

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.

by (810 points)

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

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

(You can also set the relative volume using voice_set_volume_scale_db)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories