[AS3]SOUND MIXING – SING ALONG, RECORD AND SAVE

August 19, 2011 at 2:18 AM (Actionscript) (, , , , , )

The idea is to achieve sound mixing in actionscript…with actionscript’s recent ability to capture microphone data thought it would be apt to try this by building karaoke app in flash…

1. The background sound is loaded from a playlist..
2. On Click of ‘record’ button the microphone data is captured and mixed with audio playing in the background
3. On background audio finishes playing..the mixed audio encoded into wave and saved to local disk

How mixing of two sound tracks is achieved:
Lets say source_1 and source_2 are two audio tracks, to mix these two audios

var source_1_L:Number=source_1.readFloat();//left channel of audio source_1
var source_1_R:Number=source_1.readFloat();//right channel of audio source_1
var source_2_L:Number=source_1.readFloat();//left channel of audio source_2
var source_2_R:Number=source_1.readFloat();//right channel of audio source_2
var mixed_L:Number=source_1_L+source_2_L;/left channel of mixed audio track
var mixed_R:Number=source_1_R+source_2_R;/right channel of mixed audio track
//!-the added values should be between -1 to 1
//!-to make sure the aded values fall within the limits
mixed_L=mixed_L>1?1:(mixed_L<-1?-1:mixed_L);
mixed_R=mixed_R>1?1:(mixed_R<-1?-1:mixed_R);
//!- [OR]
var mixed_L:Number=(source_1_L/2)+(source_2_L/2);/left channel of mixed audio track
var mixed_R:Number=(source_1_R/2)+(source_2_R/2);/right channel of mixed audio track

//!-now,
 mixedTrack.writeFloat(mixed_L);//mixedTrack is a ByteArray where the mixed audio data is written
 mixedTrack.writeFloat(mixed_R);

Attaching a source and demo of simple karaoke app in flash(cs5):The source code is bit messy and this is not a full application
just proof of concept…
Download the source here:
Link 1:Karaoke.zip
Link 2:Karaoke.zip

Advertisements

Permalink 23 Comments

« Previous page · Next page »

%d bloggers like this: