Problems with playing music by script.
|
|
Selador Cellardoor
Registered User
Join date: 16 Nov 2003
Posts: 3,082
|
08-01-2007 08:13
I have written the following script which is designed to play 10 second segments (actually 9.8 seconds, because sl doesn't seem to accept anything longer than this):- integer play = 0; integer listp = 0; string segment; default { state_entry() { llSetSoundQueueing(1); } touch_start(integer total_number) { do { listp++; segment="soldat_"+(string)listp; if (listp == 1) llSay(0,""  ; llPlaySound(segment,1.0); llSleep(9.  ; }while (listp < 20); llResetScript(); } } The result is completely variable. Sometimes it plays right through - sometimes there are long gaps between segments, and sometimes segments are missed out. Is this due to my crap scripting, or problems to do with the way that Second Life deals with audio files?
|
|
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
|
08-01-2007 10:08
have you experimented with LlPreloadSound()?
|
|
Selador Cellardoor
Registered User
Join date: 16 Nov 2003
Posts: 3,082
|
08-01-2007 11:52
I had a look at that, and the explanation in the Wiki left me as wise after reading it as I was before. What does it actually do? If it is to do with preloading sounds in buffers, bear in mind that these are pieces lasting five minutes or more and are pretty large in all.
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
08-01-2007 12:38
llPreloadSound() is supposed to tell the client to go ahead and download the asset (sound file) in preparation to be played shortly thereafter. However, when preloading sounds in a long series of strung-together clips, you are at the mercy of the asset server and any associated lag, and with the client's cache manager. In the latter case, if you preload too much, some of the sound clips may get garbage collected before you get around to playing them. My best advice is to do something like this: llSetSoundQueueing(TRUE); // to keeps the currently playing sound from being interrupted when you tell the next one to start. llPreloadSound("segment0"); llSleep(10.0); // give time for the client to load the first segment integer segment_num = 0; integer segment_count = 10; // set to have however many segments float clip_length = 9.8; while (segment_num < segment_count) { llPlaySound("segment"+(string)segment_num,1.0); ++segment_num; llPreloadSound("segment"+(string)segment_num); if (segment_num == 1) llSleep(clip_length / 2.0); // offset the first segment timing back a little bit to ensure time for a smooth transition else llSleep(clip_length); }
That *should* give you a smooth transition, assuming that the asset server doesn't get behind; unfortunately, there's no way to guarantee that, so you just have to hope for the best.
|
|
Selador Cellardoor
Registered User
Join date: 16 Nov 2003
Posts: 3,082
|
08-01-2007 13:46
Yes, thanks for that. I have just got back from running a version of the script which loaded sound_number+1 before it went on to play sound_number. That worked perfectly (apart from the gaps mentioned below) on one object, but when I tried the same script in another one it did a lot of weird things, like looping. Ok, I will try your method, although I did find that if I let the script sleep for the length of the clip the processing caused ugly gaps between segments, and if I reduced the sleep I got chaos.  Back to the drawing board. Will report back. 
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
08-01-2007 14:22
The gaps are caused by the llSleep lingering a bit longer than it should, which it will do. That's why I start the sleeps in the middle of the first clip and use llSetSoundQueueing(TRUE). That way, they can drift a bit, but should not drift far enough to cause it to skip for the life of an average song. Now, if you are looping, eventually, it will skip or do other weirdness.
You can also try to adjust the sleep time down a hair until it stops skipping, but the problem is that llSleep (and llSetTimerEvent/timer()) are woefully inaccurate, as they are highly sensitive to sim lag. Eventually, after enough repetitions, you will get random skips.
|
|
Selador Cellardoor
Registered User
Join date: 16 Nov 2003
Posts: 3,082
|
08-03-2007 15:28
Nope. Still got the same results with your script as I got with mine. One day we will have an sl mp3 playing function. 
|
|
Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
|
08-03-2007 15:38
While having the queueing on and starting the next clip before the previous is done -helps,- it does not solve the problem that on older sims, or on high-traffic days, or any other time in which sounds will play long after they're called, the song will still come out choppy. I've got a jukebox player that I'm working on that has the same problem; It works after the second or third playing of the same song, when all the pieces have been fully loaded, but prior to that, I'm lucky to get half the song, even if it preloads, or even PLAYS (At .01 volume) all the sound clips when it begins prepping the song. I've also noticed that having the pause between clips too short with queueing tends to make it skips bits later on, so you can't have it too close to the beginning.
|