Jump to content

Need help with Sound at random intervals.


iCade
 Share

You are about to reply to a thread that has been inactive for 3888 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Good Morning! I would like for a creepy sound to be played at random intervals ranging from at least a 15 second silence to up to a 2 minute silence.

here's the current script, I am entirely unsure which time values to change to get the desired effect. Testing it for the past 15 minutes no matter what I do, it doesn't have a random feel to it like I want it to.

 

float time = 15.0;
default
{
state_entry()
{
llSetTimerEvent(10.0);
}
 
timer()
{
llSetTimerEvent(0.0);
llPlaySound("UUID",0.5);
llSetTimerEvent(10.0+llFrand(time));
}
}

 Any pointers would be much appreciated!!

Link to comment
Share on other sites

Good Morning! I would like for a creepy sound to be played at random intervals ranging from at least a 15 second silence to up to a 2 minute silence.

here's the current script, I am entirely unsure which time values to change to get the desired effect. Testing it for the past 15 minutes no matter what I do, it doesn't have a random feel to it like I want it to.

 

float time = 15.0;
default
{
state_entry()
{
llSetTimerEvent(10.0);
}
 
timer()
{
llSetTimerEvent(0.0);
llPlaySound("UUID",0.5);
llSetTimerEvent(10.0+llFrand(time));
}
}

 Any pointers would be much appreciated!!

Link to comment
Share on other sites

We could start by setting the timer values according to your "15 second silence to up to a 2 minute silence", but to do that precisely, we'd need to know how long the sound itself lasts.

For now, let's pretend it lasts 10 seconds.

So, the minimum amount of time between sound starts would be that 10 second sound duration plus the 15 second minimum silent interval, or 25 seconds.

A maximum silent time of 2 minutes means that the maximum time between sound starts must be the sound duration (assumed to be 10 seconds) plus 120 seconds (2 minutes), so that's 130 seconds. And 130 seconds is 105 seconds more than the 25 second minimum, so you could try

float time = 105.0;

and, in the timer() handler

llSetTimerEvent(25.0+llFrand(time));

Now, I'm guessing that you may want to redo this math with a shorter minimum silence than 15 seconds, but that's up to you. If it still doesn't "feel random", though, it may be that the uniform distribution just doesn't fit the natural occurrence of these events... but then we have somewhat more math to do.

  • Like 1
Link to comment
Share on other sites

Sorry was an error, think i got it sorted.

// randomly picks a sound in inventory, plays it,// waits a random interval, repeats.//// Set this between 0.0 and 1.0float LOUDNESS 	= 1.0;//// Interval in seconds to be silent.// If you set these to be less than 10 seconds,// they default to 10 seconds.integer SHORTEST 	= 15;integer LONGEST 	= 120;integer on = FALSE ;integer DOUBLE_TOUCH_INTERVAL = 1;integer gi_last_touch_time;switch(){	if ( on == TRUE )	{		on = FALSE;		llResetScript();	}	else	{		on = TRUE;		llSetTimerEvent(1.0);	}}default{	state_entry()	{		if (SHORTEST < 10 )     SHORTEST = 10;		if (LONGEST < 10 )      LONGEST = 10;		if (SHORTEST > LONGEST) SHORTEST = LONGEST;		llStopSound();		llSleep( 1.0 );	}	on_rez(integer start_param)	{		llSleep( 1.0 );	}	touch_start(integer not )	{		integer tt = llGetUnixTime();		if(llDetectedKey(0)==llGetOwner())		{			if( tt - gi_last_touch_time <= DOUBLE_TOUCH_INTERVAL )			{				switch();			}			gi_last_touch_time = tt;		}	}	timer()	{		state noisy;	}}state noisy{	state_entry()	{		integer on = TRUE ;		integer sounds = llGetInventoryNumber(INVENTORY_SOUND);		if ( sounds <= 0 ) state default;		string soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(sounds)) );		if ( soundname != "" )		{			llPlaySound( soundname, LOUDNESS );		}		state silent;	}	on_rez(integer start_param)	{		state default;	}	touch_start(integer not )	{		integer tt = llGetUnixTime();		if(llDetectedKey(0)==llGetOwner())		{			if( tt - gi_last_touch_time <= DOUBLE_TOUCH_INTERVAL )			{				switch();			}			gi_last_touch_time = tt;		}	}}state silent{	state_entry()	{     integer on = TRUE ;			llSetTimerEvent( (float)(llFloor(llFrand(LONGEST - SHORTEST)) + SHORTEST) );		}	timer()	{		state noisy;	}	on_rez(integer start_param)	{		state default;	}	touch_start(integer not )	{		integer tt = llGetUnixTime();		if(llDetectedKey(0)==llGetOwner())		{			if( tt - gi_last_touch_time <= DOUBLE_TOUCH_INTERVAL )			{				switch();			}			gi_last_touch_time = tt;		}	}}

 

  • Like 1
Link to comment
Share on other sites


iCade wrote:

Good Morning! I would like for a creepy sound to be played at random intervals ranging from at least a 15 second silence to up to a 2 minute silence.

here's the current script, I am entirely unsure which time values to change to get the desired effect. Testing it for the past 15 minutes no matter what I do, it doesn't have a random feel to it like I want it to.

 
float time = 15.0;

default

{

state_entry()

{

llSetTimerEvent(10.0);

}

 

timer()

{

llSetTimerEvent(0.0);

llPlaySound("UUID",0.5);

llSetTimerEvent(10.0+llFrand(time));

}

}

 

 Any pointers would be much appreciated!!

Qie's (correct) approach would be coded as:

// length the sound playsfloat soundLength = 10.0;// minimum silence lengthfloat minTime = 15.0;// maximum silence lengthfloat maxTime = 120.0;default{	state_entry()	{		llSetTimerEvent(10.0);	} 	timer()	{		llSetTimerEvent(0.0);		llPlaySound("UUID",0.5);		llSetTimerEvent(soundLength + minTime + llFrand(maxTime - minTime)); 	}}

 That gives you the 3 variables at the top to adjust until it has the spooky effect you want.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3888 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...