1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 /****************************************************************** 12 13 iLBC Speech Coder ANSI-C Source Code 14 15 WebRtcIlbcfix_LsfCheck.c 16 17 ******************************************************************/ 18 19 #include "modules/audio_coding/codecs/ilbc/defines.h" 20 #include "modules/audio_coding/codecs/ilbc/constants.h" 21 22 /*----------------------------------------------------------------* 23 * check for stability of lsf coefficients 24 *---------------------------------------------------------------*/ 25 WebRtcIlbcfix_LsfCheck(int16_t * lsf,int dim,int NoAn)26int WebRtcIlbcfix_LsfCheck( 27 int16_t *lsf, /* LSF parameters */ 28 int dim, /* dimension of LSF */ 29 int NoAn) /* No of analysis per frame */ 30 { 31 int k,n,m, Nit=2, change=0,pos; 32 const int16_t eps=319; /* 0.039 in Q13 (50 Hz)*/ 33 const int16_t eps2=160; /* eps/2.0 in Q13;*/ 34 const int16_t maxlsf=25723; /* 3.14; (4000 Hz)*/ 35 const int16_t minlsf=82; /* 0.01; (0 Hz)*/ 36 37 /* LSF separation check*/ 38 for (n=0;n<Nit;n++) { /* Run through a 2 times */ 39 for (m=0;m<NoAn;m++) { /* Number of analyses per frame */ 40 for (k=0;k<(dim-1);k++) { 41 pos=m*dim+k; 42 43 /* Seperate coefficients with a safety margin of 50 Hz */ 44 if ((lsf[pos+1]-lsf[pos])<eps) { 45 46 if (lsf[pos+1]<lsf[pos]) { 47 lsf[pos+1]= lsf[pos]+eps2; 48 lsf[pos]= lsf[pos+1]-eps2; 49 } else { 50 lsf[pos]-=eps2; 51 lsf[pos+1]+=eps2; 52 } 53 change=1; 54 } 55 56 /* Limit minimum and maximum LSF */ 57 if (lsf[pos]<minlsf) { 58 lsf[pos]=minlsf; 59 change=1; 60 } 61 62 if (lsf[pos]>maxlsf) { 63 lsf[pos]=maxlsf; 64 change=1; 65 } 66 } 67 } 68 } 69 70 return change; 71 } 72