问题
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;
}
回答1:
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 );
}
}
来源:https://stackoverflow.com/questions/8912631/how-to-extract-sound-object-to-a-mono-byte-array-in-as3