两路short型混音 参考链接:https://blog.csdn.net/jeffasd/article/details/77335874
public static float[] mix_float(float[][] src_buffer, float[] buffer_mix) {
//src_buffer 里面有两路流
//归一化混音
float MAX = 3.4028235E38f;
float MIN = 1.4E-45f;
double f = 1; //衰减因子
float output;//归一化后输出
for (int i = 0; i < src_buffer[0].length; i++) {
float temp = 0;
for (int j = 0; j < 2; j++) {
temp += src_buffer[j][i];
}
output = (float) (temp * f);
if (output > MAX) {
f = (double) MAX / (double) (output);
output = MAX;
}
if (output < MIN) {
f = (double) MIN / (double) (output);
output = MIN;
}
if (f < 1) {
f += ((double) 1 - f) / (double) 16;
}
System.out.println(f);
buffer_mix[i] = output;
}
return buffer_mix;
}
上面方法对float型经过测试,不好使。
两路float型混音 参考链接:https://blog.csdn.net/TopsLuo/article/details/72769800
public static float[] mix_float2(float[][] src_buffer, float[] buffer_mix) {
for (int i = 0; i < src_buffer[0].length; i++) {
// A B代表两路流的对应值
float A = src_buffer[0][i];
float B = src_buffer[1][i];
// C 代表混合后的结果
float C;
if (A < 0 && B < 0) {
C = (float) (A + B - (A * B / -(Math.pow(2, 32 - 1) - 1)));
} else {
C = (float) (A + B - (A * B / (Math.pow(2, 32 - 1))));
}
C = C > 1 ? 1 : C;
C = C < -1 ? -1 : C;
buffer_mix[i] = C;
}
return buffer_mix;
}