actionscript 3 - Flash 10.1 AS3 - Applying realtime effects to Microphone - stutter problems -
i'm trying write flash application takes microphone stream , applies realtime effects , outputs speakers.
i'm finding i'm having problems stuttering when taking output mic, copying bytearray amd using seperate
sound = new sound();
sound.addeventlistener(sampledataevent.sample_data, processsound);
sound.play();
to read bytearray , play sound.
i have noticed input mic's bytesavailable changes, , 2 events (the mic's sample_data , sound's sample_data) aren't firing b b b b needed more random.
am right in thinking mic.sample_data event fires @ different intervals different amounts of data , working implementation need read available data in , buffer input sound sampledataevent have play avoid stuffering?
i found solution thought i'd post on here incase else had similar problems (many google searches turned nothing me).
it seem input mic fed through inconsistently, , bytes sent through needed in order process sound. key getting work use array buffer input.
private var mic:microphone; private var micbuffer:array; private var playbacksound:sound; //the effect applying needed applied private var _leftchannel:vector.<number> = new vector.<number>(8192/2); private function init() { micbuffer = new array(); mic = microphone.getmicrophone(); mic.rate = 22; mic.addeventlistener(sampledataevent.sample_data, micsampledata); } private function micsampledata(e:sampledataevent) { //store sent microphone array - vary in length while (e.data.bytesavailable > 0) micbuffer.push(e.data.readfloat()); //can wait here array reach size if needed if (!playbacksound) { playbacksound = new sound(); playbacksound.addeventlistener(sampledataevent.sample_data, processsound); playbacksound.play(); } } private function playbacksoundsampledata(e:sampledataevent) { //this number change depending on sample rate of microphone var numberoffloats = 8192/8; (var = 0; i<numberoffloats && micbuffer.length > 0; i++) { _leftchannel[i] = micbuffer.shift(); count++; } //apply effect //sample rate here half of 44 write twice + twice again make stereo for(var = 0 ; < count ; ++i ) { e.data.writefloat( _leftchannel[i] ); e.data.writefloat( _leftchannel[i] ); e.data.writefloat( _leftchannel[i] ); e.data.writefloat( _leftchannel[i] ); } }
Comments
Post a Comment