sound panning 360 degrees in BGT working example and code

2016-06-02 Thread AudioGames . net Forum — Developers room : sneak via Audiogames-reflector


  


sound panning 360 degrees in BGT working example and code

So, going to try this again. The previous code was rittled with mathematical errors, woops. Anyway, everything is fixed and I went ahead and commented out the function, if you don't understand sine cosine and arc_tangent, it won't help you much though, but it works now, I promise! void thetaPos(double soundA, double soundB, sound@ SoundHandle, double myA, double myB, double myTheta){//initialize our variables.double absolutetheta;double relativetheta;double tempH;double tempV;double tVolume;//find the lengths of the triangle we make to find the distance between our listener and the sound.double temp1 = soundA-myA;double temp2 = myB-soundB;double d1=power(temp1, 2);double d2=power(temp2,2);//use distance formuladouble d=square_root(d1+d2);//if the distance we got is less than 75.if(d<75){ //play our sound looped. SoundHandle.play_looped();
  if(temp1==0 && temp2==0) absolutetheta=-1; if(temp2==0) {  if(soundA>myA) absolutetheta=0;  if(soundA<myA) absolutetheta=180; } if(temp2>0) {  absolutetheta=arc_tangent(temp1/temp2); } if(temp2<0) {  absolutetheta=arc_tangent(temp1/temp2)+pi; } absolutetheta = (absolutetheta*180/pi)-90; //Find our relative angle. relativetheta = absolutetheta -myTheta-90; if(relativetheta>359.999) {  relativetheta+=-360; } if(relativetheta<0) {  relativetheta+=360; }if(key_pressed(KEY_J)){alert("absolute", absolutetheta);}if(key_pressed(KEY_K)){alert("relative", relativetheta);} //Cosine is adgacent tempH=cosine(((relativetheta-90)*pi/180)); //Use the value from above to pan our sound. SoundHandle.pan=tempH*
 100; //Find our verticle measurement. Don't need to convert this one, <0 is in front, > is behind. tempV=sine(((relativetheta-90)*pi/180)); tVolume=(d*-100)/75; //if our sound is behind us. if(tempV>0) {  //Reduce the sound by a number between 0 and 10 based on how far to the left or right the sound is.  SoundHandle.volume=tVolume-5-(absolute(tempH)*20);  //Find the absolute value of our horizontal value and use that to pitch bend our sound as it pans across the stereo field. As the sound moves away from 0 (centered). it will gradually decrease in pitch, as it approaches centered, it will raise in pitch.   SoundHandle.pitch=100+absolute(tempH*5); } else {  //Same as above, except raise the pitch as the sound is centered rather than decrease.  SoundHandle.volume=tVolume+15-(absolute(tempH)*20);   SoundHandle.pitch=120-absolute(te
 mpH*20); }}else{ //If the distance is greater than 75 pause the sound. SoundHandle.pause();}}Here's the example.const double pi=3.141592653589793;double x=0;double degrees=270;double y=0;double soundx=10;double soundy=10;sound test;void main(){show_game_window("test");test.load("sounds/EnemyTeamMate.ogg");test.play_looped();do{if(key_pressed(KEY_S)){degrees-=180;}if(key_pressed(KEY_SPACE)){alert("HI", degrees);}if(key_down(KEY_RIGHT)){degrees+=.2;}if(key_down(KEY_LEFT)){degrees+=-.2;}if(degrees>359.95){degrees=0;}if(degrees<0){degrees=359.95;}thetaPos(soundx, soundy, test, x, y, degrees);wait(5);}while(!key_pressed(KEY_ESCAPE));}Anyway, sorry for posting a dud earlier. This has been tested, please let me know if you find anything wrong with it.

URL: http://forum.audiogames.net/viewtopic.php?pid=262623#p262623





___
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector

sound panning 360 degrees in BGT working example and code

2016-06-01 Thread AudioGames . net Forum — Developers room : sneak via Audiogames-reflector


  


sound panning 360 degrees in BGT working example and code

So, going to try this again. The previous code was rittled with mathematical errors, woops. Anyway, everything is fixed and I went ahead and commented out the function, if you don't understand sine cosine and arc_tangent, it won't help you much though, but it works now, I promise?void thetaPos(double soundA, double soundB, sound@ SoundHandle, double myA, double myB, double myTheta){//initialize our variables.double absolutetheta;double relativetheta;double tempH;double tempV;double tVolume;//find the lengths of the triangle we make to find the distance between our listener and the sound.double temp1 = soundA-myA;double temp2 = myB - soundB;double d1=power(temp1, 2);double d2=power(temp2,2);//use distance formuladouble d=square_root(d1+d2);//if the distance we got is less than 75.if(d<75){//play our sound looped.SoundHandle.play_looped();//If 
 our bottom leg, or the adjacent leg is to our right.if(temp1>0){//Find the longer leg and divide it by the shorter.if(temp2>temp1){absolutetheta=arc_tangent(temp2/temp1);}else{absolutetheta=arc_tangent(temp1/temp2);}}//If our adjacent leg is to our left.else if(temp1<0) {//Find the longer leg and divide it by the shorter.if(temp2>temp1){absolutetheta=arc_tangent(temp2/temp1)-90;}else{absolutetheta=arc_tangent(temp1/temp2)-90;}}//if our adjacent leg is 0, I.E, our X coords are equal to our sound's X coords.else if(temp1 == 0){//Find the longer leg and divide it by the shorter.  if (temp2 > 0){absolutetheta=90;}else if(temp2<0){absolutetheta=-90;}  else if (temp2 == 0){absolutetheta=-1;}}//Convert R
 adians to degreesabsolutetheta=absolutetheta*(180 /pi);//Find our relative angle.relativetheta = absolutetheta -myTheta-180;//Cosine is adgacenttempH=cosine((relativetheta*pi/180));//Use the value from above to pan our sound.SoundHandle.pan=tempH*100;//Find our verticle measurement. Don't need to convert this one, <0 is in front, > is behind.tempV=sine((relativetheta*pi/180));tVolume=(d*-100)/75;//if our sound is behind us.if(tempV>0){//Reduce the sound by a number between 0 and 10 based on how far to the left or right the sound is.SoundHandle.volume=tVolume-(absolute(tempH)*1000/100);//Find the absolute value of our horizontal value and use that to pitch bend our sound as it pans across the stereo field. As the sound moves away from 0 (centered). it will gradually decrease in pitch, as it approaches centered, it will raise in pitch. SoundHandle.pitch=80+absolute(temp
 H*5);}else{//Same as above, except raise the pitch as the sound is centered rather than decrease.SoundHandle.volume=tVolume-(absolute(tempH)*1000/100); SoundHandle.pitch=120-absolute(tempH*20);}}else{//If the distance is greater than 75 pause the sound.SoundHandle.pause();}}Here's the example.const double pi=3.141592653589793;double x=0;double degrees=270;double y=0;double soundx=10;double soundy=10;sound test;void main(){show_game_window("test");test.load("sounds/EnemyTeamMate.ogg");test.play_looped();do{if(key_pressed(KEY_S)){degrees-=180;}if(key_pressed(KEY_SPACE)){alert("HI", degrees);}if(key_down(KEY_RIGHT)){degrees+=.2;}if(key_down(KEY_LEFT)){degrees+=-.2;}if(degr
 ees>359.95){degrees=0;}if(degrees<0){degrees=359.95;}thetaPos(soundx, soundy, test, x, y, degrees);wait(5);}while(!key_pressed(KEY_ESCAPE));}Anyway, sorry for posting a dud earlier. This has been tested, please let me know if you find anything wrong with it.

URL: http://forum.audiogames.net/viewtopic.php?pid=262623#p262623





___
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector

sound panning 360 degrees in BGT working example and code

2016-06-01 Thread AudioGames . net Forum — Developers room : sneak via Audiogames-reflector


  


sound panning 360 degrees in BGT working example and code

So, going to try this again. The previous code was rittled with mathematical errors, woops. Anyway, everything is fixed and I went ahead and commented out the function, if you don't understand sine cosine and arc_tangent, it won't help you much though, but it works now, I promise?void thetaPos(double soundA, double soundB, sound@ SoundHandle, double myA, double myB, double myTheta){//initialize our variables.double absolutetheta;double relativetheta;double tempH;double tempV;double tVolume;//find the lengths of the triangle we make to find the distance between our listener and the sound.double temp1 = soundA-myA;double temp2 = myB - soundB;double d1=power(temp1, 2);double d2=power(temp2,2);//use distance formuladouble d=square_root(d1+d2);//if the distance we got is less than 75.if(d<75){//play our sound looped.SoundHandle.play_looped();//If 
 our bottom leg, or the adjacent leg is to our right.if(temp1>0){//Find the longer leg and divide it by the shorter.if(temp2>temp1){absolutetheta=arc_tangent(temp2/temp1);}else{absolutetheta=arc_tangent(temp1/temp2);}}//If our adjacent leg is to our left.else if(temp1<0) {//Find the longer leg and divide it by the shorter.if(temp2>temp1){absolutetheta=arc_tangent(temp2/temp1)-90;}else{absolutetheta=arc_tangent(temp1/temp2)-90;}}//if our adjacent leg is 0, I.E, our X coords are equal to our sound's X coords.else if(temp1 == 0){//Find the longer leg and divide it by the shorter.  if (temp2 > 0){absolutetheta=90;}else if(temp2<0){absolutetheta=-90;}  else if (temp2 == 0){absolutetheta=-1;}}//Convert d
 egrees to Radians.absolutetheta=absolutetheta*(180 /pi);//Find our relative angle.relativetheta = absolutetheta -myTheta-180;//Cosine is adgacenttempH=cosine((relativetheta*pi/180));//Use the value from above to pan our sound.SoundHandle.pan=tempH*100;//Find our verticle measurement. Don't need to convert this one, <0 is in front, > is behind.tempV=sine((relativetheta*pi/180));tVolume=(d*-100)/75;{}//if our sound is behind us.if(tempV>0){//Reduce the sound by a number between 0 and 10 based on how far to the left or right the sound is.SoundHandle.volume=tVolume-(absolute(tempH)*1000/100);//Find the absolute value of our horizontal value and use that to pitch bend our sound as it pans across the stereo field. As the sound moves away from 0 (centered). it will gradually decrease in pitch, as it approaches centered, it will raise in pitch. SoundHandle.pitch=
 80+absolute(tempH*5);}else{//Same as above, except raise the pitch as the sound is centered rather than decrease.SoundHandle.volume=tVolume-(absolute(tempH)*1000/100); SoundHandle.pitch=120-absolute(tempH*20);}}else{//If the distance is greater than 75 pause the sound.SoundHandle.pause();}}Here's the example.const double pi=3.141592653589793;double x=0;double degrees=270;double y=0;double soundx=10;double soundy=10;sound test;void main(){show_game_window("test");test.load("sounds/EnemyTeamMate.ogg");test.play_looped();do{if(key_pressed(KEY_S)){degrees-=180;}if(key_pressed(KEY_SPACE)){alert("HI", degrees);}if(key_down(KEY_RIGHT)){degrees+=.2;}if(key_down(KEY_LEFT)){degrees+=-.2;}if(degrees>359.95){degrees=0;}if(degrees<0){degrees=359.95;}thetaPos(soundx, soundy, test, x, y, degrees);wait(5);}while(!key_pressed(KEY_ESCAPE));}Anyway, sorry for posting a dud earlier. This has been tested, please let me know if you find anything wrong with it.

URL: http://forum.audiogames.net/viewtopic.php?pid=262623#p262623





___
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector

sound panning 360 degrees in BGT working example and code

2016-06-01 Thread AudioGames . net Forum — Developers room : sneak via Audiogames-reflector


  


sound panning 360 degrees in BGT working example and code

So, going to try this again. The previous code was rittled with mathmatical errors, woops. Anyway, everything is fixed and I went ahead and commented out the function, if you don't understand sine cosine and arc_tangent, it won't help you much though, but it works now, I promise?void thetaPos(double soundA, double soundB, sound@ SoundHandle, double myA, double myB, double myTheta){//initialize our variables.double absolutetheta;double relativetheta;double tempH;double tempV;double tVolume;//find the lengths of the triangle we make to find the distance between our listener and the sound.double temp1 = soundA-myA;double temp2 = myB - soundB;double d1=power(temp1, 2);double d2=power(temp2,2);//use distance formuladouble d=square_root(d1+d2);//if the distance we got is less than 75.if(d<75){//play our sound looped.SoundHandle.play_looped();//If o
 ur bottom leg, or the adjacent leg is to our right.if(temp1>0){//Find the longer leg and divide it by the shorter.if(temp2>temp1){absolutetheta=arc_tangent(temp2/temp1);}else{absolutetheta=arc_tangent(temp1/temp2);}}//If our adjacent leg is to our left.else if(temp1<0) {//Find the longer leg and divide it by the shorter.if(temp2>temp1){absolutetheta=arc_tangent(temp2/temp1)-90;}else{absolutetheta=arc_tangent(temp1/temp2)-90;}}//if our adjacent leg is 0, I.E, our X coords are equal to our sound's X coords.else if(temp1 == 0){//Find the longer leg and divide it by the shorter.  if (temp2 > 0){absolutetheta=90;}else if(temp2<0){absolutetheta=-90;}  else if (temp2 == 0){absolutetheta=-1;}}//Convert de
 grees to Radians.absolutetheta=absolutetheta*(180 /pi);//Find our relative angle.relativetheta = absolutetheta -myTheta-180;//Cosine is adgacenttempH=cosine((relativetheta*pi/180));//Use the value from above to pan our sound.SoundHandle.pan=tempH*100;//Find our verticle measurement. Don't need to convert this one, <0 is in front, > is behind.tempV=sine((relativetheta*pi/180));tVolume=(d*-100)/75;{}//if our sound is behind us.if(tempV>0){//Reduce the sound by a number between 0 and 10 based on how far to the left or right the sound is.SoundHandle.volume=tVolume-(absolute(tempH)*1000/100);//Find the absolute value of our horizontal value and use that to pitch bend our sound as it pans across the stereo field. As the sound moves away from 0 (centered). it will gradually decrease in pitch, as it approaches centered, it will raise in pitch. SoundHandle.pitch=8
 0+absolute(tempH*5);}else{//Same as above, except raise the pitch as the sound is centered rather than decrease.SoundHandle.volume=tVolume-(absolute(tempH)*1000/100); SoundHandle.pitch=120-absolute(tempH*20);}}else{//If the distance is greater than 75 pause the sound.SoundHandle.pause();}}Here's the example.const double pi=3.141592653589793;double x=0;double degrees=270;double y=0;double soundx=10;double soundy=10;sound test;void main(){show_game_window("test");test.load("sounds/EnemyTeamMate.ogg");test.play_looped();do{if(key_pressed(KEY_S)){degrees-=180;}if(key_pressed(KEY_SPACE)){alert("HI", degrees);}if(key_down(KEY_RIGHT)){degrees+=.2;}if(key_down(KEY_LEFT)){degrees+=-.2;<br /
 >}if(degrees>359.95){degrees=0;}if(degrees<0){degrees=359.95;}thetaPos(soundx, soundy, test, x, y, degrees);wait(5);}while(!key_pressed(KEY_ESCAPE));}Anyway, sorry for posting a dud earlier. This has been tested, please let me know if you find anything wrong with it.

URL: http://forum.audiogames.net/viewtopic.php?pid=262623#p262623





___
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector