gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 02:19:57 25 4
gpt4 key购买 nike

我需要做一些混音工作。我在 Adob​​e 帮助中找到了示例:

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 个字节和两个 channel 。移动,如下图所示。

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

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

1 2 3 4

L,R 32 float 。 -1 和 1 之间的连续数据。如 Sin 函数。

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

如果您想调整播放速率,请阅读这篇文章: http://www.kelvinluck.com/2008/11/first-steps-with-flash-10-audio-programming/

关于actionscript-3 - 我需要有关 sound.extract() 的更多信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14785842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com