Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Loop several sound files

Amaris Laval
Registered User
Join date: 20 Mar 2007
Posts: 9
06-28-2007 11:27
Okay, I got an object, in that is sound files like this 'sound01,sound02..sound20' I can make those play just fine when touching the object, stop the sound when touching the object again

Is there any way to make a loop so it plays all the sounds in the object, then returning to sound01 again to loop it all?

For short. Is there anyway of repeating it?
Amaris Laval
Registered User
Join date: 20 Mar 2007
Posts: 9
06-30-2007 03:43
No one?
Alicia Mounier
Registered User
Join date: 17 Oct 2005
Posts: 78
06-30-2007 06:08
Well I've seen alot of cd or jukebox scripts made to play 10 -9 seconds long sound files and play them in order so you can upload an entire song. They have a touch start, stop and after looking at the two I could find in my inv I see how to make it loop after playing the entire song or lot in the object and still be able to turn it off. lol, i'll post it below with some comments and if I did it wrong let me know cause i'm doing this after not having enough sleep for the past fews days after trying to optimize a gun script and looking at an optimizing post here in the forums. lol, I'm only going to do one of them for now. Depending on how long each sound clip is will determine when the timer will trigger the next one like say the clip is 9 secnds then the timer will fire off at 8.9 or so. It is commented in the script and you can mess with it, be warned though factors like sim performance and such will effect the fluidness or how seamless each sound clip is heard. lol, of course we wouldn't have to be doing this if they would maybe let us upload longer length sound files but I guess they got thier reasons behind it.

Also this has a built in delay to preload enough sound clips so it will sound more fluid.

CODE

//Psyke's Music Script v4.15.1
//Song Player

//Modified by Psyke Phaeton... this script is free for anyone to use or copy.. please make it copyable from your "CD"
//Drop 9 second song clips in reverse order into the Inv of the obect, and touch to play.

//user variables

integer waves_to_preload = 3; //wave files to Preload ahead of the wav being played.
float preload_load_time = 0.5; // seconds pause between each preloaded wave file attempt b4 play comnences
//vector set_text_colour = <,0,0>; // colour of floating text label
float set_text_alpha = 1; //no idea what this is LOL
float timer_interval = 8.9; //time interval between requesting server to play the next 9 second wave
// times just below 9 seconds are suitable as we use sound queueing
integer timer_started;

// program variables
list invlist;
integer total_wave_files; //number of wave files
integer last_wave_file_number; //final wave sequence number (note: sequence starts at zero
//- so this is 1 less than total wave files)
integer i; //used by timer() player
integer c; //user by sound() bufferer
string preloading_wave_name; //the name of the wave file being preloaded
string playing_wave_name; //the name of the wave being played
integer play = FALSE; //toggle for music playing or stopped

sound()
{
total_wave_files = llGetInventoryNumber(INVENTORY_SOUND);
last_wave_file_number = total_wave_files - 1; // because wav files are numbered from zero
float length = total_wave_files*9.0;
//llSay(0, "preloading " + (string)tottrack + " wavs. Play length " + (string)llFloor(length) + "secs");
integer c = 0;
//do full preload of sound
llSetSoundQueueing(TRUE); //ONLY WORKS ON llPlaySound not llTriggerSound
/////////////////
//integer x = waves_to_preload;
//if ( total_wave_files < waves_to_preload ) { x = total_wave_files; }
////////////////
integer x = total_wave_files;
llSay(0, "(" + llGetScriptName() + ") " + llGetSubString((string)(x * preload_load_time),0,3) + " sec buffering..");
timer_started = FALSE;
for (c = 0 ; c <= (x - 1) ; c++) { //preload X wave files b4 we play
//since wavs are numbered from 0 we minus 1
preloading_wave_name = llGetInventoryName(INVENTORY_SOUND, c);
llSetText(llGetObjectName() +
"\n(preloading " + llGetSubString((string)((x - c)*preload_load_time),0,3) + " secs)"
//////debug lines
//+ "\n--debug--\n"
//+ "Preload wav: " + (string)c
//+ " name: " + preloading_wave_name
//+ "\nkey: " + (string)llGetInventoryKey(preloading_wave_name)
//////end debug line
+"\n.", <1,0,0>, set_text_alpha);

//Attempt to preload first x wave files to local machines cache!
llTriggerSound(preloading_wave_name, 0.0);
llPreloadSound(preloading_wave_name);
//llWhisper(0, (string)c + " of " + (string)tottrack);
//llWhisper(0,"Preloading wav: " + (string)c + (string)llGetInventoryKey(preloading_wave_name));

//start play sound timer in 'timer_interval' seconds when we are less than 'timer_interval' seconds from
// finishing preloading.
if ( ((total_wave_files - c) * preload_load_time) < timer_interval && !timer_started) {
//llWhisper(0, "Starting timer:" + (string)timer_interval);
llSetTimerEvent(timer_interval);
timer_started = TRUE;
}

llSleep(preload_load_time);
}
i=0; c=0;
llSay(0, "Done! Playing.. (" + (string)llFloor(length) + " secs) Click to stop.");
//llSetTimerEvent(8.85);
}

default
{
on_rez(integer start_param)
{
//set text above object to the name of the object
llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
//llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
}
touch_start(integer total_number)
{
if (!play) {
//llTargetOmega(<0,0,1>,PI,1.0) ;
sound();
} else {
//llTargetOmega(<0,0,1>,0,0);
llSetTimerEvent(0.0);
llStopSound();
//llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
llSay(0, "Stopping..");
llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
}

play = !play;
}

timer()
{
if( i > last_wave_file_number )
{
sound();//This is what I changed or added to keep it looping till you touch it again and stop it. All the rest below was either already omitted or omitted by me where ie: // play = FALSE; was done by me and //llSay(0, "finished."); was omitted by the original maker that was prolly used for testing and such.

//llSay(0, "finished.");
// play = FALSE;
//llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
// llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
//llResetScript();
// llSetTimerEvent(0);
}
else
{
playing_wave_name = llGetInventoryName(INVENTORY_SOUND, i);
//llWhisper(0, "llPlaySound wav: " + (string)i + " " + (string)llGetInventoryKey(playing_wave_name) );
llPlaySound(playing_wave_name, 1.0);
llSetText( llGetObjectName() +
"\n(playing " + (string)i +" of "+ (string)last_wave_file_number +")\n."
, <0,1,1>, set_text_alpha);

if(i + waves_to_preload <= last_wave_file_number)
{
preloading_wave_name = llGetInventoryName(INVENTORY_SOUND, i + waves_to_preload);
//llSetText( llGetObjectName() +
// "\n(playing " + (string)i +" of "+ (string)last_wave_file_number +")"
//////debug line
//+ "\n--debug--\n"
//+ "Playing key: " + (string)llGetInventoryKey(playing_wave_name) + "\n"
//+ "Preloading sequence: " + (string)(i + waves_to_preload)
//+ " name: " + preloading_wave_name
//+ "\nPreloading key: " + (string)llGetInventoryKey(preloading_wave_name)
//////end debig line
// , set_text_colour, set_text_alpha);

//llWhisper(0, "Preloading wav:" + (string)(i + waves_to_preload) + " " +
// (string)llGetInventoryKey(preloading_wave_name) +" last = " + (string)last_wave_file_number);
llTriggerSound(llGetInventoryName(INVENTORY_SOUND, i + waves_to_preload), 0.0);
llPreloadSound(llGetInventoryName(INVENTORY_SOUND, i + waves_to_preload));
}
}

i++; //increment for next wave file in sequence!
}
}


Find "float timer_interval = 8.9;" and change it to reflect the length of the sound clip. Like for a 9 second sound clip you would change it to = 8.9. Just copy all that stuff between the [/php] thingies and put it in a new script in the object holding the sound clips. If you don't want the floating text just find all the llSetText's and get rid of those lines but make sure to do that before saving the script in the sound object or you'll be stuck with the floating text forever!!! :eek:
Alicia Mounier
Registered User
Join date: 17 Oct 2005
Posts: 78
06-30-2007 06:12
lol, oh yeah and if you don't want any messages from it just get rid of all the llSay, llOwnerSay and such. That will get rid of the text spammed in chat from it. Lol, goodluck
Amaris Laval
Registered User
Join date: 20 Mar 2007
Posts: 9
06-30-2007 06:12
oo you are the man! Erh woman!

Will definately test it out! Thank you
Amaris Laval
Registered User
Join date: 20 Mar 2007
Posts: 9
06-30-2007 07:14
Another dumb question. Sorry quite new to all this scripting thingie but is there a way to make it so the owner is the only one who can trigger it?
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
06-30-2007 07:49
From: Amaris Laval
Another dumb question. Sorry quite new to all this scripting thingie but is there a way to make it so the owner is the only one who can trigger it?
Somewhere in that script there's a "touch_start(integer total_number) { ...." Right there, after the "{", insert the line "if (llDetectedKey(0) != llGetOwner()) return;"
Dormien Dagostino
Registered User
Join date: 30 Apr 2007
Posts: 1
12-04-2007 02:38
How do you make it so this script plays the song continously, and doesn't stop, buffer and then plays soundclips again after the total sequense?
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
12-04-2007 12:10
From: Dormien Dagostino
How do you make it so this script plays the song continously, and doesn't stop, buffer and then plays soundclips again after the total sequense?



Buy land and stream that way. Sound files are set to 10 second limits. The only way I could figure on it being done is to have multiple prims, and have each prim playing the sound with a sound level of 0, thereby forcing the client to download the clips quicker, then once they're queued, you can play them back in order with volume.
Daten Thielt
Registered User
Join date: 1 Dec 2006
Posts: 104
12-04-2007 15:20
Preload the sounds twice