Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么实现MP3混流 #259

Open
suiyuanccccc opened this issue Jan 12, 2025 · 1 comment
Open

怎么实现MP3混流 #259

suiyuanccccc opened this issue Jan 12, 2025 · 1 comment

Comments

@suiyuanccccc
Copy link

suiyuanccccc commented Jan 12, 2025

目前使用MP3格式编码,帧回调切割配合websocket收发。
两个设备对讲可以编解码,三个设备时需要把两个设备的mp3流混音后发送。
但是目前直接取平均值的办法不可解码
报错
image

混音算法:

public static List<Short> calculateColumnAverages(List<List<Short>> inputs) {
    int numRows = inputs.size();
    int numCols = 0;
    for (List<Short> row : inputs) {
        if (row != null && row.size() > numCols) {
            numCols = row.size();
        }
    }
    if (numCols == 0) return null;


    // 用于存储每列的和
    long[] columnSums = new long[numCols]; // 使用 long 以避免溢出

    // 累加每列的和
    for (List<Short> row : inputs) {
        if (row != null) {
            for (int col = 0; col < numCols; col++) {
                columnSums[col] += row.get(col);
            }
        }
    }

    // 计算平均值并转换为 Short
    List<Short> averages = new ArrayList<>(numCols);
    for (int col = 0; col < numCols; col++) {
        // 截断小数部分
        averages.add((short) (columnSums[col] / (numRows+0.1)));
    }

    return averages;
}
@suiyuanccccc suiyuanccccc changed the title 怎么实现MP3 怎么实现MP3混流 Jan 12, 2025
@xiangyuecn
Copy link
Owner

简单点,直接不混流,给每个人单独创建一个播放器去播放

要混流,就很麻烦,服务器里面要解码mp3成pcm,再去混到一起,再转成mp3发送出去,这种方式不适合mp3这个格式,amr格式反而好点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants