E-mail Comment Del.icio.us Digg Reddit Technorati Furl

利用SampleDataEvent模拟出的8位机音乐源码示例

最近在国外的一个网站上看到一个示例,只有2K大小的一个swf文件播放出了长达十分钟左右的游戏音乐。很是惊讶。于是仔细研究了下源码,发现是用的fp10中的新功能。在fp10新的API中有个SampleDataEvent的类,结合Sound对象可以播放出动态的音乐。
比如下面这段代码就可以播放出简单的正弦波。在FLEX SDK3.2以上版本,或者Flash CS4中可以测试。

var mySound:Sound = new Sound();
function sineWaveGenerator(event:SampleDataEvent):void {
    for ( var c:int=0; c<8192; c++ ) {
        event.data.writeFloat(Math.sin((Number(c+event.position)/Math.PI/2))*0.25);
        event.data.writeFloat(Math.sin((Number(c+event.position)/Math.PI/2))*0.25);
    }
}
 
mySound.addEventListener(SampleDataEvent.SAMPLE_DATA,sineWaveGenerator);
mySound.play();

Adobe官方中文手册中关于这个类的介绍:

http://livedocs.adobe.com/flex/3_cn/langref/flash/events/SampleDataEvent.html

下面的是这个牛B的8位机音乐源码:8位机音乐源码下载

One Response to “利用SampleDataEvent模拟出的8位机音乐源码示例”

  1. VINCE Says:

    谢谢


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">