我正在尝试加载一个 .mp3 文件,并区分左右声道。我想从左声道复制数据并创建一个 AudioStream,通过左右声道播放来自左声道的数据。
我一直在尝试使用这段代码来实现它,但它似乎产生了一个难以辨认的字节数组
InputStream inputStream = getApplicationContext().getResources().openRawResource(R.raw.flume);
soundBytes1 = new byte[inputStream.available()];
soundBytes1 = toByteArray(inputStream);
public byte[] toByteArray(InputStream in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
int read = 0;
byte[] buffer = new byte[1024];
while (read != -1) {
read = in.read(buffer);
if (read != -1)
out.write(buffer,0,read);
}
out.close();
return out.toByteArray();
}
我希望能够使用任何 .mp3 文件执行此过程。是否需要将音频转换为其他格式才能区分 channel ?
最佳答案
Is it necessary for the audio to be converted to some other format in order for the channels to be distinguished?
是的。 MP3 与大多数有损格式一样,将音频 channel 组合在一起(在大多数情况下)并有效地存储它们之间的差异。这可以节省大量带宽,因为左右轨道通常非常相似。节省此带宽可提高给定比特率的整体质量。
因此,您不能只为一个 channel 读取一帧,然后为下一个 channel 读取一帧。您必须先将 MP3 音频解码回 PCM。
关于Android - 从立体声 .mp3 中提取一个 channel ,通过 AudioStream 的两个 channel 应用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50082946/