JAVA混音

2022/1/19 17:21:38

本文主要是介绍JAVA混音,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

两路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;

    }


这篇关于JAVA混音的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程