대역폭과 처리 리소스를 보존하기 위해 Flash Player는 아미크가 사운드를 전송하지 않는 때를 감지하려고 합니다. 마이크의 활동 레벨이 일정 시간 동안 묵음 레벨 임계값 미만을 유지하면 Flash Player는 오디오 입력 전송을 중지하고 대신 단순 ActivityEvent를 전달합니다. Speex코덱을 사용할 경우(Flash Player 10 이상 및 Adobe AIR 1.5 이상에서 지원)묵음 레벨을 0으로 설정해야 응용 프로그램에서 오디오 데이터가 연속적으로 전송됩니다. Speex 음성 활동 검출은 대역폭을 자동으로 줄입니다.

Microphone 클래스의 다음 세 가지 속성은 활동을 모니터링하고 제어합니다.

To conserve bandwidth and processing resources, Flash Player tries to detect when no sound is being transmitted by a microphone. When the microphone’s activity level stays below the silence level threshold for a period of time, Flash Player stops transmitting the audio input and dispatches a simple ActivityEvent instead.
Three properties of the Microphone class monitor and control the detection of activity:

 

 

● 읽기 전용 activityLevel 속성은 마이크가 감지하는 사운드의 양을 0~100의 등급으로 나타냄니다.

    The read-only activityLevel property indicates the amount of sound the microphone is detecting, on a scale from 0 to 100.

● silenceLevel속성은 마이크 활성화에 필요한 사운드의 양을 지정하고 ActivityEvent.ACTIVITY 이벤트를 전달합니다. silenceLevel 속성도 0~100의 등급을 사용하고 기본값은

    10입니다.

    The silenceLevel property specifies the amount of sound needed to activate the microphone and dispatch an ActivityEvent.ACTIVITY event. The silenceLevel property also uses a scale from 0 to 100, and the default value is 10.

● silenceTimeout 속성은 마이크가 현재 사용 중이지 않음을 알리기 위해 ActivityEvent.ACTIVITY 이벤트가 전달될 때까지 활동 레벨이 묵음 수준 미만을 유지해야 하는 시간을 밀리초

    단위로 정의합니다. 기본 silenceTimeout 값은 2000입니다.

    The silenceTimeout property describes the number of milliseconds that the activity level must stay below the silence level, until an ActivityEvent.ACTIVITY event is dispatched  to indicate that the microphone is now silent. The default silenceTimeout value is 2000.

 

Microphone.silenceLevel 속성과 Microphone.silenceTimeout 속성은 읽기 전용이지만 Microphone.setSilenceLevel() 메서드를 사용하여 이 값을 변경할 수 있습니다.

Both the Microphone.silenceLevel property and the Microphone.silenceTimeout property are read only, but their values can be changed by using theMicrophone.setSilenceLevel() method.


 

새로운 활동이 감지되었을 때 마이크를 활성화하는 프로세스에서 약간의 지연이 발생하는 경우도 있습니다. 마이크를 항상 활성화시켜 두면 이러한 활성화 지연을 방지할 수 있습니다. 응용 프로그램이 silenceLevel 매개 변수를 0으로 설정하여 Microphone.setSilenceLevel()메서드를 호출하면 Flash Player는 사운드가 감지되지 않더라도 마이크의 활성 상태를 유지하고 오디오 데이터를 계속 수집합니다. 반대로, silenceLevel 매개 변수를 100으로 설정하면 마이크가 전혀 활성화되지 않습니다.

In some cases, the process of activating the microphone when new activity is detected can cause a short delay. Keeping the microphone active at all times can remove such activation delays. Your application can call the Microphone.setSilenceLevel() method with the silenceLevel parameter set to zero to tell Flash Player to keep the microphone active and keep gathering audio data, even when no sound is being detected. Conversely, setting the silenceLevel parameter to 100 prevents the microphone from being activated at all.


다음 예제는 마이크에 대한 정보를 표시하고 Microphone 객체가 전달한 activity 이벤트 및 status 이벤트를 보고합니다.

The following example displays information about the microphone and reports on activity events and status events dispatched by a Microphone object. 

import flash,events.ActivityEvent;
import flash,events.StatusEvent;
import flash.media.Microphone;
var deviceArray:Array = Microphone.names;
trace("Available sound input devices:");
for (var i:int = 0; i < deviceArray.length; i++)
{
trace(" " + deviceArray[i]);
}
var mic:Microphone = Microphone.getMicrophone();
mic.gain = 60;
mic.rate = 11;
mic.setUseEchoSuppression(true);
Capturing sound input 621
mic.setLoopBack(true);
mic.setSilenceLevel(5, 1000);
mic.addEventListener(ActivityEvent.ACTIVITY, this.onMicActivity);
mic.addEventListener(StatusEvent.STATUS, this.onMicStatus);
var micDetails:String = "Sound input device name: " + mic.name + '\n';
micDetails += "Gain: " + mic.gain + '\n';
micDetails += "Rate: " + mic.rate + " kHz" + '\n';
micDetails += "Muted: " + mic.muted + '\n';
micDetails += "Silence level: " + mic.silenceLevel + '\n';
micDetails += "Silence timeout: " + mic.silenceTimeout + '\n';
micDetails += "Echo suppression: " + mic.useEchoSuppression + '\n';
trace(micDetails);
function onMicActivity(event:ActivityEvent):void
{
trace("activating=" + event.activating + ", activityLevel=" +
mic.activityLevel);
}
function onMicStatus(event:StatusEvent):void
{
trace("status: level=" + event.level + ", code=" + event.code);
}

*source : Actionscript 3.0 Reference

 

 

아래 예제는 Flex에서 마이크 활동을 감지하는 기본 예제입니다. 이를 활용해 Mic 이퀄라이저를 만들 수 있습니다.

 

 

 

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                     xmlns:s="library://ns.adobe.com/flex/spark"

                     xmlns:mx="library://ns.adobe.com/flex/mx"

                     creationComplete="init();"

                     >

     

      <fx:Script>

            <![CDATA[

                  import flash.events.ActivityEvent;

                  import flash.events.StatusEvent;

                  import flash.media.Microphone;

                 

                  private var mic:Microphone;

                  private var sv:Number = 100;

                  private var sh:Number = 100;

                 

                  private function init():void

                  {

                        mic = Microphone.getMicrophone();

//                      Security.showSettings(SecurityPanel.MICROPHONE);

                        mic.setLoopBack(true);

                        mic.setUseEchoSuppression(false);

 

                        addEventListener(Event.ENTER_FRAME, stage_EnterFrame);

                  }

                 

                  private function stage_EnterFrame(e:Event):void

                  {

                        var num:Number = mic.activityLevel*4;

                        trace(num);

                        eq.graphics.clear();

                        eq.graphics.beginFill(0xffffff * Math.random());

                        eq.graphics.drawCircle(sv, sh, num);

                  }

            ]]>

      </fx:Script>

      <mx:UIComponent id="eq" />

</s:Application>

*source : http://www.youtube.com/watch?v=IYmdkvLVRgc

*source code :MicExample.fxp

 

핵심은 Microphone 클래스의 activityLevel속성과 ENTER_FRAME 이벤트입니다. 전체적인 흐름은 간단합니다. activityLevel 속성으로 마이크 활동량을 감지해 ENTER_FRAME이벤트로 반복적으로 activityLevel을 시각화 합니다. activityLevel의 값은 0~100으로 소리를 숫자로 표현합니다.

 

- ActionScript에서 Sound작업

* [ActionScript] 액션스크립트 사운드 프로그래밍

* [ActionScript] 옥고수님의 블로그(액션스크립트 3.0을 이용한 사운드 시각화)

* [ActionScript, Flash] Classic ‘Sound Equalizer’ in Flash/AS3

* [ActionScript] ActionScript Reference(Detecting microphone activity)

* [ActionScript] 사운드 아키텍처의 이해(Adobe Reference)

* [ActionScript, Flash] Simple ActionScript 3 Flash Microphone Visualizer

* [ActionScript] 동강님의 블로그 - Microphone class(마이크를 이용한 작업)

 

AND