Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No mic activity with setLoopBack set to false - AS3

Trying to figure out why setloopback needs to be set to true for microphone activity to be detected.

The problem is the echo feedback when using a macbook with a built in mic.

If anyone has some ideas about this let me know.

Right now I'm experimenting with toggling gain, depending on activity to simulate echo reduction. Not optimal though.

@lessfame

like image 495
Franky Avatar asked May 29 '10 23:05

Franky


2 Answers

I was looking for a similar solution to this one, then I found you that you can apply a sound transform to a microphone to control the volume of the outputted volume of the microphone input.

So it can be done this easily:

var st:SoundTransform = new SoundTransform(0);
mic.soundTransform = st;

I know you asked this question almost a year ago now, but thought I'd put it up for anybody looking for an answer.
Cheers,
Will

like image 119
WillDonohoe Avatar answered Nov 10 '22 09:11

WillDonohoe


I know this is an old question but just came across the problem.

There is a bug with the SPEEX codec as noted here: Microphone soundTransform and SPEEX codec bug

This bug basically says that using the SPEEX codec ignores the sound transform. As a work around for this I setup a toggle function to switch the settings for the microphone to display activity before the audio is attached to a NetStream and to work around the bug.

Note: A Microphone object only dispatches Activity events when your application is monitoring the microphone. Thus, if you do not call setLoopBack( true ), add a listener for sample data events, or attach the microphone to a NetStream object, then no activity events are dispatched. AS3 Docs

Setup the Mic: (m is an instance variable)

m = Microphone.getMicrophone();
m.setSilenceLevel(0);
m.gain = 75;
m.setUseEchoSuppression(true);
m.rate = 16;    //rate only applies to NELLYMOSER Codec - but 16 kHz matches SPEEX default setting
m.setLoopBack(true);    //necessary to get activity
m.codec = SoundCodec.NELLYMOSER;    //this is default
m.soundTransform = new SoundTransform(0);    //mute so you don't get crazy echo!

Toggle for 'offline' and 'online' activity monitoring

protected function audioMeterToggle(switch:String) {
    if(switch == "offline") {
        m.setLoopBack(true);
        m.soundTransform.volume = 0;
        m.codec = SoundCodec.NELLYMOSER;
    } else {
        m.setLoopBack(false);
        m.soundTransform.volume = 1;
        m.codec = SoundCodec.SPEEX;
    }
}

Switching codecs helps reduce bandwidth.

Hope this helps save someone some time.

like image 27
marcfrodi Avatar answered Nov 10 '22 07:11

marcfrodi