cfdlp.c
// "standard" lpc using autocorrelation + levinson-durbin
"standard" lpc using autocorrelation + levinson-durbin
" standard " lpc using autocorrelation + levinson - durbin
void lpc( double *y, int len, int order, int compr, float *poles, int myband ) 
{
    int N = pow(2,ceil(log2(2*len-1)));
    if (N != lpc_r2c_plan_sizes[myband])
    {
	lpc_r2c_plan_sizes[myband] = N;
	if (lpc_r2c_plans[myband] != NULL)
	{
	    lock_mutex(&fftw_mutex);
	    fftw_destroy_plan(lpc_r2c_plans[myband]);
	    unlock_mutex(&fftw_mutex);
	    lpc_r2c_plans[myband] = NULL;
	}
	if (lpc_r2c_input_buffers[myband] != NULL)
	{
	    FREE(lpc_r2c_input_buffers[myband]);
	    lpc_r2c_input_buffers[myband] = NULL;
	}
	if (lpc_r2c_output_buffers[myband] != NULL)
	{
	    FREE(lpc_r2c_output_buffers[myband]);
	    lpc_r2c_output_buffers[myband] = NULL;
	}
	if (lpc_c2r_plans[myband] != NULL)
	{
	    FREE(lpc_c2r_plans[myband]);
	    lpc_c2r_plans[myband] = NULL;
	}
	if (lpc_c2r_output_buffers[myband] != NULL)
	{
	    FREE(lpc_c2r_output_buffers[myband]);
	    lpc_c2r_output_buffers[myband] = NULL;
	}
    }
    if (lpc_r2c_input_buffers[myband] == NULL)
    {
	lpc_r2c_input_buffers[myband] = (double*) MALLOC(lpc_r2c_plan_sizes[myband] * sizeof(double));
    }
    if (lpc_r2c_output_buffers[myband] == NULL)
    {
	lpc_r2c_output_buffers[myband] = (complex*) MALLOC(lpc_r2c_plan_sizes[myband] * sizeof(complex));
	memset(lpc_r2c_output_buffers[myband], 0, N * sizeof(complex)); 
    }
    if (lpc_r2c_plans[myband] == NULL)
    {
	lock_mutex(&fftw_mutex);
	lpc_r2c_plans[myband] = fftw_plan_dft_r2c_1d(
		lpc_r2c_plan_sizes[myband],
		lpc_r2c_input_buffers[myband],
		lpc_r2c_output_buffers[myband],
		FFTW_ESTIMATE);
	unlock_mutex(&fftw_mutex);
    }
    if (lpc_c2r_output_buffers[myband] == NULL)
    {
	lpc_c2r_output_buffers[myband] = (double*) MALLOC(lpc_r2c_plan_sizes[myband] * sizeof(double));
    }
    if (lpc_c2r_plans[myband] == NULL)
    {
	lock_mutex(&fftw_mutex);
	lpc_c2r_plans[myband] = fftw_plan_dft_c2r_1d(
		lpc_r2c_plan_sizes[myband],
		lpc_r2c_output_buffers[myband],
		lpc_c2r_output_buffers[myband],
		FFTW_ESTIMATE);
	unlock_mutex(&fftw_mutex);
    }
    for ( int n = 0; n < N; n++ )
    {
	if ( n < len )
	{
	    lpc_r2c_input_buffers[myband][n] = y[n];
	}
	else
	{
	    lpc_r2c_input_buffers[myband][n] = 0;
	}
    }   
    fftw_execute(lpc_r2c_plans[myband]);
    for ( int n = 0; n < N; n++ )
    {
	lpc_r2c_output_buffers[myband][n] = lpc_r2c_output_buffers[myband][n]
	    *conj(lpc_r2c_output_buffers[myband][n])
	    /len; 
    }
    fftw_execute(lpc_c2r_plans[myband]);
    for ( int n = 0; n < N; n++ )
    {
	lpc_c2r_output_buffers[myband][n] /= N;
    }
    levinson(order, lpc_c2r_output_buffers[myband], poles);
}
void lpc ( double * y , int len , int order , int compr , float * poles , int myband ) { int N = pow ( 2 , ceil ( log2 ( 2 * len - 1 ) ) ) ; if ( N != lpc_r2c_plan_sizes [ myband ] ) { lpc_r2c_plan_sizes [ myband ] = N ; if ( lpc_r2c_plans [ myband ] != NULL ) { lock_mutex ( & fftw_mutex ) ; fftw_destroy_plan ( lpc_r2c_plans [ myband ] ) ; unlock_mutex ( & fftw_mutex ) ; lpc_r2c_plans [ myband ] = NULL ; } if ( lpc_r2c_input_buffers [ myband ] != NULL ) { FREE ( lpc_r2c_input_buffers [ myband ] ) ; lpc_r2c_input_buffers [ myband ] = NULL ; } if ( lpc_r2c_output_buffers [ myband ] != NULL ) { FREE ( lpc_r2c_output_buffers [ myband ] ) ; lpc_r2c_output_buffers [ myband ] = NULL ; } if ( lpc_c2r_plans [ myband ] != NULL ) { FREE ( lpc_c2r_plans [ myband ] ) ; lpc_c2r_plans [ myband ] = NULL ; } if ( lpc_c2r_output_buffers [ myband ] != NULL ) { FREE ( lpc_c2r_output_buffers [ myband ] ) ; lpc_c2r_output_buffers [ myband ] = NULL ; } } if ( lpc_r2c_input_buffers [ myband ] == NULL ) { lpc_r2c_input_buffers [ myband ] = ( double * ) MALLOC ( lpc_r2c_plan_sizes [ myband ] * sizeof ( double ) ) ; } if ( lpc_r2c_output_buffers [ myband ] == NULL ) { lpc_r2c_output_buffers [ myband ] = ( complex * ) MALLOC ( lpc_r2c_plan_sizes [ myband ] * sizeof ( complex ) ) ; memset ( lpc_r2c_output_buffers [ myband ] , 0 , N * sizeof ( complex ) ) ; } if ( lpc_r2c_plans [ myband ] == NULL ) { lock_mutex ( & fftw_mutex ) ; lpc_r2c_plans [ myband ] = fftw_plan_dft_r2c_1d ( lpc_r2c_plan_sizes [ myband ] , lpc_r2c_input_buffers [ myband ] , lpc_r2c_output_buffers [ myband ] , FFTW_ESTIMATE ) ; unlock_mutex ( & fftw_mutex ) ; } if ( lpc_c2r_output_buffers [ myband ] == NULL ) { lpc_c2r_output_buffers [ myband ] = ( double * ) MALLOC ( lpc_r2c_plan_sizes [ myband ] * sizeof ( double ) ) ; } if ( lpc_c2r_plans [ myband ] == NULL ) { lock_mutex ( & fftw_mutex ) ; lpc_c2r_plans [ myband ] = fftw_plan_dft_c2r_1d ( lpc_r2c_plan_sizes [ myband ] , lpc_r2c_output_buffers [ myband ] , lpc_c2r_output_buffers [ myband ] , FFTW_ESTIMATE ) ; unlock_mutex ( & fftw_mutex ) ; } for ( int n = 0 ; n < N ; n ++ ) { if ( n < len ) { lpc_r2c_input_buffers [ myband ] [ n ] = y [ n ] ; } else { lpc_r2c_input_buffers [ myband ] [ n ] = 0 ; } } fftw_execute ( lpc_r2c_plans [ myband ] ) ; for ( int n = 0 ; n < N ; n ++ ) { lpc_r2c_output_buffers [ myband ] [ n ] = lpc_r2c_output_buffers [ myband ] [ n ] * conj ( lpc_r2c_output_buffers [ myband ] [ n ] ) / len ; } fftw_execute ( lpc_c2r_plans [ myband ] ) ; for ( int n = 0 ; n < N ; n ++ ) { lpc_c2r_output_buffers [ myband ] [ n ] /= N ; } levinson ( order , lpc_c2r_output_buffers [ myband ] , poles ) ; }
"standard" lpc using autocorrelation + levinson-durbin
" standard " lpc using autocorrelation + levinson - durbin
// Compute autocorrelation vector or matrix // fix uninitialized value-issue in multiplication below  //add compr