【问题标题】:How to extract sound object to a mono byte array in AS3如何在 AS3 中将声音对象提取到单字节数组
【发布时间】:2012-01-18 15:21:25
【问题描述】:

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

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

我有这个:

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

【问题讨论】:

    标签: audio actionscript bytearray microphone


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢。不幸的是,如果我使用您的代码,我正在使用的波形编写器类(由 Adob​​e 提供)会引发以下错误:错误:音频样本在 classes::WAVWriter/processSamples() 中不是浮点格式
    • 是的,我的“代码”不正确。读取字节意味着一切都是 8 位的。浮点数是 16 位,所以是的,您需要读取交替的浮点数(如果流是 16 位,则不是字节),但是选择左声道、右声道或混合它们的想法仍然有效。
    猜你喜欢
    • 2013-02-02
    • 2011-10-19
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 2011-08-17
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多