Mercurial > hg > audiostuff
comparison intercom/ilbc/FrameClassify.c @ 2:13be24d74cd2
import intercom-0.4.1
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 09:57:52 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:9cadc470e3da | 2:13be24d74cd2 |
---|---|
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 { | |
25 float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp; | |
26 int n, l, max_ssqEn_n; | |
27 const float ssqEn_win[NSUB_MAX - 1] = { (float) 0.8, (float) 0.9, | |
28 (float) 1.0, (float) 0.9, (float) 0.8 | |
29 }; | |
30 const float sampEn_win[5] = { (float) 1.0 / (float) 6.0, | |
31 (float) 2.0 / (float) 6.0, (float) 3.0 / (float) 6.0, | |
32 (float) 4.0 / (float) 6.0, (float) 5.0 / (float) 6.0 | |
33 }; | |
34 | |
35 /* init the front and back energies to zero */ | |
36 | |
37 memset(fssqEn, 0, NSUB_MAX * sizeof(float)); | |
38 memset(bssqEn, 0, NSUB_MAX * sizeof(float)); | |
39 | |
40 /* Calculate front of first seqence */ | |
41 | |
42 n = 0; | |
43 pp = residual; | |
44 for (l = 0; l < 5; l++) { | |
45 fssqEn[n] += sampEn_win[l] * (*pp) * (*pp); | |
46 pp++; | |
47 } | |
48 for (l = 5; l < SUBL; l++) { | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 fssqEn[n] += (*pp) * (*pp); | |
55 pp++; | |
56 } | |
57 | |
58 /* Calculate front and back of all middle sequences */ | |
59 | |
60 for (n = 1; n < iLBCenc_inst->nsub - 1; n++) { | |
61 pp = residual + n * SUBL; | |
62 for (l = 0; l < 5; l++) { | |
63 fssqEn[n] += sampEn_win[l] * (*pp) * (*pp); | |
64 bssqEn[n] += (*pp) * (*pp); | |
65 pp++; | |
66 } | |
67 for (l = 5; l < SUBL - 5; l++) { | |
68 fssqEn[n] += (*pp) * (*pp); | |
69 bssqEn[n] += (*pp) * (*pp); | |
70 pp++; | |
71 } | |
72 for (l = SUBL - 5; l < SUBL; l++) { | |
73 fssqEn[n] += (*pp) * (*pp); | |
74 bssqEn[n] += sampEn_win[SUBL - l - 1] * (*pp) * (*pp); | |
75 pp++; | |
76 } | |
77 } | |
78 | |
79 /* Calculate back of last seqence */ | |
80 | |
81 n = iLBCenc_inst->nsub - 1; | |
82 pp = residual + n * SUBL; | |
83 for (l = 0; l < SUBL - 5; l++) { | |
84 bssqEn[n] += (*pp) * (*pp); | |
85 pp++; | |
86 } | |
87 for (l = SUBL - 5; l < SUBL; l++) { | |
88 bssqEn[n] += sampEn_win[SUBL - l - 1] * (*pp) * (*pp); | |
89 pp++; | |
90 } | |
91 | |
92 /* find the index to the weighted 80 sample with | |
93 most energy */ | |
94 | |
95 if (iLBCenc_inst->mode == 20) | |
96 l = 1; | |
97 else | |
98 l = 0; | |
99 | |
100 max_ssqEn = (fssqEn[0] + bssqEn[1]) * ssqEn_win[l]; | |
101 max_ssqEn_n = 1; | |
102 for (n = 2; n < iLBCenc_inst->nsub; n++) { | |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | |
109 l++; | |
110 if ((fssqEn[n - 1] + bssqEn[n]) * ssqEn_win[l] > max_ssqEn) { | |
111 max_ssqEn = (fssqEn[n - 1] + bssqEn[n]) * ssqEn_win[l]; | |
112 max_ssqEn_n = n; | |
113 } | |
114 } | |
115 | |
116 return max_ssqEn_n; | |
117 } |