2019-02-12 18:01:10 (edited by gabriel-schuck 2019-02-12 18:05:49)

Hello!
I share with you a function in bgt and that I am using in my game to perform pitch bending on a sound.
It's very simple, follow the code below:

void pitch_bend(sound@ soundfile, double value, string mode, int time){
double original_value=soundfile.pitch;
while (soundfile.playing and value>1 or value>200){
if(mode=="up") value=value+1;
else if (mode=="down") value=value-1;
soundfile.pitch=value;
wait(time);
}
soundfile.pause();
soundfile.pitch=original_value;
soundfile.stop();
}

To test, you can do something like this:

#include "pitchbend.bgt"
sound test;
void main(){
show_game_window ("Pitch bend");
test.load ("filename.wav");
test.play();
wait (5000);
pitch_bend(@test,80,"down",25);
}

Or else:

#include "pitchbend.bgt"
sound test;
void main(){
show_game_window ("Pitch bend");
test.load ("filename.wav");
test.play();
wait (5000);
pitch_bend(@test,test.pitch,"up",50);
}

I hope this is useful.

2019-02-12 20:35:50

Just a hint, it seems that string mode should be bool, since you're only seeming to use it for 2 things.
That's all a bool does, either.

2019-02-12 21:36:49

thanks for this useful coad

2019-02-12 22:53:44

@keithwipf1
Makes sense. Since I made the code a while ago, I had not thought of that at the time. Thanks for remember! lol