我正在尝试将声音对象的字节数组添加到捕获的麦克风声音字节数组中。
它可以工作,但提取的声音对象会被缩小并加倍长度。我猜这是因为声音对象的字节数组是立体声的,而麦克风字节数组是单声道的。
我有这个:
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/