String to Sound
/**
* Copyright yukiorz ( http://wonderfl.net/user/yukiorz )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kLEM
*/
package {
import flash.display.Stage;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldType;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.Graphics;
import flash.media.Sound;
import flash.events.Event;
import flash.events.SampleDataEvent;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var textSprit:Sprite;
var inputTextField:TextField;
var newFormat:TextFormat = new TextFormat();
inputTextField=new TextField();
newFormat.size=180;
//TextField inisialize
inputTextField.text="yamasan";
inputTextField.selectable=true;
inputTextField.type = TextFieldType.INPUT;
inputTextField.x=10;
inputTextField.y=50;
inputTextField.width=400;
inputTextField.height=300;
inputTextField.setTextFormat(newFormat);
this.addChild(inputTextField);
var bmd :BitmapData;
var bmp :Bitmap;
/*
bmd = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0xFFFFFF );
bmp = new Bitmap( bmd );
bmp.y=250;
bmd.draw( this );
*/
var shape:Shape = new Shape();
stage.addChild(shape);
var g:Graphics = shape.graphics;
var searchX:int=0;
var searchY:int=0;
g.clear();
bmd = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0xFFFFFF );
bmp = new Bitmap( bmd );
bmp.y=250;
bmd.draw( this );
var beforeText:String=inputTextField.text;
var mySound:Sound = new Sound();
mySound.addEventListener(SampleDataEvent.SAMPLE_DATA, sineWaveGenerator);
mySound.play();
function sineWaveGenerator(event:SampleDataEvent):void
{
for (var i:int = 0; i < 8192; i++)
{
var n:Number = Math.sin((i + event.position) / Math.PI / (((searchY)/250+0.5)*4)+0.5);//a
//2~8 (searchY/250+2)*4
event.data.writeFloat(n);
event.data.writeFloat(n);
}
}
this.addEventListener(Event.ENTER_FRAME, function(event:Event):void {
if(beforeText!=inputTextField.text)
{
g.clear();
bmd = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0xFFFFFF );
bmp = new Bitmap( bmd );
bmp.y=250;
bmd.draw( this );
beforeText=inputTextField.text;
return void;
}
searchX=(searchX+1)%400;
for(searchY=0;searchY<250;searchY++)
if(bmd.getPixel(searchX,searchY)<0x888888)
break;
if(searchY!=250)
{
g.clear();
g.beginFill (0xFF0000, 1.0); // 面のスタイル設定
g.drawCircle ( searchX, searchY , 5);
}
else
g.clear();
inputTextField.setTextFormat(newFormat);
});
}
}
}