OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 /*----------------------------------------------------------------* | 24 /*----------------------------------------------------------------* |
25 * find segment starting near idata+estSegPos that has highest | 25 * find segment starting near idata+estSegPos that has highest |
26 * correlation with idata+centerStartPos through | 26 * correlation with idata+centerStartPos through |
27 * idata+centerStartPos+ENH_BLOCKL-1 segment is found at a | 27 * idata+centerStartPos+ENH_BLOCKL-1 segment is found at a |
28 * resolution of ENH_UPSO times the original of the original | 28 * resolution of ENH_UPSO times the original of the original |
29 * sampling rate | 29 * sampling rate |
30 *---------------------------------------------------------------*/ | 30 *---------------------------------------------------------------*/ |
31 | 31 |
32 void WebRtcIlbcfix_Refiner( | 32 void WebRtcIlbcfix_Refiner( |
33 int16_t *updStartPos, /* (o) updated start point (Q-2) */ | 33 size_t *updStartPos, /* (o) updated start point (Q-2) */ |
34 int16_t *idata, /* (i) original data buffer */ | 34 int16_t *idata, /* (i) original data buffer */ |
35 int16_t idatal, /* (i) dimension of idata */ | 35 size_t idatal, /* (i) dimension of idata */ |
36 int16_t centerStartPos, /* (i) beginning center segment */ | 36 size_t centerStartPos, /* (i) beginning center segment */ |
37 int16_t estSegPos, /* (i) estimated beginning other segment (Q-2) */ | 37 size_t estSegPos, /* (i) estimated beginning other segment (Q-2) */ |
38 int16_t *surround, /* (i/o) The contribution from this sequence | 38 int16_t *surround, /* (i/o) The contribution from this sequence |
39 summed with earlier contributions */ | 39 summed with earlier contributions */ |
40 int16_t gain /* (i) Gain to use for this sequence */ | 40 int16_t gain /* (i) Gain to use for this sequence */ |
41 ){ | 41 ){ |
42 int16_t estSegPosRounded,searchSegStartPos,searchSegEndPos; | 42 size_t estSegPosRounded, searchSegStartPos, searchSegEndPos, corrdim; |
43 size_t corrdim,i; | 43 size_t tloc, tloc2, i; |
44 int16_t tloc,tloc2,st,en,fraction; | |
45 | 44 |
46 int32_t maxtemp, scalefact; | 45 int32_t maxtemp, scalefact; |
47 int16_t *filtStatePtr, *polyPtr; | 46 int16_t *filtStatePtr, *polyPtr; |
48 /* Stack based */ | 47 /* Stack based */ |
49 int16_t filt[7]; | 48 int16_t filt[7]; |
50 int32_t corrVecUps[ENH_CORRDIM*ENH_UPS0]; | 49 int32_t corrVecUps[ENH_CORRDIM*ENH_UPS0]; |
51 int32_t corrVecTemp[ENH_CORRDIM]; | 50 int32_t corrVecTemp[ENH_CORRDIM]; |
52 int16_t vect[ENH_VECTL]; | 51 int16_t vect[ENH_VECTL]; |
53 int16_t corrVec[ENH_CORRDIM]; | 52 int16_t corrVec[ENH_CORRDIM]; |
54 | 53 |
55 /* defining array bounds */ | 54 /* defining array bounds */ |
56 | 55 |
57 estSegPosRounded = (estSegPos - 2) >> 2; | 56 estSegPosRounded = (estSegPos - 2) >> 2; |
58 | 57 |
59 searchSegStartPos=estSegPosRounded-ENH_SLOP; | 58 searchSegStartPos = |
| 59 (estSegPosRounded < ENH_SLOP) ? 0 : (estSegPosRounded - ENH_SLOP); |
60 | 60 |
61 if (searchSegStartPos<0) { | 61 searchSegEndPos = estSegPosRounded + ENH_SLOP; |
62 searchSegStartPos=0; | 62 if ((searchSegEndPos + ENH_BLOCKL) >= idatal) { |
| 63 searchSegEndPos = idatal - ENH_BLOCKL - 1; |
63 } | 64 } |
64 searchSegEndPos=estSegPosRounded+ENH_SLOP; | |
65 | 65 |
66 if(searchSegEndPos+ENH_BLOCKL >= idatal) { | 66 corrdim = searchSegEndPos + 1 - searchSegStartPos; |
67 searchSegEndPos=idatal-ENH_BLOCKL-1; | |
68 } | |
69 corrdim=(size_t)(searchSegEndPos-searchSegStartPos+1); | |
70 | 67 |
71 /* compute upsampled correlation and find | 68 /* compute upsampled correlation and find |
72 location of max */ | 69 location of max */ |
73 | 70 |
74 WebRtcIlbcfix_MyCorr(corrVecTemp,idata+searchSegStartPos, | 71 WebRtcIlbcfix_MyCorr(corrVecTemp, idata + searchSegStartPos, |
75 corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL); | 72 corrdim + ENH_BLOCKL - 1, idata + centerStartPos, |
| 73 ENH_BLOCKL); |
76 | 74 |
77 /* Calculate the rescaling factor for the correlation in order to | 75 /* Calculate the rescaling factor for the correlation in order to |
78 put the correlation in a int16_t vector instead */ | 76 put the correlation in a int16_t vector instead */ |
79 maxtemp=WebRtcSpl_MaxAbsValueW32(corrVecTemp, corrdim); | 77 maxtemp = WebRtcSpl_MaxAbsValueW32(corrVecTemp, corrdim); |
80 | 78 |
81 scalefact=WebRtcSpl_GetSizeInBits(maxtemp)-15; | 79 scalefact = WebRtcSpl_GetSizeInBits(maxtemp) - 15; |
82 | 80 |
83 if (scalefact>0) { | 81 if (scalefact > 0) { |
84 for (i=0;i<corrdim;i++) { | 82 for (i = 0; i < corrdim; i++) { |
85 corrVec[i] = (int16_t)(corrVecTemp[i] >> scalefact); | 83 corrVec[i] = (int16_t)(corrVecTemp[i] >> scalefact); |
86 } | 84 } |
87 } else { | 85 } else { |
88 for (i=0;i<corrdim;i++) { | 86 for (i = 0; i < corrdim; i++) { |
89 corrVec[i]=(int16_t)corrVecTemp[i]; | 87 corrVec[i] = (int16_t)corrVecTemp[i]; |
90 } | 88 } |
91 } | 89 } |
92 /* In order to guarantee that all values are initialized */ | 90 /* In order to guarantee that all values are initialized */ |
93 for (i=corrdim;i<ENH_CORRDIM;i++) { | 91 for (i = corrdim; i < ENH_CORRDIM; i++) { |
94 corrVec[i]=0; | 92 corrVec[i] = 0; |
95 } | 93 } |
96 | 94 |
97 /* Upsample the correlation */ | 95 /* Upsample the correlation */ |
98 WebRtcIlbcfix_EnhUpsample(corrVecUps,corrVec); | 96 WebRtcIlbcfix_EnhUpsample(corrVecUps, corrVec); |
99 | 97 |
100 /* Find maximum */ | 98 /* Find maximum */ |
101 tloc=WebRtcSpl_MaxIndexW32(corrVecUps, ENH_UPS0 * corrdim); | 99 tloc = WebRtcSpl_MaxIndexW32(corrVecUps, ENH_UPS0 * corrdim); |
102 | 100 |
103 /* make vector can be upsampled without ever running outside | 101 /* make vector can be upsampled without ever running outside |
104 bounds */ | 102 bounds */ |
105 *updStartPos = (int16_t)(searchSegStartPos * 4) + tloc + 4; | 103 *updStartPos = searchSegStartPos * 4 + tloc + 4; |
106 | 104 |
107 tloc2 = (tloc + 3) >> 2; | 105 tloc2 = (tloc + 3) >> 2; |
108 | 106 |
109 st=searchSegStartPos+tloc2-ENH_FL0; | |
110 | |
111 /* initialize the vector to be filtered, stuff with zeros | 107 /* initialize the vector to be filtered, stuff with zeros |
112 when data is outside idata buffer */ | 108 when data is outside idata buffer */ |
113 if(st<0){ | 109 if (ENH_FL0 > (searchSegStartPos + tloc2)) { |
114 WebRtcSpl_MemSetW16(vect, 0, (size_t)(-st)); | 110 const size_t st = ENH_FL0 - searchSegStartPos - tloc2; |
115 WEBRTC_SPL_MEMCPY_W16(&vect[-st], idata, (ENH_VECTL+st)); | 111 WebRtcSpl_MemSetW16(vect, 0, st); |
116 } | 112 WEBRTC_SPL_MEMCPY_W16(&vect[st], idata, ENH_VECTL - st); |
117 else{ | 113 } else { |
118 en=st+ENH_VECTL; | 114 const size_t st = searchSegStartPos + tloc2 - ENH_FL0; |
119 | 115 if ((st + ENH_VECTL) > idatal) { |
120 if(en>idatal){ | 116 const size_t en = st + ENH_VECTL - idatal; |
121 WEBRTC_SPL_MEMCPY_W16(vect, &idata[st], | 117 WEBRTC_SPL_MEMCPY_W16(vect, &idata[st], ENH_VECTL - en); |
122 (ENH_VECTL-(en-idatal))); | 118 WebRtcSpl_MemSetW16(&vect[ENH_VECTL - en], 0, en); |
123 WebRtcSpl_MemSetW16(&vect[ENH_VECTL-(en-idatal)], 0, | 119 } else { |
124 (size_t)(en-idatal)); | |
125 } | |
126 else { | |
127 WEBRTC_SPL_MEMCPY_W16(vect, &idata[st], ENH_VECTL); | 120 WEBRTC_SPL_MEMCPY_W16(vect, &idata[st], ENH_VECTL); |
128 } | 121 } |
129 } | 122 } |
130 /* Calculate which of the 4 fractions to use */ | |
131 fraction = (int16_t)(tloc2 * ENH_UPS0) - tloc; | |
132 | 123 |
133 /* compute the segment (this is actually a convolution) */ | 124 /* compute the segment (this is actually a convolution) */ |
134 | |
135 filtStatePtr = filt + 6; | 125 filtStatePtr = filt + 6; |
136 polyPtr = (int16_t*)WebRtcIlbcfix_kEnhPolyPhaser[fraction]; | 126 polyPtr = (int16_t*)WebRtcIlbcfix_kEnhPolyPhaser[tloc2 * ENH_UPS0 - tloc]; |
137 for (i=0;i<7;i++) { | 127 for (i = 0; i < 7; i++) { |
138 *filtStatePtr-- = *polyPtr++; | 128 *filtStatePtr-- = *polyPtr++; |
139 } | 129 } |
140 | 130 |
141 WebRtcSpl_FilterMAFastQ12( | 131 WebRtcSpl_FilterMAFastQ12(&vect[6], vect, filt, ENH_FLO_MULT2_PLUS1, |
142 &vect[6], vect, filt, | 132 ENH_BLOCKL); |
143 ENH_FLO_MULT2_PLUS1, ENH_BLOCKL); | |
144 | 133 |
145 /* Add the contribution from this vector (scaled with gain) to the total surro
und vector */ | 134 /* Add the contribution from this vector (scaled with gain) to the total |
146 WebRtcSpl_AddAffineVectorToVector( | 135 surround vector */ |
147 surround, vect, gain, | 136 WebRtcSpl_AddAffineVectorToVector(surround, vect, gain, 32768, 16, |
148 (int32_t)32768, 16, ENH_BLOCKL); | 137 ENH_BLOCKL); |
149 | 138 |
150 return; | 139 return; |
151 } | 140 } |
OLD | NEW |