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

flash on 2011-9-22

Get Adobe Flash player
by AndreMichelle 22 Sep 2011

    Talk

    katopz at 22 Sep 2011 20:59
    OMG Flash Player XII !?!?!?
    Thy at 23 Sep 2011 04:38
    ur ms / my ms = .33, .64, .83, .92; w7 10.3.183.1 cool
    Hasufel at 23 Sep 2011 23:05
    Flash player 12 :) Come on Andre!
    makc3d at 24 Sep 2011 03:40
    prerelease²
    Embed
/**
 * Copyright AndreMichelle ( http://wonderfl.net/user/AndreMichelle )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hbNd
 */

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.SampleDataEvent;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.system.Capabilities;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.ByteArray;

	/**
	 * Quick LatencyCheck
	 * 
	 * @author Andre Michelle
	 */
	public class DemoLatency extends Sprite
	{
		private static const TESTS: Vector.<int> = Vector.<int>( [ 2048, 3072, 4096, 8192 ] );
		
		private const buffer: ByteArray = new ByteArray();
		
		private const sounds: Vector.<Sound> = new Vector.<Sound>();
		private const channels: Vector.<SoundChannel> = new Vector.<SoundChannel>();
		
		private const textField: TextField = new TextField();
		private const outputs: Vector.<String> = new Vector.<String>();
		
		private var _buildIndex: int = 0;
		
		public function DemoLatency()
		{
			textField.autoSize = TextFieldAutoSize.LEFT;
			textField.defaultTextFormat = new TextFormat( 'Verdana', 10, 0x0, false );
			textField.text = '';
			addChild( textField );
			
			buffer.length = TESTS[ int( TESTS.length - 1 ) ] << 3; // MAX SAMPLES * sizeof float (times two: stereo)
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.addEventListener( Event.ENTER_FRAME, enterFrame );
		}

		private function enterFrame( event: Event ): void
		{
			if( _buildIndex < TESTS.length )
			{
				sounds[_buildIndex] = new Sound();
				sounds[_buildIndex].addEventListener( SampleDataEvent.SAMPLE_DATA, sampleData );
				channels[_buildIndex] = sounds[_buildIndex].play();
				
				++_buildIndex;
			}
			
			textField.text = '';
			textField.appendText( 'System\t' + Capabilities.os + '\n' );
			textField.appendText( 'Player\t' + Capabilities.version + ' ' + Capabilities.playerType + '\n' );
			textField.appendText( '--------------------------------------------------------------------\n' );
			
			var i: int = 0;
			var n: int = outputs.length;
			
			for( ; i < n ; ++i )
			{
				textField.appendText( outputs[i] + '\n' );
			}
		}

		private function sampleData( event: SampleDataEvent ): void
		{
			var index: int = sounds.indexOf( event.target );
			
			if( -1 == index )
				throw new Error();

			buffer.position = 0;
			
			event.data.writeBytes( buffer, 0, TESTS[index] << 3 );
				
			if( channels.length > index && channels[index] != null )
			{
				// Compute difference from writing and audible audio data
				const latency: Number = event.position / 44.1 - channels[index].position;

				outputs[index] = 'Providing ' + TESTS[index] + ' samples results in ' + latency.toFixed(3) + 'ms latency';
			}
		}
	}
}