Actionscript 3 我需要有关sound.extract()的更多信息

Actionscript 3 我需要有关sound.extract()的更多信息,actionscript-3,audio,Actionscript 3,Audio,我需要做一些混音工作。我在Adobe帮助中找到了以下示例: var sourceSnd:Sound = new Sound(); var outputSnd:Sound = new Sound(); var urlReq:URLRequest = new URLRequest("test.mp3"); sourceSnd.load(urlReq); sourceSnd.addEventListener(Event.COMPLETE, loaded); function loaded(even

我需要做一些混音工作。我在Adobe帮助中找到了以下示例:

var sourceSnd:Sound = new Sound();
var outputSnd:Sound = new Sound();
var urlReq:URLRequest = new URLRequest("test.mp3");

sourceSnd.load(urlReq);
sourceSnd.addEventListener(Event.COMPLETE, loaded);

function loaded(event:Event):void
{
    outputSnd.addEventListener(SampleDataEvent.SAMPLE_DATA, processSound);
    outputSnd.play();
}

function processSound(event:SampleDataEvent):void
{
    var bytes:ByteArray = new ByteArray();
    sourceSnd.extract(bytes, 4096);
    event.data.writeBytes(upOctave(bytes));
}

function upOctave(bytes:ByteArray):ByteArray
{
    var returnBytes:ByteArray = new ByteArray();
    bytes.position = 0;
    while(bytes.bytesAvailable > 0)
    {
        returnBytes.writeFloat(bytes.readFloat());
        returnBytes.writeFloat(bytes.readFloat());
        if (bytes.bytesAvailable > 0)
        {
            bytes.position += 8;
        }
    }
    return returnBytes;
}
它说:

target:ByteArray — A ByteArray object in which the extracted sound samples are placed.

length:Number — The number of sound samples to extract. A sample contains both the left and right channels — that is, two 32-bit floating-point values.
我建议

    returnBytes.writeFloat(bytes.readFloat());
    returnBytes.writeFloat(bytes.readFloat());
必须写入leftchannel值和rightchannel值

bytes.position += 8
减少采样,使声音播放得更快。我已尝试将该值修改为4。速度减慢到2,我只听到噪音,为什么?其他值,如16或更高,没有声音输出。为什么?如何只用一个浮点数就可以产生各种音效

我需要更多的信息来了解我的工作,请帮助

更新:我稍微更改了upOctave()函数,现在可以调整速度了

        function upOctave(bytes:ByteArray):ByteArray
        {
            var returnBytes:ByteArray = new ByteArray();
            bytes.position = 0;
            var position:int = 0;
            var speed:Number = 0.75;
            while(bytes.bytesAvailable > 0)
            {
                if (bytes.bytesAvailable > 0)
                {
                    bytes.position = int(speed*position)*8;
                }
                position++;
                if(bytes.bytesAvailable>0){
                    returnBytes.writeFloat(bytes.readFloat());
                    returnBytes.writeFloat(bytes.readFloat());
                }
            }
            return returnBytes;
        }

简而言之,
bytes.position+=8不表示播放速率

每个浮点4字节,两个通道。移动,如下图所示

8台byteArray为1台。换句话说,抽样

 4byte  4byte
[  L  ][  R  ] [  L  ][  R  ] [  L  ][  R  ] [  L  ][  R  ] ...

       1              2              3              4
五十、 R 32浮动。介于-1和1之间的连续数据。类似于Sin函数

创建一个波形,你可以控制声音。直波,锯齿波,三角波,正弦波,噪声波。。。最终,声音取决于波形


如果您想调整播放速率,请阅读本文:

谢谢,因为我了解了结构,现在我可以更改速度,请参阅上面的代码^^。您能告诉我有关波形的更多信息吗?