Scripting a musical instrument? a lil help please :)
|
|
falney Finney
Freedom is just a word
Join date: 18 Dec 2006
Posts: 66
|
02-25-2007 17:48
Hi... Im trying to script an instrument to play a track.... I'm pretty new to coding so Im half expecting you people to look at this and have a chuckle to your self.... but running through pseudo code and the Wiki... this is the best Ive come up with and it doesn’t work..... in this code there is 30 secs of music and all I hear is a "dum" when I click the prim with it in.
Well as you can see.... Ive had a go... if a pathetic one... and I was wondering if one or more of you could push me in the right direction... I want to link in total 45 sound files and then in the future I will be expanding it with a menu to select other tracks.
Well.... could you tell me what I’ve done wrong please?
Thanks
Falney
:: code ::
float VOLUME = 1.0;
default {
touch_start(integer total_number) { llSetSoundQueueing(TRUE); llPlaySound("s1", VOLUME); llSetTimerEvent(9.0); llPlaySound("s2", VOLUME); llSetTimerEvent(9.0); llPlaySound("s3", VOLUME); } }
::Edit::
After posting this, I found a script that does what I want at this stage, But personally I would rather learn how todo it myself than copy some one elses work.... Morals and all... Also if I learn how to do it I can replicate it in the future and use it when I make the instrument menu driven...
|
|
Jeff Kelley
Registered User
Join date: 8 Nov 2006
Posts: 223
|
02-25-2007 19:20
llSetTimerEvent() fires a timer but does not delay the script. Use llSleep() instead. But you'll never be able to get continuous audio. The timing is not accurate enough compared to what the ear needs to be happy. Please, don't murder Mozart 
|
|
AJ DaSilva
woz ere
Join date: 15 Jun 2005
Posts: 1,993
|
02-25-2007 21:28
I haven't really played with sound yet, but from the looks of it you should be able to get continuous audio if sound queueing has been set (really slow servers or insanely long tracks could get out of sync still though). You'll don't need the first sleep you've got either - you want the queue to be filled as soon as there's a free slot. The idea is to always be loading the next file while the current one is playing. IIRC a timer event would be better than using sleeps too, but don't quote me on that. I'd start with something like this: integer volume; integer trackPos; integer trackParts;
string trackName;
playTrack( string _name, integer _parts ) { trackName = _name trackParts = _parts; trackPos=2; llPlaySound( trackName + "0", volume ); llPlaySound( trackName + "1", volume ); llSetTimerEvent( 10 ); }
default { state_entry { volume = 1; llSetSoundQueueing( TRUE ); }
touch(integer _n) { playTrack( "myTrack", 20 ); } timer() { llPlaySound( trackName + (string)trackPos, volume); trackPos++; if( trackPos == trackParts ) llSetTimerEvent( 0 ); } }
|
|
falney Finney
Freedom is just a word
Join date: 18 Dec 2006
Posts: 66
|
02-26-2007 02:43
From: Jeff Kelley llSetTimerEvent() fires a timer but does not delay the script. Use llSleep() instead. But you'll never be able to get continuous audio. The timing is not accurate enough compared to what the ear needs to be happy. Please, don't murder Mozart  Hehe I know about the delay on the script.... an no its not Mozart.............. Beethoven Nah Ive no idea who it is.... a friend said "can you script" and me being an egotistical moron said "A bit" and then she asked me todo something ive never even thought of.... how ever if I could get the track allignment set up for a lagless day, I might put the 9min version of Lead Zeplin, Stair way to heavern on my Guitar *grins* From: AJ DaSilva I haven't really played with sound yet, but from the looks of it you should be able to get continuous audio if sound queueing has been set (really slow servers or insanely long tracks could get out of sync still though). You'll don't need the first sleep you've got either - you want the queue to be filled as soon as there's a free slot. The idea is to always be loading the next file while the current one is playing. IIRC a timer event would be better than using sleeps too, but don't quote me on that. I'd start with something like this: integer volume; integer trackPos; integer trackParts;
string trackName;
playTrack( string _name, integer _parts ) { trackName = _name trackParts = _parts; trackPos=2; llPlaySound( trackName + "0", volume ); llPlaySound( trackName + "1", volume ); llSetTimerEvent( 10 ); }
default { state_entry { volume = 1; llSetSoundQueueing( TRUE ); }
touch(integer _n) { playTrack( "myTrack", 20 ); } timer() { llPlaySound( trackName + (string)trackPos, volume); trackPos++; if( trackPos == trackParts ) llSetTimerEvent( 0 ); } } Thanks... I will have a play around with this.... say there is 30 sound files would you know if I would be able to use the llpreloadsound to cache the first say 20 secs of the song before it starts playing then cache the rest of the song through out so the only delay is in client side lag (or server side knowing LL *sniggers*) andthe script delay.
|
|
Jeff Kelley
Registered User
Join date: 8 Nov 2006
Posts: 223
|
02-26-2007 04:51
From: falney Finney there is 30 sound files would you know if I would be able to use the llpreloadsound to cache the first say 20 secs of the song before it starts playing then cache the rest of the song through out so the only delay is in client side lag (or server side knowing LL *sniggers*) andthe script delay. Assuming the next buffer would be present in the client when playing the previous, you won't control the start time with enough precision. We are speaking of 1/44100 of a second, 22 micro-seconds. Some SL jukeboxes work this way, and they pause randomly about 1/10s to 1/2s between files. That's just audio garbage.
|
|
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
|
02-26-2007 05:01
Not to mention that the symantics of llPlaySound are roughly "if this sound has actually been received by the client despite audio being given the lowest possible priority of everything SL wants to send to the client please play it". llPlaySound is more like a suggestion than a command.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
Lol
02-26-2007 05:31
From: Malachi Petunia Not to mention that the symantics of llPlaySound are roughly "if this sound has actually been received by the client despite audio being given the lowest possible priority of everything SL wants to send to the client please play it". llPlaySound is more like a suggestion than a command. The way SL is running atm I feel every LSL command is only a suggestion!
|
|
Snow Gretzky
Registered User
Join date: 20 Oct 2005
Posts: 23
|
02-26-2007 08:00
From: Newgate Ludd The way SL is running atm I feel every LSL command is only a suggestion! Best laugh I've had in a long while NL. ty. And as far as stringing a bunch of 9.999 second clips together and calling it a tune, . . . it just don't make it. It may work now and then but as a viable vehicle for CDs, instruments, etc, as often as not, it's just a frustrating experience. I've always suspected that the reason LL won't allow longer clips is a worry over copyright infringement and if this is the case then we won't ever see full-length songs consistantly playable in SL. Unless LL would consider "licensing" some residents to upload tunes that either are original material or in the public domain.
|
|
falney Finney
Freedom is just a word
Join date: 18 Dec 2006
Posts: 66
|
02-26-2007 09:03
From: Snow Gretzky Unless LL would consider "licensing" some residents to upload tunes that either are original material or in the public domain.
I cant see that happining..... I guess another way of doing it would be to post it on my webserver and use a streaming script for it... but then I need to worryabout streaming permissions right? also it costs me bandwidth rather than LL... Ive got it running... and after having what feels like 10 yeas of frustration playing with the timings.... I went back and re-split the music.... splitting it at natual breaks as much as possible.... as long as there isnt too much lag interfearing with it, it doesnt sound too terrible... but if I can get an easy way around it.... eg sleep with the sim owner.... I might try streaming it...
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
One addition to the breaks..
02-26-2007 11:03
Also, I have found that if you break the clips up into 7.8 - 8 second clips - it actually works out pretty good most of the time. Prelloading a tune, then playing it, then sleeping for 6.8 then the loopback to continue on. It seems to have worked out pretty well now that I've finally got it all cleaned up. Thanks to people here. Anyway, no scripting advice to give really, but as far as file lenght - it appears that th magic number seems to be around 8 seconds for a nice seamless tune. (As seamless as SL gets that is... LOL) Have fun!  Oh yeah, don't make my mistake, keep your channels random! LOL c-me! Hap
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
02-26-2007 13:47
How do you break a sound file into 8 second long pieces?
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
02-26-2007 14:45
Well... just use an audio editor?? If I understand what you're asking. I just use Audacity because it has the best timeline / slidebar display so it's easy to tell where you're at in the wave-form. (Plus it's free to boot) All you do is open your .wav file in Audacity. (or most any sound file) Go out into the file (or out to the right) 8 seconds. Click and hold... then drag back to the beginning. This will select everything from 8 seconds (usually you end up snagging around 7.997 to  Then you cut that. Open a new file Paste it Export it as a new .wav file named "Your_Sounds_Name_1.wav" Then just repeat that process until you have literally "cut" your file into nothing - 8 seconds at a time, while at the same time having created new 8 second blocks of Sound1.wav, Sound2.wav, etc. It's really pretty easy once you've done it. If you already have sounds chunked out into 10 second files... well that's a whole different story. Just stick with it, or I can tell you privately or something. You have to put it all together, then break it up. Take care! Hap
|