改善Android的App运行时间

时间:2014-09-17 19:37:29

标签: java android runtime signal-processing

我为andriod App写了一个语音增强代码。算法在256个大小的语音样本帧上运行。在我的电脑上,代码每帧运行大约5ms,而在我的Nexsus5上它更像50ms,在30秒长的录音运行中进行语音增强超过两分钟,在我的PC上增强整个音频文件需要不到一分钟。我希望尽可能地改善运行时间。 我附加了每帧运行的代码,这是我看到运行时间增加最多的地方。

for(int j = 0; j < Consts.NUM_OF_CLUSTERS; j++)
    {
        tmp_log_h=0;
        for(int k = 0; k < Consts.SIZE_OF_SEMPELS_IN_CHUNCK; k++)
        {

            f_X = (1/FastMath.sqrt(2*FastMath.PI*sigmaSqr.get(j).get(k)))*FastMath.exp(-(FastMath.pow(NoisySignal[k] - mue.get(j).get(k),2))/(2*sigmaSqr.get(j).get(k)));// equation (3)
            F_X=(0.500 + 0.5*Erf.erf((NoisySignal[k] - mue.get(j).get(k))/(FastMath.sqrt(2*sigmaSqr.get(j).get(k)))));// equation (6)

            if(j==0)
            {
                g_pdf_Y[k]=1/FastMath.sqrt(2*FastMath.PI*Noise_sigmaSqr.get(k))*FastMath.exp(-(FastMath.pow(NoisySignal[k] - Noise_mu.get(k),2))/(2*Noise_sigmaSqr.get(k)));// equation (4)
                G_cdf_Y[k]=(0.500 + 0.5*Erf.erf((NoisySignal[k] - Noise_mu.get(k))/(FastMath.sqrt(2*Noise_sigmaSqr.get(k)))));// equation (5)
            }

            tmp_R_samples = (f_X/F_X);// equation (12.5)

            if(j==0)
            {
                R_noise[k]=g_pdf_Y[k]/G_cdf_Y[k]; // equation (12.5)
            }

            Roe[j][k] = 1/(1 + (R_noise[k]/tmp_R_samples));
            X_hat[j][k] = NoisySignal[k]*Roe[j][k]+ (mue.get(j).get(k))*(1 - Roe[j][k]) - (sigmaSqr.get(j).get(k))*((f_X*R_noise[k])/(f_X + F_X*R_noise[k]));
            tmp_h_first=(f_X*G_cdf_Y[k] + F_X*g_pdf_Y[k]);// equation (7.5)             
            tmp_log_h += FastMath.log(tmp_h_first); // equation (7.5)
        }


        Log_h_second[j]=tmp_log_h;
        Log_h_final_vecotr[j]=FastMath.log(c.get(j)) + Log_h_second[j];
    }


    Double maxVi = MathHelpers.findMax(Log_h_final_vecotr);

    double sumExp = 0.0;

    for(int j = 0; j < Consts.NUM_OF_CLUSTERS; j++)
    {
        sumExp +=(FastMath.exp(Log_h_final_vecotr[j] - maxVi));// equation (18)
        System.out.println(sumExp);
    }

    Log_h_final = maxVi + FastMath.log(sumExp);


    for(int j = 0; j < Consts.NUM_OF_CLUSTERS; j++)
    {
        Log_q[j]=FastMath.log(c.get(j)) + Log_h_second[j] - Log_h_final;
        q[j]=(FastMath.exp(Log_q[j]));// equation (10)
    }


    for(int k = 0; k < Consts.SIZE_OF_SEMPELS_IN_CHUNCK; k++)
    {
        Double temp_X_estimate = 0.0;

        for(int j = 0; j < Consts.NUM_OF_CLUSTERS; j++)
        {
            temp_X_estimate += (X_hat[j][k]*q[j]);
        }   

        X_estimate[k]=temp_X_estimate;// equation (9)
    }

0 个答案:

没有答案