Asterisk - The Open Source Telephony Project GIT-master-f36a736
FrameClassify.c
Go to the documentation of this file.
1
2 /******************************************************************
3
4 iLBC Speech Coder ANSI-C Source Code
5
6 FrameClassify.c
7
8 Copyright (C) The Internet Society (2004).
9 All Rights Reserved.
10
11 ******************************************************************/
12
13 #include "iLBC_define.h"
14
15 /*---------------------------------------------------------------*
16 * Classification of subframes to localize start state
17 *--------------------------------------------------------------*/
18
19 int FrameClassify( /* index to the max-energy sub-frame */
20 iLBC_Enc_Inst_t *iLBCenc_inst,
21 /* (i/o) the encoder state structure */
22 float *residual /* (i) lpc residual signal */
23 ) {
24 float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp;
25 int n, l, max_ssqEn_n;
26 const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9,
27 (float)1.0,(float)0.9,(float)0.8};
28 const float sampEn_win[5]={(float)1.0/(float)6.0,
29 (float)2.0/(float)6.0, (float)3.0/(float)6.0,
30 (float)4.0/(float)6.0, (float)5.0/(float)6.0};
31
32 /* init the front and back energies to zero */
33
34 memset(fssqEn, 0, NSUB_MAX*sizeof(float));
35 memset(bssqEn, 0, NSUB_MAX*sizeof(float));
36
37 /* Calculate front of first seqence */
38
39 n=0;
40 pp=residual;
41 for (l=0; l<5; l++) {
42 fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
43 pp++;
44 }
45 for (l=5; l<SUBL; l++) {
46
47
48
49
50
51 fssqEn[n] += (*pp) * (*pp);
52 pp++;
53 }
54
55 /* Calculate front and back of all middle sequences */
56
57 for (n=1; n<iLBCenc_inst->nsub-1; n++) {
58 pp=residual+n*SUBL;
59 for (l=0; l<5; l++) {
60 fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
61 bssqEn[n] += (*pp) * (*pp);
62 pp++;
63 }
64 for (l=5; l<SUBL-5; l++) {
65 fssqEn[n] += (*pp) * (*pp);
66 bssqEn[n] += (*pp) * (*pp);
67 pp++;
68 }
69 for (l=SUBL-5; l<SUBL; l++) {
70 fssqEn[n] += (*pp) * (*pp);
71 bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
72 pp++;
73 }
74 }
75
76 /* Calculate back of last seqence */
77
78 n=iLBCenc_inst->nsub-1;
79 pp=residual+n*SUBL;
80 for (l=0; l<SUBL-5; l++) {
81 bssqEn[n] += (*pp) * (*pp);
82 pp++;
83 }
84 for (l=SUBL-5; l<SUBL; l++) {
85 bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
86 pp++;
87 }
88
89 /* find the index to the weighted 80 sample with
90 most energy */
91
92 if (iLBCenc_inst->mode==20) l=1;
93 else l=0;
94
95 max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l];
96 max_ssqEn_n=1;
97 for (n=2; n<iLBCenc_inst->nsub; n++) {
98
99
100
101
102
103
104 l++;
105 if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) {
106 max_ssqEn=(fssqEn[n-1]+bssqEn[n]) *
107 ssqEn_win[l];
108 max_ssqEn_n=n;
109 }
110 }
111
112 return max_ssqEn_n;
113 }
int FrameClassify(iLBC_Enc_Inst_t *iLBCenc_inst, float *residual)
Definition: FrameClassify.c:19
#define SUBL
Definition: iLBC_define.h:33
#define NSUB_MAX
Definition: iLBC_define.h:24