|
Paulo Dielli
Symfurny Furniture
Join date: 19 Jan 2007
Posts: 780
|
02-01-2007 20:15
I'd like to play a constant looping ambient sound like the buzz of crickets on my land. I have a 10 sec soundfile that can be played looping. I don't mean a streaming url or music that can only be heard when the audio-play-button is pressed. Just a constant background sound for some more atmosphere on my land. I guess I have to do this with llPlaySound on a prim, but I have no idea how this script must be written. The wiki and knowledge base don't help me.
Besides the constant ambient sound, I also want to put soundfiles in prims on other parts of my land. For example a bird that sits somewehere in a tree and can only be heard when nearby. Does this also work with llPlaySound?
So, if anyone would be so kind: could you please post examples of these two scripts? One for the ambient overall sound and one for the occasional sounds. Thanks in advance!
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
02-02-2007 01:01
You can trigger a sound within a limited range using llTriggerSoundLimited You supply the sound name (or key), volume and then max and min coordinates. However it will only play the sound once. You would have to retrigger it :- string sound = "my sound file name"; float length = 10; // length of clip float volume = 1.0;
default { state_entry() { llSetTimerEvent(length); llPreloadSound(sound); }
timer() { vector pos = llGetPos(); llTriggerSoundLimited(sound,volume,pos + < 5,5,5 >, pos - <5,5,5>); } }
|
|
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
|
02-02-2007 05:24
I dropped an early creation of mine on Paolo; all of the sounds in it are of my creation. You can replace them. Here is the code which I released for general use years ago. Please note the date on it before noting that it doesn't use more modern API calls. // intermittent sound - plays a set of abmient sounds at various random intervals // unlimited use in SL granted provided you leave these top comments // and don't pretend you wrote it. // // 15-oct-03 malachi petunia v1.0 // 31-mar-04 mp - TriggerSoundLimited doesn't seem to work at all, So I bumped up the interval, sigh // user changable paramters are here // float gain = 0.2; // 0.0 is silent, 1.0 is as loud as it goes // end of user changeable paramters float minDelay = 120.0; // min interval between sound plays float delayEpsilon = 60.0; // variance to add to minDelay list soundInventory = []; integer num_sounds; integer lastSound = -1; // used to prevent the same sound twice in a row integer DEBUG = FALSE; // excess devleopment verbosity debug(string s) { if(DEBUG) llSay(0, s); } // fills the soundInventory for later use // fillSoundInventory() { integer i; string sound_name; num_sounds = llGetInventoryNumber( INVENTORY_SOUND ); debug((string)num_sounds + " sounds in inventory:" ); soundInventory = []; for ( i = 0; i < num_sounds; i++ ) { sound_name = llGetInventoryName( INVENTORY_SOUND, i ); debug(sound_name); soundInventory += sound_name; } lastSound = -1; } // returns a random sound from all sounds in the object unless it was the last one returned // string getRandomSound() { integer rand; debug("lastSound is " + ((string) lastSound)); do { rand = llFloor(llFrand(num_sounds)); debug("rand is " + ((string) rand)); } while(rand == lastSound); lastSound = rand; debug("using sound " + ((string) rand) + " of " + ((string) num_sounds)); return llList2String(soundInventory, llFloor(llFrand(num_sounds))); } string getNextSound() { lastSound++; lastSound %= num_sounds; return llList2String(soundInventory, lastSound); } float getRandomInterval() { float delay = minDelay + (llFrand(delayEpsilon)-((delayEpsilon)/2)); debug("new delay is " + ((string) delay)); return delay; } // restores script to initial state // initialize() { fillSoundInventory(); llWhisper(0, "Activated"); } default { state_entry() { initialize(); llSetTimerEvent(getRandomInterval()); } timer() { llPlaySound(getNextSound(), gain); llSetTimerEvent(getRandomInterval()); } touch_start(integer num_detected) { // only looks at the first toucher (assumes low touch rate) if(llDetectedKey(0) == llGetOwner()) { state Idled; } } } state Idled { state_entry() { llStopSound(); llSetTimerEvent(0.0); llWhisper(0, "Idled"); } touch_start(integer num_detected) { if(llDetectedKey(0) == llGetOwner()) { state default; } } }
|
|
Paulo Dielli
Symfurny Furniture
Join date: 19 Jan 2007
Posts: 780
|
02-02-2007 20:24
Oh my god! This simple script from Newgate Ludd works like a dream. I made sure that my sounds were exactly timed and had the same sound levels at the beginning and the end, so they would loop well. After that it was just a matter of setting the right trigger distances for the various sounds. It's really wonderfull and adds SO much atmosphere to my land. I'm sitting in my newly built house in my own designed chair (my 'business' on SL) looking at the sunset with sounds of birds in the distance and waves nearby. In the meantime my fireplace is making that beautiful subtle fire-sound (how do you say that in English?). When I walk accross my 'island' I hear the waves in all four corners and birds and chimes in the centre. In one corner an odd bird is singing its own tune... Thanks very very much! This is my home: http://slurl.com/secondlife/Gisborne/226/133/21
|