如何在 AS3 中将声音对象提取到单字节数组
我试图将声音对象的字节数组添加到捕获的麦克风声音字节数组中。
它可以工作,但是提取的声音对象会被缩小并长度加倍。我猜这是因为声音对象的字节数组是立体声的,而麦克风字节数组是单声道的。
我有这个:
sound.extract(myByteArray, extract);
myByteArray 现在包含立体声数据。我怎样才能把它变成单声道(我是 ByteArrays 的新手)。
更新:
这是一个可行的解决方案:
existingByte.position = 0;
var mono : ByteArray = new ByteArray();
while(existingByte.bytesAvailable) {
var left : Number = existingByte.readFloat();
mono.writeFloat(left);
existingByte.position +=4;
}
I'm trying to prepend the byte array of a sound object to a captured microphone sound byte array.
It works, but the extracted sound object get pichted down and doubled in length. I guess this is because the byte array of the sound object is in stereo, while the mic byte array is in mono.
I have this:
sound.extract(myByteArray, extract);
myByteArray now contains the stereo data. How can I turn this to mono (I'm new to ByteArrays).
UPDATE:
Here's a working solution:
existingByte.position = 0;
var mono : ByteArray = new ByteArray();
while(existingByte.bytesAvailable) {
var left : Number = existingByte.readFloat();
mono.writeFloat(left);
existingByte.position +=4;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需选择一个通道即可提取。我认为 ByteArray 是交错的,因此如果您选择所有奇数字节,则它是左通道,如果您选择所有偶数字节,则它是右通道。
Just pick a channel to extract. I think ByteArray is interleaved so if you pick all odd bytes its the left channel, if you pick all even bytes it's the right channel.