sound loop

Posted By: Marky Mark

sound loop - 03/05/07 19:30

Hey,

Here's my rain sound function. I want to start a loop in a certain moment, so i placed the snd_loop in a function that will be called later...

here it is:

Code:

function rain_play()
{
if (snd_playing(rainloopnice) == 1)
{
wait(1);
}
if (snd_playing(rainloopnice) == 0)
{
snd_loop (rainloopnice, 80, 0);
}
}



Heres my other function, the one that calls rain_play()

Code:

while(1)
{
if (vec_dist(my.x, player.x) < my.skill1)
{
if (ObservationConditions == ocAverage)
{
rainit();
rain_play();
}
if (ObservationConditions == ocGood)
{
rainit();
rain_play();
}
}
else
{
// No Rain...
}
wait(1);
}
Code:


When I run my game, it works, but it seems like the sound is playing 200 times
so it looks like a robotic rain sound mixed with a "your computer will crash soon" .. any ideas? thanks
Posted By: Xarthor

Re: sound loop - 03/05/07 20:26

I guess "rainloopnice" is a sound defined this way:
sound rainloopnice = <source.fileType>; ?

If yes:
snd_playing() is expecting a handle of a sound, not the sound itself.
You need to define a var which stores the handle to that sound:
Code:

var rainloop_handle;
//...
if(snd_playing(rainloop_handle))
{
return;
}
else
{
rainloop_handle = snd_loop(rainloopnice,80,0);
}
//...


Posted By: Marky Mark

Re: sound loop - 03/05/07 20:50

Yeah its defined this way. I'll give a try. thanks
Posted By: Marky Mark

Re: sound loop - 03/05/07 21:26

Thanks it works!!

Now, to stop it, i just have to do snd_stop(handle) ?
Posted By: Marky Mark

Re: sound loop - 03/05/07 22:40

I want to stop the rain sound and my particle effect when i'm out of the distance... it won't work.. look at my code:

Thanks to help!

bmap rainitBmap = <drop.tga>;
VAR rainitAnzahlPartikel = 9; //number of particles used for this effect
sound rainloopnice = <rainl.wav>;
var rainturnoff = 0;



Function rainit_spec_fun()
{
my.alpha -= -13.770 *time;
IF(My.alpha < 0) { my.alpha = 0; my.lifespan = 0; }
my.skill_b += 0.03;
my.skill_c = 6 - my.skill_b;
if(my.skill_c < 0) { my.lifespan = 0; }
if (rainturnoff == 1) { my.lifespan = 0; }
}

Function rainitspezial()
{
my.blue = 128 ;
my.green = 128 ;
my.red = 128 ;
my.skill_c = 0; my.skill_b = 0;
my.bmap = rainitBmap; //the effect bitmap
my.vel_x = random( 0 ) - 0 ;
my.vel_y = random( 0 ) - 0 ;
my.vel_z = -40 ;
my.size = 14 ;
my.alpha = 46.375 ;
my.x += random(5000)-500; //2000 2000 500
my.y += random(5000)-500;
my.z += random(2000)-50;
my.gravity = 0 ;
my.streak = off;
my.flare = on;
my.bright = on;
my.beam = off;
my.move = on;
my.transparent = on;
my.function = rainit_spec_fun;
}


Function rainit()
{
while(1)
{
rainitAnzahlPartikel = 38;
var myPos[3];
vec_set(myPOS,camera.x);
temp.x = COS(camera.pan);
temp.y = SIN(camera.pan);
temp.Z = 600*COS(camera.tilt);
MyPos.X = myPos.X + temp.Z*temp.X;
MyPos.Y = myPos.Y + temp.Z*temp.Y;;
MyPos.Z = myPos.Z + 600*SIN(camera.TILT); //600
MyPos.Z = Camera.Z + 800; //800
effect(rainitspezial,max(1,int(rainitAnzahlPartikel*time)),MyPOS,nullvector);
wait(1);
}
}






var rainloop_handle;

action rainthatshit
{
// Range to scan for rain...
my.skill1 = 4000;
//
while(1)
{
if (vec_dist(my.x, player.x) < my.skill1)
{
if (ObservationConditions == ocAverage)
{
rainit();
if(snd_playing(rainloop_handle))
{
return;
}
else
{
rainloop_handle = snd_loop(rainloopnice,15,0);
rainturnoff = 0;
}
}
if (ObservationConditions == ocGood)
{
rainit();
if(snd_playing(rainloop_handle))
{
return;
}
else
{
rainloop_handle = snd_loop(rainloopnice,15,0);
rainturnoff = 0;
}
}
}
else
{
stopit();
}
wait(1);
}
}

function stopit()
{
snd_stop(rainloop_handle);
rainturnoff = 1;
}

Posted By: xXxGuitar511

Re: sound loop - 03/06/07 00:29

Take out the while(1) out of rain_init().

This is causing it to keep running
Posted By: Marky Mark

Re: sound loop - 03/06/07 15:43

First, it's rainit() , and i tried, but when i remove the while(1), i can see that it starts raining for a first bunch of particles, but then after those particles, nothing. So i guess i have to place the while(1) in this function, but maybe there's something else to add to the function if i want to stop it when i'm outside the distance of the cloud?
Posted By: Marky Mark

Re: sound loop - 03/06/07 15:49

also, my rain sound won't stop ... i dont know why.. maybe the distance scan is not doing his job?
Posted By: xXxGuitar511

Re: sound loop - 03/06/07 16:01

I'm leaving in 2 minutes, but when I get home I'll check out your code. The problems something small, I just need to see where. The while() needs to be removed from rainit() though.
Posted By: Marky Mark

Re: sound loop - 03/06/07 16:06

check out you pm's
© 2023 lite-C Forums