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): WaveReader.zip

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.

Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest

10 thoughts on “Mix Wave files with Actionscript! (with source)

  1. December 08? Hmm… so who’s paying? πŸ˜›
    This sample is nice though, I wonder if with a little work you could convert sample rates too, it’s all numbers right? πŸ˜€ Cheers, EP.

  2. Hi,
    One more time, i can’t trying your application on MacOSX because unfortunately that’s crash.
    It’s again the Browse methos who shit
    here in your code :
    file = File.desktopDirectory;
    file.addEventListener(Event.SELECT, onOpen2);
    file.browseForOpen(“Open Wave File”, [new FileFilter(“wave”,”*.wav”)]);
    It’s a big bug in AIR 1.0, i don’t understand and hope Adobe will make an update soon.


  3. Hallo Benjamin,

    You are in Berlin, right? I am going to be over there for a couple of days starting on Wed Sept 26th. I am a Flex developer in Boston but I am really curious about what people are doing with Flex and AIR around the globe. Since I am going to be overthere, I thought it would be a good opportunity to meet with other Flex/AIR developers.

    Let me know, if you would be available.

  4. Hi! This sample seens very nice, but unfortunately it won’t open on the current version of Adobe Air. Any ideas?

  5. I’m trying to use this concept in another programming language, but there’s a part of the code I don’t understand. The largest value of a byte is 255. when you add the value of some of the bytes together they are larger than 255. yet this code even has an if statement to check to see if the value is larger than 32767. Whats happening here?

    sn2 = waveReader2.bytes.readShort();
    var newSample = sn1+sn2;

    if(newSample > 32767 || newSample < -32768){



  6. I get the same 404 Error …
    Can you send me a link to download the source code?
    Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *