audio - 如何在 AS3 中将声音对象提取到单字节数组

标签 audio actionscript bytearray microphone

我正在尝试将声音对象的字节数组添加到捕获的麦克风声音字节数组中。

它可以工作,但提取的声音对象会被缩小并加倍长度。我猜这是因为声音对象的字节数组是立体声的,而麦克风字节数组是单声道的。

我有这个:

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;
}

最佳答案

只需选择要提取的 channel 。我认为 ByteArray 是交错的,所以如果你选择所有奇数字节它的左 channel ,如果你选择所有偶数字节它是右 channel 。

var mono : ByteArray = new ByteArray();
for( var i : int = 0; i < raw.length; i+=2 ) {
    var left : int = raw[i];
    var right : int = raw[i+1];

    var mixed : int = left * 0.5 + right * 0.5;
    if( pickLeft ) {
      mono.writeByte( left );
    } else if( pickRight ) {
      mono.writeByte( right );
    } else {
      mono.writeByte( mixed );
    }
}

关于audio - 如何在 AS3 中将声音对象提取到单字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8912631/

相关文章:

class - ActionScript 包中有多个类?

c++ - 如何通过串行发送 float

ios将音视频url保存到文档目录

audio - 添加KeyEvent时无声音

java - 读取当前音频输出 - Android

html - Google Swiffy,响应式设计,高度

c# - 在事件中使用 'this'

php - 如何将 red5recorder 与 red5 服务器或 wowza 流服务器一起使用?

c++ - 如何使用高字节和低字节?

spring - Spring 的 @RequestBody byte[](长度大于预期)有什么问题?