Change font size
It is currently Sat Dec 15, 2018 1:21 pm

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 2   [ 13 posts ]
Go to page 1, 2  Next
Author Message
 Post subject: Ambient Sound
PostPosted: Mon Apr 27, 2009 2:32 am 

Joined: Mon Apr 27, 2009 1:52 am
Posts: 6
Ok, 1 more before i pop off for bed :) Dunno' about you all but I love those ambient sound effects. Waves crashing, birds chirping, wind blowing. You feeling me yet? lol.

Alrighty! Pretty simple. Set the float parameters the shortest or longest you want it to wait before randomly playing a sound, either put the sound into the object with the script or the preferable way, get the sounds UUID and use that instead (right click copy asset uuid).

{L_CODE}:
// Ambient Sound script by Alfkin Small.

// To use: Place this script in the object that you want to play a sound.
// The object need not be special.  Just place is where you want the sound
// to come from.
// Drop a sound file in the object, then change the key sound line below to
// the name of your sound file.
// If you like, you can set the min and max values as well, in addition to
// the volume.  That's all there is to it!

// Set debug to TRUE if you'd like to get debugging messages, otherwise
// leave the next line alone.
integer debug = FALSE;

// Minimum amount of time (in seconds) between sounds.
float min = 10;

// Maximum amount of time (in seconds) between sounds.
float max = 30;

// This is the volume at which the sound will play.  0 = Inaudible
// Valid values are between 0.0 - 1.0
float vol = 0.5;

// Sound to play.
key sound = "GullsBeach2";

default
{
    state_entry()
    {
        if (debug) llSay(0, "Debugging is ON");
     
        // Set the initial timer
        llSetTimerEvent(5.0);       
    }
    timer()
    {     
        // Play the sound once       
        llPlaySound(sound, vol);
       
        // Randomly select the next time (in seconds) to play the sound.
        float time = min + llFrand(max - min);
       
        if (debug) llSay(0, "Time set to" + (string)time);
       
        llSetTimerEvent(time);
    }       
}


Top
 Profile  
 
 Post subject: Re: Ambient Sound
PostPosted: Mon Apr 27, 2009 6:40 am 
OSG Elite
User avatar

Joined: Fri Oct 17, 2008 11:30 am
Posts: 300
Location: Yorkshire, England
Useful to have something like this kicking about - I love ambient sound in SL and OS - done well, it makes the whole thing that much more immersive.

Just some idle thoughts:

One of the many unfinished projects I have kicking around is a similar script that plays different sounds according to different probablities based on morning/day/evening/night differentation between sounds in a set based on llGetSunDirection(). A notecard specifies, for each sound, its frequency/time of day correlation. I was going to use that to trigger bird sounds etc, and include all the full-perm ambient sounds I could lay my hands on, organised into sets, but like so many of these things it never got finished and remains on my "one of these days" list.

For constantly playing sounds, such as running water, it's more efficient to use llLoopSound() instead; just put that in the state_entry() event and forget about it - no need for a timer.

I also wrote a simple script which uses llLoopSound() but triggers it, and retriggers it occasionally, at random times. That's to stop objects with the same length of sound (or indeed the same sound) all playing "in sync"; by retriggering llSetTextureAnim() at the same time, it stopped all my waves crashing at the same time, and made the beach a more realistic place to hang out.

_________________
John
UK resident; OSGrid & Second Life: "Barrington John"; code monkey in RL
OSGrid region server: P4/3.6GHz/2GB, Ubuntu Karmic/Mono 2.6/MySQL 14.14v5.1.37, home ADSL (~8.5Mbps/0.85Mbps), 8-14 regions, 2 users


Top
 Profile  
 
 Post subject: Re: Ambient Sound
PostPosted: Mon Dec 14, 2009 12:41 pm 

Joined: Mon Nov 02, 2009 5:33 pm
Posts: 27
This is a nice script to play intermittent sounds, this one is day, there is one for night too. It isn't working here on OSgrid... can anyone see the problem? TIA

// Sound Prim Script - Intermittent Daytime
//
// If the sun is above the horizon, this
// randomly picks a sound in inventory, plays it,
// waits a random interval, repeats.
//
// Set this between 0.0 and 1.0
float 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 = 60;
integer LONGEST = 150;
//
////////////////////////////////////////////////
default
{

state_entry()
{
if (SHORTEST < 10 ) SHORTEST = 10;
if (LONGEST < 10 ) LONGEST = 10;
if (SHORTEST > LONGEST) SHORTEST = LONGEST;

llSleep( 1.0 );
state noisy;
}

on_rez(integer start_param)
{
llSleep( 1.0 );
state noisy;
}

}
////////////////////////////////////////////////
state noisy
{

state_entry()
{
vector sun_point = llGetSunDirection();
if ( sun_point.z < 0.0 ) state silent;

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;
}

}
////////////////////////////////////////////////
state silent
{

state_entry()
{
llSleep( (float)(llFloor(llFrand(LONGEST - SHORTEST)) + SHORTEST) );
state noisy;
}

on_rez(integer start_param)
{
state default;
}

}


Top
 Profile  
 
 Post subject: Re: Ambient Sound
PostPosted: Mon Dec 14, 2009 12:53 pm 
OSG Elite
User avatar

Joined: Fri Oct 17, 2008 11:30 am
Posts: 300
Location: Yorkshire, England
Maybe your llSleep() statements are timing out? I would suggest using timers instead anyway.

Also llFrand() takes a float as an argument, and you're passing an integer. Try casting it as a float before passing: llFloor(llFrand((float)sounds)).

_________________
John
UK resident; OSGrid & Second Life: "Barrington John"; code monkey in RL
OSGrid region server: P4/3.6GHz/2GB, Ubuntu Karmic/Mono 2.6/MySQL 14.14v5.1.37, home ADSL (~8.5Mbps/0.85Mbps), 8-14 regions, 2 users


Top
 Profile  
 
 Post subject: Re: Ambient Sound
PostPosted: Mon Dec 14, 2009 1:13 pm 

Joined: Mon Nov 02, 2009 5:33 pm
Posts: 27
Thanks for your quick answer! I didn't write the script, I'm a builder, haven't learned scripting yet, it's on the list. These are lil scripts I use in rocks to play nature sounds at appropriate times on Second Life, I was hoping it was something quick and easy to change over for use here, lol.. it's never easy, is it?


Top
 Profile  
 
 Post subject: Re: Ambient Sound
PostPosted: Mon Dec 14, 2009 10:25 pm 
OSG Elite
User avatar

Joined: Wed Mar 11, 2009 3:57 pm
Posts: 444
Here is another variation of a Sound Generator. Just drop your sounds in and it will play them during the daytime.

NOTES:
Never use llSleep in OpenSimulator.... it's borked and will cause issues with script engines.
THIS USES LOOPING SOUND so the sound will continue to play till the next cycle is initiated.
A More Complete and Versatile Sound Manager System is located Further in this posting on Page-2 @ http://osgrid.org/forums/viewtopic.php?f=5&t=1151&p=9088#p9088

{L_CODE}:
// Looping Sound Script
// CORRECTED for OpenSimulator
// December 14,2009
// No LLSLEEP functions
// Uses llSetTimerEvent
// -------------------------------------------------------------------------
// * Plays sound ONLY in Daytime
// * Randomly picks a sound in inventory, plays it in loop till next cycle,
// * Random Timing Cycle to switch sounds
// -------------------------------------------------------------------------
// === SET FOLLOWING VALUES ===
// Set this between 0.0 and 1.0 where 1.0 = LOUDEST
float LOUDNESS = 0.5;
//
// Interval in seconds to be silent.
// Minimal Value should be Greater then 10.0
// These are in Seconds! 
// Smaller Numbers will generally result in faster switching / cycling of sounds.
float SHORTEST = 60.0;
float LONGEST = 150.0;
//
// === NO NEED TO CHANGE NEXT LINE ===
integer night = TRUE; // just a checker for day versus night
//
// === PLAY SOUND ROUTINE ===
SoundPlay()
{
    vector sun_point = llGetSunDirection();
    if ( sun_point.z <= 0.0 ) // It's Night Time as SUN is Below Horizon
    {
        night = TRUE;
        llSetTimerEvent(300); // 5 minutes till next cycle & test
        return;
    }
    else    // It's daytime as SUN is above Horizon
    {
        night = FALSE;
        integer sounds = llGetInventoryNumber(INVENTORY_SOUND);
        if ( sounds <= 0 ) llOwnerSay("There are no sounds in me, Please put sounds files into this prim for me to play");
        string soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(sounds)) );
        if ( soundname != "" )
        {
            llLoopSound( soundname, LOUDNESS );  // Plays Sound in Looping mode.  It will run continously till next cycle.
            // llPlaySound( soundname, LOUDNESS );  // Plays Sound ONCE every cycle. 
           // UN-COMMENT above line if desired and comment the llLoopSound line
        }
        // Sets timer event to trigger again @ random time causing sound cycle
        float timing = (float)(llFloor(llFrand(LONGEST - SHORTEST)) + SHORTEST);
        if(timing < 10.0) timing = 10.0;
        llSetTimerEvent(timing);
    }
}
//
// === MAIN APP STATE ===
default
{

    state_entry()
    {
        SoundPlay(); // Just to kick off sounds @ entry
       
    }
    on_rez(integer start_param)
    {
        llResetScript();
    }
    timer()
    {
        llSetTimerEvent(0.0); // clears it as it is reset in SoundPlay
        SoundPlay(); // loop back to function
    }
}



Good Luck and have fun

_________________
No further support of any kind, for any of my materials. Use as/is whereis.
PLEASE UNSTICKY Any Stickied Posting by myself.


Last edited by WhiteStar Magic on Mon Dec 21, 2009 8:22 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Ambient Sound
PostPosted: Mon Dec 21, 2009 6:33 am 

Joined: Mon Nov 02, 2009 5:33 pm
Posts: 27
Thanks a ton Whitestar! I'll go kill everything that sleeps now.


Top
 Profile  
 
 Post subject: Re: Ambient Sound
PostPosted: Mon Dec 21, 2009 7:18 am 

Joined: Mon Nov 02, 2009 5:33 pm
Posts: 27
That didn't work for me, it only plays one of the birds instead of cycling thru them and no matter what I set float SHORTEST, float LONGEST to it still plays the same bird over and over pretty rapidly. Semi amusing, I tried this in a rock with peacock calls, oh my that's not something you want on a fast loop this early (if ever!) LOL


Top
 Profile  
 
 Post subject: Re: Ambient Sound
PostPosted: Mon Dec 21, 2009 9:48 am 
OSG Elite
User avatar

Joined: Fri Oct 17, 2008 11:30 am
Posts: 300
Location: Yorkshire, England
Try changing:

llLoopSound( soundname, LOUDNESS );

to:

llPlaySound( soundname, LOUDNESS );

That should fix it.

_________________
John
UK resident; OSGrid & Second Life: "Barrington John"; code monkey in RL
OSGrid region server: P4/3.6GHz/2GB, Ubuntu Karmic/Mono 2.6/MySQL 14.14v5.1.37, home ADSL (~8.5Mbps/0.85Mbps), 8-14 regions, 2 users


Top
 Profile  
 
 Post subject: Re: Ambient Sound
PostPosted: Mon Dec 21, 2009 11:24 am 

Joined: Mon Nov 02, 2009 5:33 pm
Posts: 27
Wonderful, I have my birds back! Thanks you guys.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 2   [ 13 posts ]
Go to page 1, 2  Next


Who is online

Users browsing this forum: legacy_google [bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net