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/lsf_check.h" 20 21 #include "modules/audio_coding/codecs/ilbc/constants.h" 22 #include "modules/audio_coding/codecs/ilbc/defines.h" 23 24 /*----------------------------------------------------------------* 25 * check for stability of lsf coefficients 26 *---------------------------------------------------------------*/ 27 WebRtcIlbcfix_LsfCheck(int16_t * lsf,int dim,int NoAn)28int WebRtcIlbcfix_LsfCheck( 29 int16_t *lsf, /* LSF parameters */ 30 int dim, /* dimension of LSF */ 31 int NoAn) /* No of analysis per frame */ 32 { 33 int k,n,m, Nit=2, change=0,pos; 34 const int16_t eps=319; /* 0.039 in Q13 (50 Hz)*/ 35 const int16_t eps2=160; /* eps/2.0 in Q13;*/ 36 const int16_t maxlsf=25723; /* 3.14; (4000 Hz)*/ 37 const int16_t minlsf=82; /* 0.01; (0 Hz)*/ 38 39 /* LSF separation check*/ 40 for (n=0;n<Nit;n++) { /* Run through a 2 times */ 41 for (m=0;m<NoAn;m++) { /* Number of analyses per frame */ 42 for (k=0;k<(dim-1);k++) { 43 pos=m*dim+k; 44 45 /* Seperate coefficients with a safety margin of 50 Hz */ 46 if ((lsf[pos+1]-lsf[pos])<eps) { 47 48 if (lsf[pos+1]<lsf[pos]) { 49 lsf[pos+1]= lsf[pos]+eps2; 50 lsf[pos]= lsf[pos+1]-eps2; 51 } else { 52 lsf[pos]-=eps2; 53 lsf[pos+1]+=eps2; 54 } 55 change=1; 56 } 57 58 /* Limit minimum and maximum LSF */ 59 if (lsf[pos]<minlsf) { 60 lsf[pos]=minlsf; 61 change=1; 62 } 63 64 if (lsf[pos]>maxlsf) { 65 lsf[pos]=maxlsf; 66 change=1; 67 } 68 } 69 } 70 } 71 72 return change; 73 } 74