PDA

View Full Version : Generating an audio waveform


kyle.s.evans
10-02-2008, 08:45 PM
Are there any tricks that generate a static image of an audio waveform in AS3?

The way the ComputeSpectrum method is structured, it would appear you would have to cycle through an entire audio file to generate the amplitude information that you could weave into an image (you could probably use the EchoNest API similarly) - are there any other tools that would allow this to be done more directly? Any ideas?

Many thanks -
Kyle

lordofduct
10-03-2008, 01:11 AM
not directly from the Sound object, I couldn't say. From what I can tell the Sound object streams sound.

What I could suggest is to access a byteArray of the sound file itself. But this would be useless if it weren't in WAV format... mp3s and the sort are compressed so the binary data wouldn't accurately look like a WAVE form.

But if it were a WAVE file I guess you could use the URLLoader class to upload said sound file as binary data and then use that byteArray to paint a picture of the whole WAVE form from beginning to end.

Another suggestion would be to in one frame go through the entire Sound object and grab images of each moment in the song. The resolution wouldn't be as high, because you'd have to step through at increments of like 1 tenth of a second. But it'd get the job done I bet. It'd also probably take some time to process. But this would take care of decompressing mp3s and the sort.

wvxvw
10-03-2008, 11:19 AM
http://etcs.ru/pre/WAVPlayer/srcview/
Here's __etc's WAVE player that does something like you want. But, almost always you have WAVE files using some compression (and there's plenty of different compression types...), so, you'll need to write the decompressing algorithm yourself.

kyle.s.evans
10-03-2008, 09:15 PM
Many thanks for the responses (I really appreciate it) - after thinking a bit more about it, I'm not sure Flash is the right solution for this. We're going to go with a server-side implementation of a C script using the STK library, throw it into a high-res image, and store it for later recall.

kse

efnx
10-24-2008, 10:52 PM
I just wrote a class that will supply you with a left and right channel Vector full of data points from which you can draw your waveform. All it takes is your loaded sound object, then it dispatches events progressively until the entire waveform is computed. Here are the details: Flash Actionscript 3 Waveform Generation Class (http://blog.efnx.com/?p=90). Hope that helps. Feel free to comment with questions.