From 9022d768021bbe15c7815cc6f8b64218b46f0e10 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Thu, 15 Oct 2020 16:27:49 +0200 Subject: Bump to upstream version 0.9.2 --- nlp.c | 183 +----------------------------------------------------------------- 1 file changed, 1 insertion(+), 182 deletions(-) (limited to 'nlp.c') diff --git a/nlp.c b/nlp.c index 8c8d5f1..036f6be 100644 --- a/nlp.c +++ b/nlp.c @@ -53,7 +53,6 @@ #define F0_MAX 500 #define CNLP 0.3 /* post processor constant */ #define NLP_NTAP 48 /* Decimation LPF order */ -#undef POST_PROCESS_MBE /* choose post processor */ /* 8 to 16 kHz sample rate conversion */ @@ -132,10 +131,6 @@ typedef struct { FILE *f; } NLP; -#ifdef POST_PROCESS_MBE -float test_candidate_mbe(COMP Sw[], COMP W[], float f0); -float post_process_mbe(COMP Fw[], int pmin, int pmax, float gmax, COMP Sw[], COMP W[], float *prev_Wo); -#endif float post_process_sub_multiples(COMP Fw[], int pmin, int pmax, float gmax, int gmax_bin, float *prev_f0); @@ -258,7 +253,7 @@ float nlp( int n, /* frames shift (no. new samples in Sn[]) */ float *pitch, /* estimated pitch period in samples at current Fs */ COMP Sw[], /* Freq domain version of Sn[] */ - COMP W[], /* Freq domain window */ + float W[], /* Freq domain window */ float *prev_f0 /* previous pitch f0 in Hz, memory for pitch tracking */ ) { @@ -389,11 +384,7 @@ float nlp( PROFILE_SAMPLE_AND_LOG(peakpick, magsq, " peak pick"); - #ifdef POST_PROCESS_MBE - best_f0 = post_process_mbe(Fw, pmin, pmax, gmax, Sw, W, prev_f0); - #else best_f0 = post_process_sub_multiples(Fw, pmin, pmax, gmax, gmax_bin, prev_f0); - #endif PROFILE_SAMPLE_AND_LOG(shiftmem, peakpick, " post process"); @@ -491,178 +482,6 @@ float post_process_sub_multiples(COMP Fw[], return best_f0; } -#ifdef POST_PROCESS_MBE - -/*---------------------------------------------------------------------------*\ - - post_process_mbe() - - Use the MBE pitch estimation algorithm to evaluate pitch candidates. This - works OK but the accuracy at low F0 is affected by NW, the analysis window - size used for the DFT of the input speech Sw[]. Also favours high F0 in - the presence of background noise which causes periodic artifacts in the - synthesised speech. - -\*---------------------------------------------------------------------------*/ - -float post_process_mbe(COMP Fw[], int pmin, int pmax, float gmax, COMP Sw[], COMP W[], float *prev_Wo) -{ - float candidate_f0; - float f0,best_f0; /* fundamental frequency */ - float e,e_min; /* MBE cost function */ - int i; - #ifdef DUMP - float e_hz[F0_MAX]; - #endif - #if !defined(NDEBUG) || defined(DUMP) - int bin; - #endif - float f0_min, f0_max; - float f0_start, f0_end; - - f0_min = (float)SAMPLE_RATE/pmax; - f0_max = (float)SAMPLE_RATE/pmin; - - /* Now look for local maxima. Each local maxima is a candidate - that we test using the MBE pitch estimation algotithm */ - - #ifdef DUMP - for(i=0; i Fw[i-1].real) && (Fw[i].real > Fw[i+1].real)) { - - /* local maxima found, lets test if it's big enough */ - - if (Fw[i].real > T*gmax) { - - /* OK, sample MBE cost function over +/- 10Hz range in 2.5Hz steps */ - - candidate_f0 = (float)i*SAMPLE_RATE/(PE_FFT_SIZE*DEC); - f0_start = candidate_f0-20; - f0_end = candidate_f0+20; - if (f0_start < f0_min) f0_start = f0_min; - if (f0_end > f0_max) f0_end = f0_max; - - for(f0=f0_start; f0<=f0_end; f0+= 2.5) { - e = test_candidate_mbe(Sw, W, f0); - #if !defined(NDEBUG) || defined(DUMP) - bin = floorf(f0); assert((bin > 0) && (bin < F0_MAX)); - #endif - #ifdef DUMP - e_hz[bin] = e; - #endif - if (e < e_min) { - e_min = e; - best_f0 = f0; - } - } - - } - } - } - - /* finally sample MBE cost function around previous pitch estimate - (form of pitch tracking) */ - - candidate_f0 = *prev_Wo * SAMPLE_RATE/TWO_PI; - f0_start = candidate_f0-20; - f0_end = candidate_f0+20; - if (f0_start < f0_min) f0_start = f0_min; - if (f0_end > f0_max) f0_end = f0_max; - - for(f0=f0_start; f0<=f0_end; f0+= 2.5) { - e = test_candidate_mbe(Sw, W, f0); - #if !defined(NDEBUG) || defined(DUMP) - bin = floorf(f0); assert((bin > 0) && (bin < F0_MAX)); - #endif - #ifdef DUMP - e_hz[bin] = e; - #endif - if (e < e_min) { - e_min = e; - best_f0 = f0; - } - } - - #ifdef DUMP - dump_e(e_hz); - #endif - - return best_f0; -} - -/*---------------------------------------------------------------------------*\ - - test_candidate_mbe() - - Returns the error of the MBE cost function for the input f0. - - Note: I think a lot of the operations below can be simplified as - W[].imag = 0 and has been normalised such that den always equals 1. - -\*---------------------------------------------------------------------------*/ - -float test_candidate_mbe( - COMP Sw[], - COMP W[], - float f0 -) -{ - COMP Sw_[FFT_ENC]; /* DFT of all voiced synthesised signal */ - int l,al,bl,m; /* loop variables */ - COMP Am; /* amplitude sample for this band */ - int offset; /* centers Hw[] about current harmonic */ - float den; /* denominator of Am expression */ - float error; /* accumulated error between originl and synthesised */ - float Wo; /* current "test" fundamental freq. */ - int L; - - L = floorf((SAMPLE_RATE/2.0)/f0); - Wo = f0*(2*PI/SAMPLE_RATE); - - error = 0.0; - - /* Just test across the harmonics in the first 1000 Hz (L/4) */ - - for(l=1; l