Android - 从立体声 .mp3 中提取一个 channel ,通过 AudioStream 的两个 channel 应用它

标签 android audio mp3 audio-streaming android-music-player

我正在尝试加载一个 .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/

相关文章:

php - Jw 播放器未播放 mime 类型为 "audio/x-mpeg"的 mp3

java - 播放MP3的java

android - 自定义 android 首选项类型在键入时失去焦点

android - IOS 中的动画延迟无法正常工作

java - 如何将我的状态栏设置为透明但导航栏保持黑色?

android - 在 OpenCV android 应用程序中启用 "libc++_shared.so"

c# - Crossfading - 获取音频 C# .NET Compact Framework 的最佳方式?

iOS 在执行其他操作之前播放声音

android - 如何在android中索引媒体文件以进行快速搜索

javascript - 让 <iframe> 异步工作