如何提取声音对象在AS3单字节数组数组、字节、对象、声音

2023-09-08 11:54:58 作者:陪伴是最好的表白

我想prePEND一个声音对象的字节数组捕获的麦克风声音字节数组。

它的工作原理,但提取的声音对象得到pichted下来,长了一倍。我想这是因为声音对象的字节数组是立体声,而MIC字节数组是单声道。

我有这样的:

  sound.extract(myByteArray,提取);
 

myByteArray现在包含立体声数据。我怎么能拒绝这单声道(我是新来的ByteArray)。

更新:

下面是一个工作的解决方案:

  existingByte.position = 0;
VAR单:ByteArray的=新的ByteArray();
而(existingByte.bytesAvailable){
    VAR左:数= existingByte.readFloat();
    mono.writeFloat(左);
    existingByte.position + = 4;
}
 
如何把一个byte数组转化为字符串

解决方案

只需选择一个渠道来提取。我想是这样,如果你选择所有奇数字节的左声道,如果你选择的所有字节,甚至是右声道的ByteArray是交错的。

  VAR单:ByteArray的=新的ByteArray();
对于(VAR我:= 0; I< raw.length;我+ = 2){
    VAR左:INT =原[I]
    无功权:INT =原[I + 1];

    VAR混合:INT =左* 0.5 +右* 0.5;
    如果(pickLeft){
      mono.writeByte(左);
    }否则,如果(pickRight){
      mono.writeByte(右);
    } 其他 {
      mono.writeByte(混合);
    }
}
 

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

解决方案

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.

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