niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Timothy Gu | 3111783 | 2020-12-18 22:25:57 -0800 | [diff] [blame] | 19 | #include "modules/audio_coding/codecs/ilbc/lsf_check.h" |
| 20 | |
Mirko Bonadei | 06c2aa9 | 2018-02-01 15:11:41 +0100 | [diff] [blame] | 21 | #include "modules/audio_coding/codecs/ilbc/constants.h" |
Timothy Gu | 3111783 | 2020-12-18 22:25:57 -0800 | [diff] [blame] | 22 | #include "modules/audio_coding/codecs/ilbc/defines.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | /*----------------------------------------------------------------* |
| 25 | * check for stability of lsf coefficients |
| 26 | *---------------------------------------------------------------*/ |
| 27 | |
| 28 | int WebRtcIlbcfix_LsfCheck( |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 29 | int16_t *lsf, /* LSF parameters */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 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)*/ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | } |