Richapps@MAX: What do you want to know about ByteArrays?

It`s official now! I will have a session at MAX in Barcelona. The session will be called “Bits and Bytes with AIR”.
I have a basic outline for my talk finished. It will be an introduction targeted at the intermediate Flash/Flex/AIR developer for whom the ByteArray class is still a mystery and who wants to find out more about its use. Part of the talk will be about the very basics (bits and bytes) and the other part will be a more practical one where I show how you can put this knowledge to good use ( Analyzing and manipulating Mp3, Wave, SWF and FLV files).  I want to take one example and explain it in more detail. I thought of showing how to analyze an FLV file and extract the sound as an mp3 or how to mix two wave files.
So it would be cool if you would leave a comment what you`d like to get explained. This is your chance to make this a valuable session for everyone. Go ahead leave a comment or write me a mail to: benz (at)

Reading Waveform and mixing Waves with AS 3.0 (source included)

So here is part 2 (part1) of this nights sleepless hours product.
This is a little example of how to load multiple wave files and show the waveform of each wave file.


You can also save a Mix of all files as one wav. This uses my new Wave Mix class which is super simple to use.
You have to pass it an Array of WaveReaders in the constructor like this:

var waveMix:WaveMix = new WaveMix(myWaveReaders);

Then you just call the mix() method of the WaveMix class and it return a ByteArray which is the new wave file.
You can now use this to save the bytes to the filesystem or send them to a server.
var waveBytes:ByteArray = waveMix.mix();

There are still some problems with wave files of different sample sizes. It works best if all files are 44500 Hz, 16Bit, Stereo wave files.
I`ll work on that :-)
I know it`s al a bit ugly unfinished code but it`s all from one night so bear with me.

Get The AIR file here.
and Code here.

Load and Play .wav files at rumtime with AS 3.0 (source included)

This is a follow up to my previous post about mixing wav files with Actionscript. I couldn`t sleep tonight so I have hacked together some classes that make it easy to load and play wave files at runtime with Actionscript 3.0.
You know that it`s not natively possible to load and play wave files at runtime. The trick is to load the wave file as a ByteArray (e.g. with Loader, FileStream, URLStream…) and than construct a swf file in memory that has the wave bytes embedded. First i created a swf file in memory that has the wave sound embeded and played it back with a StartStream-Tag. I did not liked that method because it does not give you good control over the playback of your sound. So the solution was to create a SWF file that defines a sound that is linked to a class so you can access the Sound Object directly. For those interested in details here is how the SWF file that i create in memory looks like:


Here is a overview of the classes you need if you want to load a wave at runtime:


What the WaveMix class is for will be revealed in the next post :-)
In order to load a wave sound these are the basic steps:
// Create a new Wave Reader
waveReader = new WaveReader();;

// Create a wave SWF
var waveSwf:WaveSWF = new WaveSWF(waveReader);
waveSwf.addEventListener(Event.COMPLETE, onWaveReady);

private function onWaveReady(evt:Event):void{
sound = WaveSWF(;
channel =,0);

Now you can use all methods of the Sound Object to work with your sound.

All this is still a bit buggy (all hacked together this night :-). So use it at your own risk.

I`ve prepared a little example in AIR that let`s you load a wave sound. The Wave has to be a PCM encoded (uncompressed) wave file.
Download AIR Example
Download Flex Project (Source)
Let me know what you think 😉
This was a pretty long night :-) so in the next post i`ll add something to this (reading waveforms + mixing sounds)

Mix Wave files with Actionscript! (with source)

Today Alan Queen pointed me to his AIR application that allows to mix wave samples. It`s a really nice AIR application but what was the most remarkable thing is that it actually mixes samples and outputs a new wave file. That`s what i always (and still ;-)) dream to do with RichFLV but reencoding FLVs and Mp3 files with actionscript may not be possible because of the complex algorithms used for compression. But still i had to find out how it`s possible with Wave files. The trick is that the wave files have to be in PCM format. PCM is a periodical measure of acoustic pressure at regular intervals and thats why it`s possible to easily modify samples of PCM data with simplest math lik addition :-) In order to mix two samples you just sum up the values of the two samples. Crazy easy!
So here is a quick and really dirty test:


This AIR app mixes two wave files. The wave files should have the same sample rate and have to use PCM encoding. I did not test it really well and stopped working on it when i got some results so this might not work with all waves. Yeah it`s pretty ugly (codewise) but i think i will not put more time into this so i thought i share this information and my code. I was also able to do some other modifications like modifiying the volume and stuff like that.

Get the AIR app: WaveReader.air
Get the Flex Project (source):

Now I go back to my super cool AIR project I`m working on ( to be released in december 08 07 ;-)) . And I`ve also started to work on RichFLV Version 2! Yeah i skip version1.0 and go directly to 2.0. In this version you`ll be able to import multiple FLV and Mp3 files and merge them together with all the export and editing functionality of version 1. Ah yeah and i`ve not forgotten my article series :-) I`ll continue that soon – hopefully.