all groups > flash actionscript > may 2005 >
You're in the

flash actionscript

group:

Studder in music loop


Studder in music loop jeskey
5/9/2005 12:00:00 AM
flash actionscript:
I have a noticable studder in my music loop when it repeats. I know my loop is
good as I have heard it on another site and it works fine, unfortunately, i do
not have access to that code.

I assume there are different ways to code the action script. Can someone
point me in the right direction?

Thanks.
Re: Studder in music loop David Stiller
5/9/2005 12:00:00 AM
jeskey,

[quoted text, click to view]

This generally happens when A) the sound is not cut on rythm or B) the
sound is loaded from an external file.

[quoted text, click to view]

Good, then it's not the way the sound file was cut. Believe it or not,
though, it probably has nothing to do with the ActionScript. Given the
nature of the MP3 format, the audio is saved into "chunks" that may (but
usually do not) coincide with the timing of a sound file's exact end. I'm
betting the loop on that other site works because it was imported into the
FLA itself as a WAV file.

[quoted text, click to view]

If you want the sound to loop, import it as a WAV, then use whatever
method you please. The shortest ActionScript I know is ...

var mySound = new Sound(this);
mySound.attachSound("LinkageIdFromLibrary");
mySound.start(0, 999);

.... which will loop the sound 999 times (as good as "loop continuously,"
which is a feature Flash does not support without custom programming).


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Re: Studder in music loop jeskey
5/9/2005 12:00:00 AM
This is an MP3 file referenced in an external xml document.

Does this mean i will have to include it in the flash file as a wav file? It
is 269K and i am afraid it will greatly effect the download as the swf is
currently 113k.
Re: Studder in music loop jeskey
5/9/2005 12:00:00 AM
Sorry, I am very new to Flash. The mp3 is 260K, the WAV when i converted it was
like 2.6 megs (no way) and i know the Flash movie that i got this from whicj
works fine is using an MP3(same file).

This is the code in my AS file which i kind of understand. What would i have
to do to accomlish what you suggest? I guess i actually do not mind the mp3 in
my SWF if it does not hold the entire movie from starting until it loads.


// Loader
audio.trackName=currNode.attributes.SRC;
audio.stopped=false;
audio.snd=new Sound();
audio.snd.loadSound(audio.trackName);
audio.state=1;
audio.tween("_alpha",0,0.3,mylinear,0);
intHolder.snd=setInterval(preloadSnd,50);

//Preloader code
function preloadSnd(){
var perc=preloadMc(audio.snd);
if (perc>=100){
audio.stopTween();
audio._alpha=0;
equalizer._visible=true;
audio.snd.start(1,9999);
clearInterval(intHolder.snd);
}
else{
if (!audio.isTweening()){
if(audio.state){
audio.state=0;
audio.tween("_alpha",0,0.3,mylinear,0);
}
else{
audio.state=1;
audio.tween("_alpha",100,0.3,mylinear,0);
}
}
}

}
Re: Studder in music loop Patrick Bay
5/9/2005 7:33:46 PM
Hi,

David's post is correct.

The MP3 format appends about 10 milliseconds of silence to the beginning of your
audio. Unfortunately, this is not removable by any means (it has to do with the
way the ecompression software works). For looped sounds you must import them as WAV.

An excellent (and free) audio editor/converter is Audacity
(http://audacity.sourceforge.net/). Although the support for audio formats is
somewhat limited, it will do what you need it to do.

Regards,
Patrick

[quoted text, click to view]
Re: Studder in music loop David Stiller
5/9/2005 8:00:44 PM
[quoted text, click to view]

It would if you imported the WAV into your main file, but why not import
the WAV into its own FLA (just a tiny 32 x 32 pixel thing), then load that
SWF externally? It's not entirely the same as loading an MP3 at runtime,
but you can still do a preloader, you can still keep that audio from being
directly embedded, and you can still loop it seamlessly. :)


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Re: Studder in music loop David Stiller
5/9/2005 9:10:43 PM
[quoted text, click to view]

Flash will reduce that 2.6 MB to a surprisingly small number. I
wouldn't be surprised at all if Flash compresses your WAV down to the same
size as a comparable MP3.

[quoted text, click to view]

As Patrick concurred, the nature of the MP3 file format simply makes
this an almost impossibility. One could argue, based on the nature of the
music's rhythm, that the proper coincidence of "chunks" and timing is
possible, but very, very unlikely. It may be that the MP3 timing issue is
decreased or avoided when MP3s are imported by hand directly into the FLA
.... maybe that's it.

[quoted text, click to view]

If you're doing what I suggest, you'll start a brand new FLA and import
the MP3 or WAV file into that. The only thing in this new FLA will be your
embedded audio file, which you'll drag to frame 1 of the main timeline and
set to loop 999 times in the Properties inspector, or use the ActionScript I
posted earlier. Then you'll publish that FLA into a SWF, fiddling with the
Publish settings to get the file size down as small as possible while trying
to retain as much audio quality as you can.

Then you'll load this SWF via ActionScript into your main FLA, rather
than loading an MP3.

[quoted text, click to view]

Experiment with it. If you import directly into your existing FLA, you
may find that you can live with the increased file size. I think you're not
seeing it yet that importing a WAV won't hurt your FLA. Even if the WAV is
several megs, your SWF won't be, unless you don't compress the audio. In
comparison, it is standard practise to import graphics as non-compressed
BMPs (which can be huge), then rely on Flash's JPEG compression to decreased
the file size of the SWF.

[quoted text, click to view]

Of the above code, two lines are almost identical to what I posted
earlier ...

audio.snd = new Sound();
audio.snd.loadSound(audio.trackName);

Those are the only two that have anything to do with loading sound. The
rest is all graphics. I don't know where you found this code, but it will
help you tremendously to fully understand it. :) Start with the basics in
a brand new FLA -- just to avoid the clutter of what's already in your
existing FLA -- check out the "Sound class" entry in the ActionScript
Language Reference (F1 key), and dive in. There are examples galore, and
you'll thank yourself to starting with the unadorned fundamental building
blocks first.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Re: Studder in music loop jeskey
5/10/2005 12:00:00 AM
Thanks David. I appreciate your detailed answer and the time it took to write it. I will start playing around with your suggestions.

Again, yhanks for your time.
Johnm
AddThis Social Bookmark Button