Function to perform pitch bending on a sound in BGT

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.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : gabriel-schuck via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : gabriel-schuck via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : keithwipf1 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : mahdi-abedi via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : gabriel-schuck via Audiogames-reflector

Reply via email to