Change font size
It is currently Fri Aug 23, 2019 7:50 pm

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 2 of 2   [ 13 posts ]
Go to page Previous  1, 2
Author Message
 Post subject: Re: Ambient Sound
PostPosted: Mon Dec 21, 2009 3:05 pm 
OSG Elite
User avatar

Joined: Wed Mar 11, 2009 3:57 pm
Posts: 444
Shez Oyen {L_WROTE}:
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


I have this script running in my test region and it works fine and cycles through the sounds randomly. I would not have posted it without testing it. I dropped 20 valid sound files into the prim and sat patiently while it cycled through. It uses standard LSL so there's no issue with osFunctions. I can imagine hearing Hyper Peacocks... OMG, I had a neighbour who kept them in RL, what a noisy bunch of foul !

Here is another, Considerably more Advanced Script:
The Script is fully commented and everythig you need to know is in the Header of the script. It's menu driven and has several enhanced functions and Low-Lag as I like to do housekeeping and keep irrelevant chatter down. You can now control the Entire system from the menu's and there is no need to edit the script to take advantage of the goodies and to adjust the settings. It's coded for the Owner Only, so folks can't fool around with it. I have tested this with 30 sounds (which BTW is a tad annoying as I used Door Sounds LOL) and have no issues with it at all. You can also turn on DEBUG and see what it is doing and it will be quite versose to OWNER in Chat so it won't spam people while you are setting things up. It accomodates Sound Looping if needed or Single Play in the cycle. (not all sounds are equal)

{L_CODE}:
// ----------------------------------------------------------------
// Script Title:    Advanced Sound Player
// Created by:      WhiteStar Magic
// Creation Date:   December 21,2009
// Platforms:
//    OpenSim:      Tested & operational on OpenSim 0.6.9 (Dev) ba75526 - r11721
//
// Revision:        0.5
// Revision History:
//     Evolved from basic DayTime Sound Module
//     Now does Day, Night or Always sound emination with Volume control and more,
//     All Menu driven and no need to edit script for functionality.
//
// Revision Contributors:
//
//
//
// Conditions:
// Please maintain this header. If you modify the script indicate your
// revision details / enhancements
//
// Support:
//  If & When needed as Time Permits
//
// Licensing:  Creative Commons 2.5 (Canada)
//
// http://creativecommons.org/licenses/by/2.5/ca/
// http://creativecommons.org/licenses/by/2.5/ca/legalcode.en
// ================================================================
// ** SCRIPT NOTES **
//  This is  Multi Mode Sound player Script.  It can play sounds during Daytime, Nightime or Always
//  Plays sounds for a Random Period of Time between 15 to 150 seconds in duration
//  Menu Driven with Settings Status Information
//  Menu can only be accessed by Owner
//  Debugging can be enabled from Menu for extended details of operation
//  No Lag Chat & Listen functions (uses Good Housekeeping)
//  No llSleep Functions, uses active timer
//
//  ** INSTALLATION **
//    Install script into a prim of your choice
//    Copy in your desired sound files into same prim
//    Touch for OWNER Menu to activate Options
//
//  ** MENU OPTIONS **
//    ON    = Player ON
//    OFF   = Player OFF
//    Day   = Play Sounds Daytime Only
//    Night = Play Sounds Nightime Only
//    Allways = Play Sounds always
//    Looping = Loops Sound during Cycle
//    Single  = Plays Sound once in Cycle
//    Volume = Volume/Loudness menu
//      Volume menu gives option of 1/4, 1/3, 1/2, 2/3, 3/4, full
//    RESET = RESET SCRIPT
//    DEBUG = On/Off (Chats info to Owner)
//    DONE  = EXIT MENU SYSTEM
//
//================================================================
// === Variables Used ===
//==================================
// === DO NOT CHANGE LINES BELOW ===
//==================================
//
// Smaller Numbers will generally result in faster switching / cycling of sounds.
float SHORTEST = 11.0;  // allows for Short Sound Burst cycle = More Randomness
float LONGEST = 165.0;  // 2.5 minutes Max Sound Play value with correction for llFrand
//
string  WhenToPlay = "Day"; // Day, Night, Allways
integer On_Off = TRUE;      // Device Active On or Off
integer MENU_ACTIVE = FALSE;
string  MENU;
string  MyVol = "1/2";
integer sounds;
float   timing = 10.0;
integer CHANNEL;            // Channel for Menus
key     OWNER;              // Owners UUID
integer DEBUG = FALSE;      // Debugging Switch
string  MyStatus;
float   LOUDNESS = 0.5;     // 0.0 = silent - 1.0 = Loudest
integer LOOPING = FALSE;
// =====================================
// === Day Night Check ===
DayOrNight()
{
    vector sun_point = llGetSunDirection();
    if ( sun_point.z <= 0.0 ) // It's Night Time as SUN is Below Horizon
    {
        if(DEBUG) llOwnerSay("Currently Night time");
        if(WhenToPlay == "Night")
        {
            SoundPlay();
        }
        else
        {
            llSetTimerEvent(300); // 5 minutes till next cycle & test
            return;
        }
    }
    else    // It's daytime as SUN is above Horizon
    {
        if(DEBUG) llOwnerSay("Currently Day time");
        if(WhenToPlay == "Day")
        {
            SoundPlay();
        }
        else
        {
            llSetTimerEvent(300); // 5 minutes till next cycle & test
            return;
        }
    }
}
// === PLAY SOUND ROUTINE ===
SoundPlay()
{
    // Sets timer event to trigger again @ random time causing sound cycle
    // Little bit of tom foolery here to compensate & rationalize values
    timing = (float)(llFloor(llFrand(LONGEST - SHORTEST)) + 1);
    if(timing < 10.0) timing = SHORTEST;
    llSetTimerEvent(timing);
    //       
    if ( sounds <= 0 ) llOwnerSay("There are no sounds in me, Please put sounds files into this prim for me to play");
    integer randomnum = llFloor(llFrand(sounds));
    string soundname = llGetInventoryName( INVENTORY_SOUND, randomnum );
    if ( soundname != "" )
    {
        if(DEBUG) llOwnerSay("Sounds Found = ["+(string)sounds+"]: File Being Played = [# "+(string)randomnum+" / "+soundname+"] for ["+llGetSubString((string)timing, 0,llSubStringIndex((string)timing,".")+1)+"] Seconds");
        if(LOOPING) llLoopSound( soundname, LOUDNESS );
        else llPlaySound( soundname, LOUDNESS );
    }
}
//
// ==============
// MENU FUNCTIONS
// ==============
// Simple Button Ordering for regular functions (MAX 12 BUTTONS)
//===== Order the Buttons into right sequence for DIALOG MENUS
list ButtonSort(list btns)
{
    return llList2List(btns, -3, -1) + llList2List(btns, -6, -4)
        + llList2List(btns, -9, -7) + llList2List(btns, -12, -10);
}
//
OPEN_Comms()  // Open Communications Channel only when needed
{
    llListenRemove(CHANNEL);                         // SAFETY Kill CHANNEL incase left over
    CHANNEL = (integer)(llFrand(-1000.0) - 1000.0);  // RANDOM Negative Channel
    llListen(CHANNEL, "", "", "");                   // listen for dialog answers
    llSetTimerEvent(45.0);                           // to AutoKill CHANNEL
}
//
MENU_Admin(key id)  // Admin Menu
{
    OPEN_Comms();
    MENU_ACTIVE = TRUE;
    MENU = "ADM";
    llSetTimerEvent(60.0);
    //
    status();
    //
    string MA_data;
    list MA_list;
    //
    MA_data = "-=[Multi-Mode Sound Player]=-"+MyStatus+
        "\n=== Select the Option ===\n"+
        "ON    = Player ON\n"+
        "OFF   = Player OFF\n"+
        "Day   = Play Sounds Daytime Only\n"+
        "Night = Play Sounds Nightime Only\n"+
        "Allways = Play Sounds always\n"+
        "Looping = Loops Sound during Cycle\n"+
        "Single  = Plays Sound once in Cycle\n"+
        "Volume  = Volume/Loudness Menu\n"+
        "RESET = RESET SCRIPT\n"+
        "DEBUG =  On/Off (Chats info to Owner)\n"+
        "DONE  = EXIT MENU SYSTEM";
    MA_list = ["ON","OFF","Day","Night","Allways","Looping","Single","Volume","RESET","DEBUG","DONE"];
    llDialog(id, MA_data, ButtonSort(MA_list), CHANNEL);
}
//
MENU_Volume(key id)  // Volume Menu
{
    OPEN_Comms();
    MENU_ACTIVE = TRUE;
    MENU = "VOL";
    llSetTimerEvent(60.0);
    //
    status();
    //
    string MA_data;
    list MA_list;
    //
    MA_data = "-=[Multi-Mode Sound Player]=-"+MyStatus+
        "\n=== Volume/Loudness ===\n"+
        "Select your Volumen Prefference\n"+
        "NB: Sound is Centered ON the prim containing this script\n"+
        "DONE  = EXIT MENU SYSTEM";
    MA_list = ["1/4","1/3","1/2","2/3","3/4","FULL","DONE"];
    llDialog(id, MA_data, ButtonSort(MA_list), CHANNEL);
}
//
status()
{
    string statusA =    "Debug OFF";
    if(DEBUG) statusA = "Debug ON";
    string statusB =     "Device OFF";
    if(On_Off) statusB = "Device ON";
    string statusC =    "OFF";
    if(LOOPING) statusC = "ON";

    MyStatus = "\nSTATUS: ["+statusA+"] ["+statusB+"]\n"+
        "Play Mode:["+WhenToPlay+"] Vol:["+(string)MyVol+"] Loop:["+statusC+"]\n"+
        "Sounds Available: ["+(string)sounds+"]";
}
// === MAIN APP STATE ===
default
{
    state_entry()
    {
        OWNER = llGetOwner();
        sounds = llGetInventoryNumber(INVENTORY_SOUND);
        status();
        llOwnerSay(MyStatus);
        llStopSound();
        llSetTimerEvent(10.0);  // kick the timer in 10 seconds and act on defaults
    }
   
    on_rez(integer start_param)
    {
        llResetScript();
    }
   
    changed(integer change)     // something changed, take action
    {
        if(change & CHANGED_OWNER)
        {
            llResetScript();
        }
        else if (change & CHANGED_INVENTORY)
        {
            sounds = llGetInventoryNumber(INVENTORY_SOUND);
            llOwnerSay("Sound Inventory Changed, resetting Sound Inventory Count "+(string)sounds+" Sounds Found");
        }
    }
   
    touch_start(integer num_detected)
    {
        key id_key = llDetectedKey(0);
        if(id_key == OWNER) MENU_Admin(id_key);
    }
   
    timer()
    {
        if (MENU_ACTIVE)
        {
            MENU_ACTIVE = FALSE;
            MENU = "";
            llOwnerSay("Menu Deactivated Touch to get New Menu");
            llListenRemove(CHANNEL);
            llSetTimerEvent(timing);
        }
        if(On_Off) // it's ON so act accordingly
        {
            if (WhenToPlay == "Allways") SoundPlay();
            else DayOrNight();
        }
    }
    // ==== Listening & acting on Menu Response ====
    listen( integer channel, string name, key id, string msg )
    {
        if(DEBUG) llOwnerSay("\nListen Heard on Channel " + (string)channel+
            "\nName: "+name+
            "\nID: "+(string)id+
            "\nMSG: "+msg);
        // housekeping - Kill Listen reduce Lag
        llListenRemove(CHANNEL);
        // Take Action
        if(msg == "ON")
        {
            On_Off = TRUE;
            llSetTimerEvent(timing);
        }
        else if(msg == "OFF")
        {
            On_Off = FALSE;
            llStopSound();
        }
        else if(msg == "DEBUG")
        {
            if(DEBUG) DEBUG = FALSE;
            else DEBUG = TRUE;
        }
        else if(msg == "Day") WhenToPlay = msg;
        else if(msg == "Night") WhenToPlay = msg;
        else if(msg == "Allways") WhenToPlay = msg;
        else if(msg == "Looping") LOOPING = TRUE;
        else if(msg == "Single") LOOPING = FALSE;
        // volume selections
        else if(msg == "Volume")
        {
            MENU_Volume(id);
            return;
        }
        else if(msg == "1/4") { LOUDNESS = 0.25; MyVol = msg;}
        else if(msg == "1/3") { LOUDNESS = 0.33; MyVol = msg;}
        else if(msg == "1/2") { LOUDNESS = 0.50; MyVol = msg;}
        else if(msg == "2/3") { LOUDNESS = 0.66; MyVol = msg;}
        else if(msg == "3/4") { LOUDNESS = 0.75; MyVol = msg;}
        else if(msg == "FULL") { LOUDNESS = 1.00; MyVol = msg;}
        //
        else if(msg == "RESET") llResetScript();
        if(msg == "DONE")
        {
            MENU_ACTIVE = FALSE;
            MENU = "";
            llSetTimerEvent(timing); //set timing back to the random value already generated OR default
            llOwnerSay(MyStatus);
            return;
        }
        else if(MENU == "ADM") MENU_Admin(id);
        else if(MENU == "VOL") MENU_Volume(id);
    }
}

_________________
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:16 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Ambient Sound
PostPosted: Mon Dec 21, 2009 6:22 pm 
OSG Elite
User avatar

Joined: Fri Oct 17, 2008 11:30 am
Posts: 300
Location: Yorkshire, England
Whitestar, are you using that previous script for intermittent sounds, such as bird calls, or for continuous sounds, such as a waterfall? I can't see how the script as you posted it would ever stop playing a sound until the next one came along, since there's llLoopSound()[b/] to kick it off, but there's no [b]llStopSound() to stop it playing. No wonder [b]Shez[b]'s peacocks were screeching so much!

[EDITED TO ADD] I haven't tried the last one you've posted; this applies only to the one before last.

_________________
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 8:13 pm 
OSG Elite
User avatar

Joined: Wed Mar 11, 2009 3:57 pm
Posts: 444
In the latest rev, the user can pick wether or not to Loop a Sound, for instance a waterfall should be looped as it is a continous sound whereas a single bird call should be once.

The llLoopSound does not need to be stopped as it is overiden by the next call so I play a "loop SOUND-A" then in a minute I issue a "Loop SOUND-B" then Sound-A is terminated with the subsequent call for Sound-B.

The Previous Script was for a continous loop till the next cycle, I will make a not in that particular post to help with any confusion which may arise.

The Last Script I posted is tested and fully operational, I whipped it up this morning while having my morning coffee and ran it all day in differing modes to ensure that it works to specification. I could tighten the code up but did it this way to allow for general readability for folks who are not coders. I believe that the last script should cover pretty much most use cases for a sound generating prim.

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


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


Who is online

Users browsing this forum: No registered users 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