Flash SampleDataEvent.data.writeFloat()-为什么要调用它两次?

Flash SampleDataEvent.data.writeFloat()-为什么要调用它两次?,flash,actionscript-3,bytearray,audio,Flash,Actionscript 3,Bytearray,Audio,下面是Adobe Live DocsSampleDataEvent类的一个片段。它演示了如何通过将样本推入ByteArray来创建可听见的正弦波。我挂断的部分是为什么需要将相同的值推入writeFloat()方法两次 var mySound:Sound = new Sound(); function sineWaveGenerator(event:SampleDataEvent):void { for ( var c:int=0; c<8192; c++ ) {

下面是Adobe Live Docs
SampleDataEvent
类的一个片段。它演示了如何通过将样本推入
ByteArray
来创建可听见的正弦波。我挂断的部分是为什么需要将相同的值推入
writeFloat()
方法两次

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();
var mySound:Sound=new Sound();
函数sineWaveGenerator(事件:SampleDataEvent):无效
{

对于(var c:int=0;c它需要两次写入,因为它是立体声的。每个通道需要一个采样。在这种情况下,写入的值是相同的,但是如果您想将声音100%平移到一侧,例如,您可以使用第一个(或第二个)写入值writeFloat,并将0传递给另一个调用。

谢谢您的回复。那么,如果我将缓冲区大小增加一倍,只调用writeFloat()为什么会这样呢有一次,我遇到过同样的问题吗?我想这是因为在这种情况下,您没有两次写入相同的值,因为传递给writeFloat的值会根据循环计数器的不同而变化。您将正弦波的两个“快照”写入同一时间点(一个在右通道,另一个在左通道)还值得注意的是,SampleData API只允许2048到8192个样本继续播放().允许小于2048,但播放该集后将停止播放。超过8192的任何内容都可能导致未定义的行为。哎呀,我已更正。在将样本数增加到16384之前,您删除了对writeFloat的一个调用。我之前的评论应该是“介于2048和8192个样本对之间”.所以你没有超过允许的长度。