Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Synchronized sound/music playback from multiple prims

Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
03-24-2006 18:37
DISCLAIMER
I've written these instructions as plainly as I know how, so don't ask me to help you set it up! Also, I will not give you any music to play through this, so don't ask.

Purpose
This can be used to play a sound clip from multiple prims in perfect synchronization. The speaker prims HAVE to all be linked together for this to work. The player is in its own separate prim. It chats the keys of sound to be played on a private channel. (That is the SNDCHAN variable in two of the scripts below - you'll want to change it to something harder to guess.)

Player
First, the player. Put your sound clips into a prim. The sound clip names should be set up alphabetically, so that they play in the correct order, i.e.:

Cool_Song_clip0
Cool_Song_clip1
Cool_Song_clip2

BEFORE you copy the sounds into the player prim, you will need to open them in your inventory and set full permissions on them. This is so that they can be played by prims other than those they are in.

etc...

In that same prim, put this script:
CODE
// The Sound of Music
// Original script by Sausage Turner (posted here with his permission)
// Modified to work with sound slave functions by Huns Valen
integer clips;
integer toggle = TRUE;
float clip_length = 10;//in seconds
float last_clip_length = 6;//length of last clip in seconds
integer cycle;

integer SNDCHAN = -12345;

string TenSecsQuiet = "634ad819-1b04-51de-dccd-696a670cd64d";

init() {
toggle = TRUE;
llSetTimerEvent(0);
llSetSoundQueueing(FALSE);
llStopSound();
llTargetOmega(<0,0,1>,1,1);
llSay(0,"Loading clip 1 please wait.");
llSetSoundQueueing(TRUE);
clips = llGetInventoryNumber(INVENTORY_SOUND);
llPreloadSound(llGetInventoryName(INVENTORY_SOUND,0));
llSleep(clip_length);
llLoopSoundMaster(TenSecsQuiet, 1);
llSay(0,"Touch to start.");
}

default {
state_entry() {
init();
}
on_rez(integer param) {
init();
}

touch_start(integer total_number) {
if(llDetectedKey(0)!=llGetOwner())
return;

if(toggle){
toggle = FALSE;
llSay(0,"Starting Player");
llSetSoundQueueing(TRUE);
llSay(SNDCHAN, (string)llGetInventoryKey( llGetInventoryName(INVENTORY_SOUND,0)));
llSay(SNDCHAN, (string)llGetInventoryKey( llGetInventoryName(INVENTORY_SOUND,0)));
//llTriggerSound(llGetInventoryName(INVENTORY_SOUND,0),1);
llPreloadSound(llGetInventoryName(INVENTORY_SOUND,1));
cycle = 1;
llSetTimerEvent(clip_length/2);
} else {
toggle = TRUE;
llSetTimerEvent(0);
llSay(0,"Player Stopped");
llSetSoundQueueing(FALSE);
llStopSound();
}
}

timer() {
if(cycle < clips ){
llSay(SNDCHAN, (string)llGetInventoryKey( llGetInventoryName(INVENTORY_SOUND,cycle)));
// llPlaySound( llGetInventoryName(INVENTORY_SOUND,cycle),1);
cycle = cycle + 1;
if(cycle < clips){
llSetTimerEvent(clip_length);
llPreloadSound( llGetInventoryName(INVENTORY_SOUND,cycle));
} else {
llSetTimerEvent(0);//last_clip_length);
llPreloadSound( llGetInventoryName(INVENTORY_SOUND,0));
}
}
else {
llSetTimerEvent(clip_length);
llSay(SNDCHAN, (string)llGetInventoryKey( llGetInventoryName(INVENTORY_SOUND,0)));
// llPlaySound( llGetInventoryName(INVENTORY_SOUND,0),1);
llPreloadSound( llGetInventoryName(INVENTORY_SOUND,1));
cycle = 1;
}
}
}


Now, that will be your sound player. It is separate from the "speaker" prims, so that you can have multiple players driving the same speakers at different times.

Speakers
In the ROOT PRIM of the speakers, put this script:
CODE
// Speakers, Root Prim
// By Huns Valen
integer SNDCHAN = -12345;

default {
state_entry() {
llListen(SNDCHAN, "", "", "");
}
listen(integer chan, string name, key id, string msg) {
llMessageLinked(LINK_SET, 0, msg, "");
}
}


In every prim in the speaker set that you want to act as a speaker, put this script:
CODE
// Speakers, put this in whatever prim you want to act as a speaker
// By Huns Valen
float volume = 1;

default {
state_entry() {
llSetSoundQueueing(TRUE);
}
link_message(integer snum, integer num, string str, key id) {
llPlaySoundSlave(str, volume);
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
03-24-2006 20:05
/15/a5/95864/1.html
_____________________
i've got nothing. ;)
Zypher Crash
Charter Member
Join date: 17 May 2003
Posts: 55
06-17-2006 22:33
hehehe, did this back in beta. sounds good from more than 1 source, even better than standard headphones. Just never released the speakers, but did the player. Ill have to test this one to see how it sounds compared to my old school one.
_____________________
Anything I'v posted was not posted to soley point someone out nore discredit any persons mentioned. The Above is soley my own oppinion that witch I am entitled to. Any flame or comments welcome But will be ignored. Unless specified other.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
06-17-2006 23:38
ive done this before but in a different way, needless to say interesting :)

(mostly different in the main script, follows the same basics tho)
Zoz Quandry
Registered User
Join date: 18 Nov 2008
Posts: 3
12-21-2008 12:26
excuse the noob question but i did try find the answer elsewhere fruitlessly :)

do i have to remove the PHP quotes or something? if i place this in an object i get nothing clickable.
I've paid for a few scripts only to find they dont do what i need them to do already and it would be great to work out his stuff myself. Sound & Photoshop i can do but not scripting yet :)

My home at sunsplash village has an open interactive music studio, drum circle & singing stones meditation area... i want to get as much options involved as possible. maybe theres a scripter out there who wants to work with me? I'm interested in building imaginary instruments & sound equipment so people can produce & mix creatively in a easy to use environment.

peace
Zozzy
Abraxes Binder
Registered User
Join date: 23 May 2008
Posts: 205
12-22-2008 01:09
Zoz, the 'PHP' is a 'board-tag' and you should not include it in your code.
The idea behind the php-tag is to preserve indentations on the code. This can ONLY be seen if you click the 'Quote' button. The text will now be formatted as the orr. poster intended.
This embedding is often misunderstood by posters on this board and they embed their code in a 'Quote'-tag. This does however not work at all :)
BR
ab
_____________________
BR ab
Chalice Yao
Registered User
Join date: 30 Jan 2007
Posts: 14
12-23-2008 02:02
There is, sadly, a bug in the SL sound system FMod that will make sounds, if played synchronously from several prims, to lose their quality drastically if you start to move the avatar around. Not the camera, the avatar.

This can be best witnessed if you use around 3-4 prims with sound slaves to play a song, and then take a single step. The doppler effect does not drop, and the music either loses all its deep frequencies, or the high ones.

This is fixed with the new opensource OpenAL sound system that is currently part of the 1.22 code trunk. Let's hope it'll be the default in the 1.22 final viewer, as it also gives us surround sound support.
Ollj Oh
Registered User
Join date: 28 Aug 2007
Posts: 522
12-23-2008 05:24
to any music script i say this:
- if it doesnt use a do{ makenoise() }while(track--); loop it is wasting memory, that is critical for timing and bandwidth of music scripts.
- if it doesnt use {llPreloadsound (nextsound()); llSleep(( tracklength/llGetRegionTimeDilation() ) -1);} it is poorly timed for not taking time dilation into its timing calculation!

thanks for a key to "10 secs quiet", its not really needed in this script may be usefull someday.

The doppler effect can be very nasty and casn be reduced to zero in your settings