Open
Description
目前使用MP3格式编码,帧回调切割配合websocket收发。
两个设备对讲可以编解码,三个设备时需要把两个设备的mp3流混音后发送。
但是目前直接取平均值的办法不可解码
报错
混音算法:
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;
}
Metadata
Assignees
Labels
No labels
Activity