Sound sample rate test
flash.media.Sound クラスが 44.1 KHz かどうか検証してみた。
1秒に一度0.1秒だけ音を鳴らし、その都度getTimeでTraceしてみる。
ゆらぎは多少あるものの、サンプリングレートは 44.1KHz であってそう。
ちなみに、44KHz として計算した場合はちょっとずつズレる。
♥0 |
Line 43 |
Modified 2011-06-19 04:16:19 |
MIT License
archived:2017-03-20 09:04:23
ActionScript3 source code
/**
* Copyright _katsuren ( http://wonderfl.net/user/_katsuren )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/nhj7
*/
package {
import flash.text.TextField;
import flash.events.SampleDataEvent;
import flash.display.Sprite;
import flash.media.Sound;
public class FlashTest extends Sprite {
private var sound:Sound;
private var tf:TextField;
private var count:int;
public function FlashTest() {
tf = new TextField();
tf.x = 0;
tf.y = 0;
tf.width = 150;
tf.height = 500;
this.addChild(tf);
count = 0;
sound = new Sound();
sound.addEventListener(SampleDataEvent.SAMPLE_DATA, sampleDataEvent);
sound.play();
}
private function sampleDataEvent(e:SampleDataEvent):void {
if (++count % 10 == 1) {
var time:Number = new Date().getTime();
appendText(int(count/10).toString() + "秒 : " + time.toString());
}
for (var i:int=0; i<4410; i++) {
if (count % 10 == 1) {
var data:Number = Math.sin(Number(i+e.position)/Math.PI/2)*0.25;
e.data.writeFloat(data);
e.data.writeFloat(data);
}
else {
e.data.writeFloat(0);
e.data.writeFloat(0);
}
}
}
private function appendText(str:String):void {
tf.appendText(str + "\n");
}
}
}