Copy link to clipboard
Copied
I am trying to unmute the microphone to make it make it work with a Spectrum Analyser.
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.SampleDataEvent;
import flash.media.Microphone;
import flash.media.Sound;
import flash.media.SoundMixer;
import flash.utils.ByteArray;
var mic:Microphone = Microphone.getMicrophone();
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
var _soundBytes:ByteArray = new ByteArray();
var _micBytes:ByteArray;
var _micSound:Sound;
initMic();
import SpectrumAnalyzer;
var visualization:SpectrumAnalyzer = new SpectrumAnalyzer( 550, 400);
addChild(visualization);
var soundIsOn = true();
function changeSound{
var st:SoundTransform = new SoundTransform();
if(soundIsOn)
{
st.volume = 0;
SoundMixer.soundTransform = st;
soundIsOn = false;
}
else
{
st.volume = 1;
SoundMixer.soundTransform = st;
soundIsOn = true;
}
}
function initMic():void {
if ( mic ) {
mic.rate = 44;
mic.gain = 50;
mic.setSilenceLevel(5);
trace("Microphone available, setting up sound objects");
initSound();
}
else {
// no mic
}
}
function micSampleDataHandler(event:SampleDataEvent) :void {
trace("Mic data available");
_micBytes = event.data;
_micSound.play();
}
function initSound():void {
_micSound = new Sound();
_micSound.addEventListener(SampleDataEvent.SAMPLE_DATA, soundSampleDataHandler);
}
function soundSampleDataHandler(event:SampleDataEvent):void {
trace("Sound object needs more sample data");
for (var i:int = 0; i < 8192 && _micBytes.bytesAvailable > 0; i++) {
var sample:Number = _micBytes.readFloat();
event.data.writeFloat(sample);
event.data.writeFloat(sample);
}
}
stop();
No doubt there is more going wrong, but first, this:
function changeSound{
should be:
function changeSound() {
Copy link to clipboard
Copied
No doubt there is more going wrong, but first, this:
function changeSound{
should be:
function changeSound() {
Find more inspiration, events, and resources on the new Adobe Community
Explore Now