정상파 발생 플래시입니다. 소리를 들어보세요.

(화면에 표시되는 내용은 스피커에 전달될 샘플링 데이터를 나타낸 것으로 정상파와는 맞지 않습니다.)







소스코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.text.TextFieldAutoSize;
import flash.media.Sound;
import flash.events.SampleDataEvent;
 
var mySound:Sound = new Sound();
 
var t:Number = 0;
var amplitude:Number = 0.25;
var graph_amplitude:Number = 50/amplitude;
var bmpDat:BitmapData = new BitmapData(400,200,false,0x0);
var bmp:Bitmap = new Bitmap(bmpDat);
bmp.y=50;
addChild(bmp);
 
 
var tfield:TextField = new TextField();
tfield.text = "화면을 누르면 시작.";
tfield.x = 120;
tfield.y = 100;
tfield.autoSize = TextFieldAutoSize.LEFT;
tfield.selectable = false;
var tformat:TextFormat = tfield.getTextFormat();
tformat.color = 0x33cc33;
tformat.align = TextFormatAlign.CENTER;
tfield.setTextFormat(tformat);
addChild(tfield);
stage.addEventListener(MouseEvent.CLICK, mouse_h);
 
 
function sineWaveGenerator(event:SampleDataEvent):void {
    t+=2;
    bmpDat.fillRect(new Rectangle(0,0,400,200),0x0);
    var wave:Number;
    for ( var c:int=0; c<2048; c++ ) {
        wave = getWave(c+event.position,t);
        event.data.writeFloat(wave);
        event.data.writeFloat(wave);
        if(c<800){
            bmpDat.setPixel(c,wave*graph_amplitude+100,0x00ff00);
        }
    }
    bmp.bitmapData = bmpDat;
 
}
 
 
function getWave(p:Number,t:Number):Number
{
    return (Math.sin(0.420*(Number(p+t)/Math.PI/2))+Math.sin(0.420*(Number(p)/Math.PI/2)))*amplitude;
}
 
function mouse_h(evt:MouseEvent):void
{
    mySound.addEventListener(SampleDataEvent.SAMPLE_DATA,sineWaveGenerator);
    mySound.play();
    removeChild(tfield);
}







+ Recent posts