From: drowe67 Date: Fri, 23 Jun 2017 08:38:42 +0000 (+0000) Subject: fixed oaccasional case where Wo*L >= PI X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=4dbd057755eae4e75a4cc6b42c067fcb4c787190;p=freetel-svn-tracking.git fixed oaccasional case where Wo*L >= PI git-svn-id: https://svn.code.sf.net/p/freetel/code@3239 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/sine.c b/codec2-dev/src/sine.c index 9ec134fa..72e39966 100644 --- a/codec2-dev/src/sine.c +++ b/codec2-dev/src/sine.c @@ -324,6 +324,12 @@ void two_stage_pitch_refinement(C2CONST *c2const, MODEL *model, COMP Sw[]) model->Wo = TWO_PI/c2const->p_min; model->L = floorf(PI/model->Wo); + + /* trap occasional round off issues with floorf() */ + if (model->Wo*model->L >= PI) { + model->L--; + } + assert(model->Wo*model->L < PI); } /*---------------------------------------------------------------------------*\ @@ -475,9 +481,10 @@ float est_voicing_mbe( Wo = model->Wo; error = 1E-4; - /* Just test across the harmonics in the first 1000 Hz (L/4) */ + /* Just test across the harmonics in the first 1000 Hz */ - for(l=1; l<=model->L/4; l++) { + int l_1000hz = model->L*1000.0/(c2const->Fs/2); + for(l=1; l<=l_1000hz; l++) { Am.real = 0.0; Am.imag = 0.0; den = 0.0; @@ -522,11 +529,13 @@ float est_voicing_mbe( determine if we have made any gross errors. */ + int l_2000hz = model->L*2000.0/(c2const->Fs/2); + int l_4000hz = model->L*4000.0/(c2const->Fs/2); elow = ehigh = 1E-4; - for(l=1; l<=model->L/2; l++) { + for(l=1; l<=l_2000hz; l++) { elow += model->A[l]*model->A[l]; } - for(l=model->L/2; l<=model->L; l++) { + for(l=l_2000hz; l<=l_4000hz; l++) { ehigh += model->A[l]*model->A[l]; } eratio = 10.0*log10f(elow/ehigh);