我正在使用Android sdk的AudioRecord类来录制原始音频,然后我用蹩脚的mp3编码器对其进行编码。为此,我必须像这样在立体声录音模式中分离左右声道。
bytesEncoded = Lame.encode(left, isMono ? left : right, samplesRead, mp3Buf, mp3Buf.length);
如何将左右声道从缓冲区分离到自己的缓冲区?
我尝试过使用它,但它会产生间隙声音。 link
以下方法正在运行,但它在后台添加了噪音:`
private int readStereo(short[] left, short[] right, int numSamples) throws IOException {
byte[] buf = new byte[numSamples * 4];
int index = 0;
if (audioRecorder == null)
return -1;
int bytesRead = audioRecorder.read(buf, 0, numSamples * 4);
for (int i = 0; i < bytesRead; i+=2) {
short val = byteToShortLE(buf[0], buf[i+1]);
if (i % 4 == 0) {
left[index] = val;
} else {
right[index] = val;
index++;
}
}
return index;
}`
private static short byteToShortLE(byte b1, byte b2) {
return (short) (b1 & 0xFF | ((b2 & 0xFF) << 8));
}