In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Pitch Detection

SiON FFT module で 声紋解析 (Hamming窓+時間分解能11ms)
Get Adobe Flash player
by jonathantneal 15 Oct 2011
    Embed
/**
 * Copyright jonathantneal ( http://wonderfl.net/user/jonathantneal )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/aU94
 */

package
{
    import com.buraks.tuner.*;
    import flash.display.*;
    import flash.events.*;
    import flash.media.*;
    import flash.text.*;
    import flash.utils.*;
    import main.*;

    public class main extends MovieClip
    {
        var samples:ByteArray;
        var keyboard:Keyboard;
        var gauge:Gauge;
        var graph:Graph;

        public function main()
        {
            var _loc_1:* = new TextFormat();
            _loc_1.font = "Tahoma";
            _loc_1.color = 16777215;
            _loc_1.size = 12;
            var _loc_2:* = new TextField();
            _loc_2.defaultTextFormat = _loc_1;
            _loc_2.autoSize = "left";
            _loc_2.selectable = false;
            _loc_2.htmlText = "Copyright © 2010 <a href=\'http://www.manitugroup.com\'>Manitu Group</a>";
            addChild(_loc_2);
            _loc_2.x = 20;
            _loc_2.y = 240;
            _loc_1 = new TextFormat();
            _loc_1.font = "Tahoma";
            _loc_1.color = 16777215;
            _loc_1.size = 16;
            _loc_2 = new TextField();
            _loc_2.defaultTextFormat = _loc_1;
            _loc_2.autoSize = "left";
            _loc_2.selectable = false;
            _loc_2.text = "Chromatic Guitar Tuner";
            addChild(_loc_2);
            _loc_2.x = 20;
            _loc_2.y = 200;
            _loc_1 = new TextFormat();
            _loc_1.font = "Tahoma";
            _loc_1.color = 16777215;
            _loc_1.size = 12;
            _loc_2 = new TextField();
            _loc_2.defaultTextFormat = _loc_1;
            _loc_2.autoSize = "left";
            _loc_2.selectable = false;
            _loc_2.text = "Version 1.0";
            addChild(_loc_2);
            _loc_2.x = 20;
            _loc_2.y = 222;
            _loc_1 = new TextFormat();
            _loc_1.font = "Tahoma";
            _loc_1.color = 16777215;
            _loc_1.size = 10;
            _loc_2 = new TextField();
            _loc_2.defaultTextFormat = _loc_1;
            _loc_2.autoSize = "left";
            _loc_2.selectable = false;
            _loc_2.htmlText = "<a href=\'http://www.buraks.com/tuner/\'>http://www.buraks.com/tuner</a>";
            addChild(_loc_2);
            _loc_2.x = 20;
            _loc_2.y = 260;
            this.keyboard = new Keyboard(6);
            addChild(this.keyboard);
            this.keyboard.addNote(16, "E");
            this.keyboard.addNote(21, "A");
            this.keyboard.addNote(26, "D");
            this.keyboard.addNote(31, "G");
            this.keyboard.addNote(35, "B");
            this.keyboard.addNote(40, "E");
            this.graph = new Graph(512, 100);
            addChild(this.graph);
            this.graph.y = 86;
            this.graph.width = this.keyboard.width;
            this.graph.alpha = 0.3;
            this.gauge = new Gauge();
            addChild(this.gauge);
            this.gauge.x = 400;
            this.gauge.y = 190;
            this.samples = new ByteArray();
            this.samples.endian = Endian.LITTLE_ENDIAN;
            var _loc_3:* = Microphone.getMicrophone();
            _loc_3.setSilenceLevel(0);
            _loc_3.gain = 50;
            _loc_3.rate = 11;
            _loc_3.addEventListener(SampleDataEvent.SAMPLE_DATA, this.micSampleDataHandler);
            _loc_1 = new TextFormat();
            _loc_1.font = "Tahoma";
            _loc_1.color = 6745702;
            _loc_1.size = 10;
            _loc_2 = new TextField();
            _loc_2.defaultTextFormat = _loc_1;
            _loc_2.autoSize = "left";
            _loc_2.selectable = false;
            _loc_2.htmlText = "Free version. <a href=\'http://www.buraks.com\'> Check out other fine software by Manitu Group!</a>";
            addChild(_loc_2);
            _loc_2.x = 20;
            _loc_2.y = 90;
            stop();
            return;
        }// end function

        private function micSampleDataHandler(event:SampleDataEvent) : void
        {
            var _loc_4:int = 0;
            var _loc_6:Number = NaN;
            var _loc_7:Number = NaN;
            var _loc_8:int = 0;
            var _loc_9:Number = NaN;
            var _loc_10:int = 0;
            var _loc_2:* = event.data;
            _loc_2.position = 0;
            var _loc_3:* = _loc_2.bytesAvailable >> 2;
            if (_loc_3 > 512)
            {
                _loc_3 = 512;
            }
            this.samples.position = 0;
            _loc_4 = 0;
            while (_loc_4 < _loc_3)
            {
                
                this.samples.writeFloat(_loc_2.readFloat());
                _loc_4++;
            }
            this.graph.drawData(this.samples, _loc_3);
            var _loc_5:* = xamdf.detectPitch(this.samples, _loc_3);
            if (_loc_5 == 0)
            {
                this.keyboard.putDot(-1);
                this.gauge.clearGauge();
            }
            else
            {
                _loc_6 = 11025 / _loc_5;
                _loc_7 = 45 + Math.log(_loc_6 / 440) * Math.LOG2E * 12;
                _loc_8 = Math.round(_loc_7);
                _loc_9 = _loc_7 - _loc_8;
                _loc_10 = Math.round(_loc_9 * 100) * 1;
                this.keyboard.putDot(_loc_8);
                this.gauge.drawGauge(_loc_8, _loc_10);
            }
            return;
        }// end function

    }
}