Jump to content

walker/typer script with music and positonsave for the music. - gaps/lags between parts


Pete Chandru
 Share

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

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

Recommended Posts

Hello,

 

I have a problem with my selfmade walker/typer with musicclps, that are one whole short song. The script should preload eveytime on attach on login and then play all musicfiles after another when typing or walking (depending in which prim it is and changed to typer or writer). When stopping and restart walking or typing, the script plays from the last position. However. I made soundfiles that are exactly 9,900 seconds long (when i made 10,000 second life tells me i cannot upload them). When I put the soundfiles in a gesture with those timings, than the usually is no gap between the parts. Can someone maybe help finding the issue?

 

//====================================================================================================
// Global Variables
//====================================================================================================

// Tweakable variables
integer giConditionToTriggerSound; // Set this variable in state_entry() below

// Use AGENT_TYPING to function as a typer
// Use AGENT_WALKING to function as a walker
// You can also combine them togther (using the bitwise OR operator) as such:
// AGENT_TYPING | AGENT_WALKING
// That would make it both a typer and a walker
// There are many other conditions, you can look at them at http://wiki.secondlife.com/wiki/LlGetAgentInfo

integer giResetOnStop = FALSE;
float gfSoundFileLength = 9.9;


// Please don't tweak the next
integer giCurrSoundIndex = 0;
integer giNumSoundFiles;
integer giTriggeredLastInterval = FALSE;
float gfTimerInterval = 0.25;
float gfTimeElapsed;

//====================================================================================================
// LSL States And Functions
//====================================================================================================
default
{
        attach(key id)
    {
        llResetScript();
    }
    state_entry()
    {
        // Set condition variable
        giConditionToTriggerSound = AGENT_TYPING;
        
        
        giNumSoundFiles = llGetInventoryNumber(INVENTORY_SOUND);
        
        if (giNumSoundFiles != 0)
        {
            llOwnerSay("Preloading...");
            
            // Preload sounds
            integer i=0;
            while(i<giNumSoundFiles)
            {
                llPreloadSound(llGetInventoryName(INVENTORY_SOUND,i));
                ++i;
            }
            
            llOwnerSay("Done preloading.");
            
            // Start the timer
            llSetTimerEvent(gfTimerInterval);
        }
    }
    
    //----------------------------------------------------------------------------------------------------
    
    changed(integer change)
    {
        // If there's been a change in inventory
        if (change & CHANGED_INVENTORY)
        {
            // Retreive amount of sound files
            giNumSoundFiles = llGetInventoryNumber(INVENTORY_SOUND);
            
            // If there are none
            if (giNumSoundFiles == 0)
            {
                // Stop the timer
                llSetTimerEvent(0.0);
            }
        }
    }
    
    //----------------------------------------------------------------------------------------------------
    
    timer()
    {
        // Update timer
        gfTimeElapsed += gfTimerInterval;
        
        // Get owner's info
        integer iAgentInfo= llGetAgentInfo(llGetOwner());
        
        // If the condition is true
        if(iAgentInfo & giConditionToTriggerSound)  
        { 
            // Make the sound audible
            llAdjustSoundVolume(1.0);
            
            if((gfTimeElapsed >= gfSoundFileLength) || !giTriggeredLastInterval)
            {
                // Reset timer
                gfTimeElapsed = 0;
                
                // Play the current sound
                llPlaySound(llGetInventoryName(INVENTORY_SOUND,giCurrSoundIndex), 0.001); 
                
                // Get next sound file's index
                giCurrSoundIndex = (giCurrSoundIndex + 1) % giNumSoundFiles;
                
                // Preload it
                // llPreloadSound(llGetInventoryName(INVENTORY_SOUND, giCurrSoundIndex));
            }
            
            giTriggeredLastInterval = TRUE;
        }
        
        else
        {
            if (giResetOnStop)
            {
                // Reset index and timer
                giCurrSoundIndex = 0;
                gfTimeElapsed = 0.0;
                
                giTriggeredLastInterval = FALSE;
                
                // Stop the sound
                llStopSound();
            }
            
            else
            {
                // Mute the sound
                llAdjustSoundVolume(0.0);
            }
        }
    }
    
    //----------------------------------------------------------------------------------------------------
}

I guess this forum is the best way to may getting help :)

Link to comment
Share on other sites

It's hard to stitch sounds together seamlessly.  All it takes is a little lag in a region to mess things up.  You might try any of the following:

1.  Use llSetSoundQueueing(TRUE) so that the next sound waits to start playing until the previous one has finished. That can often keep sound from bumping into each other and stalling.

2. Adjust the variable gfTimerInterval in your script.  As much as I try to avoid fast timers, there are some scripts in which they are unavoidable.  This may be one of them.  The "gap" you are hearing may be the 0.25 second time between the end of one sound file and the next time that your timer event is triggered.  Make it shorter.

3. A sound can't be heard until it is fully preloaded, which means that anyone within hearing range has already "heard" the complete sound and loaded it into cache.  When you have sound files of exactly the same length, you do need a small gap between them to guarantee that the next one is fully preloaded by the time you need it. If the gap is too short, preloading won;t be complete.  If it's too long, as you discovered, the gap is audible. There is a way around the problem, however. You can do your preloading from a child prim with a different, linked script. Because llPreloadSound can be flaky, it's sometimes best to use llPlaySound at zero volume instead.  Coordinate your two scripts so that the hidden one -- the one in the child prim -- starts slightly before the main script is triggered.  That way, you can be sure that it will have finished before the main script finishes playing the current sound.  I'm not sure how well this strategy will work in your application, since a walker/typer is meant to be interrupted when you stop walking or typing, but it might be worth trying.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3048 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...