blob: 9f0e19a2d9f11b2f0bd6c972bb832e53710f5312 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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 Gu31117832020-12-18 22:25:57 -080019#include "modules/audio_coding/codecs/ilbc/lsf_check.h"
20
Mirko Bonadei06c2aa92018-02-01 15:11:41 +010021#include "modules/audio_coding/codecs/ilbc/constants.h"
Timothy Gu31117832020-12-18 22:25:57 -080022#include "modules/audio_coding/codecs/ilbc/defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24/*----------------------------------------------------------------*
25 * check for stability of lsf coefficients
26 *---------------------------------------------------------------*/
27
28int WebRtcIlbcfix_LsfCheck(
pbos@webrtc.org0946a562013-04-09 00:28:06 +000029 int16_t *lsf, /* LSF parameters */
niklase@google.com470e71d2011-07-07 08:21:25 +000030 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.org0946a562013-04-09 00:28:06 +000034 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.com470e71d2011-07-07 08:21:25 +000038
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}