| 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 /*----------------------------------------------------------------* | 29 /*----------------------------------------------------------------* |
| 30 * interface for enhancer | 30 * interface for enhancer |
| 31 *---------------------------------------------------------------*/ | 31 *---------------------------------------------------------------*/ |
| 32 | 32 |
| 33 size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ | 33 size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ |
| 34 int16_t *out, /* (o) enhanced signal */ | 34 int16_t *out, /* (o) enhanced signal */ |
| 35 int16_t *in, /* (i) unenhanced signal */ | 35 int16_t *in, /* (i) unenhanced signal */ |
| 36 IlbcDecoder *iLBCdec_inst /* (i) buffers etc */ | 36 IlbcDecoder *iLBCdec_inst /* (i) buffers etc */ |
| 37 ){ | 37 ){ |
| 38 int iblock; | 38 size_t iblock; |
| 39 size_t lag=20, tlag=20; | 39 size_t lag=20, tlag=20; |
| 40 size_t inLen=iLBCdec_inst->blockl+120; | 40 size_t inLen=iLBCdec_inst->blockl+120; |
| 41 int16_t scale, scale1; | 41 int16_t scale, scale1; |
| 42 size_t plc_blockl; | 42 size_t plc_blockl; |
| 43 int16_t *enh_buf, *enh_period; | 43 int16_t *enh_buf; |
| 44 int32_t tmp1, tmp2, max, new_blocks; | 44 size_t *enh_period; |
| 45 int32_t tmp1, tmp2, max; |
| 46 size_t new_blocks; |
| 45 int16_t *enh_bufPtr1; | 47 int16_t *enh_bufPtr1; |
| 46 size_t i; | 48 size_t i; |
| 47 int k; | 49 size_t k; |
| 48 int16_t EnChange; | 50 int16_t EnChange; |
| 49 int16_t SqrtEnChange; | 51 int16_t SqrtEnChange; |
| 50 int16_t inc; | 52 int16_t inc; |
| 51 int16_t win; | 53 int16_t win; |
| 52 int16_t *tmpW16ptr; | 54 int16_t *tmpW16ptr; |
| 53 int16_t startPos; | 55 size_t startPos; |
| 54 int16_t *plc_pred; | 56 int16_t *plc_pred; |
| 55 int16_t *target, *regressor; | 57 int16_t *target, *regressor; |
| 56 int16_t max16; | 58 int16_t max16; |
| 57 int shifts; | 59 int shifts; |
| 58 int32_t ener; | 60 int32_t ener; |
| 59 int16_t enerSh; | 61 int16_t enerSh; |
| 60 int16_t corrSh; | 62 int16_t corrSh; |
| 61 size_t ind; | 63 size_t ind; |
| 62 int16_t sh; | 64 int16_t sh; |
| 63 int16_t start, stop; | 65 size_t start, stop; |
| 64 /* Stack based */ | 66 /* Stack based */ |
| 65 int16_t totsh[3]; | 67 int16_t totsh[3]; |
| 66 int16_t downsampled[(BLOCKL_MAX+120)>>1]; /* length 180 */ | 68 int16_t downsampled[(BLOCKL_MAX+120)>>1]; /* length 180 */ |
| 67 int32_t corr32[50]; | 69 int32_t corr32[50]; |
| 68 int32_t corrmax[3]; | 70 int32_t corrmax[3]; |
| 69 int16_t corr16[3]; | 71 int16_t corr16[3]; |
| 70 int16_t en16[3]; | 72 int16_t en16[3]; |
| 71 int16_t lagmax[3]; | 73 size_t lagmax[3]; |
| 72 | 74 |
| 73 plc_pred = downsampled; /* Reuse memory since plc_pred[ENH_BLOCKL] and | 75 plc_pred = downsampled; /* Reuse memory since plc_pred[ENH_BLOCKL] and |
| 74 downsampled are non overlapping */ | 76 downsampled are non overlapping */ |
| 75 enh_buf=iLBCdec_inst->enh_buf; | 77 enh_buf=iLBCdec_inst->enh_buf; |
| 76 enh_period=iLBCdec_inst->enh_period; | 78 enh_period=iLBCdec_inst->enh_period; |
| 77 | 79 |
| 78 /* Copy in the new data into the enhancer buffer */ | 80 /* Copy in the new data into the enhancer buffer */ |
| 79 memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl], | 81 memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl], |
| 80 (ENH_BUFL - iLBCdec_inst->blockl) * sizeof(*enh_buf)); | 82 (ENH_BUFL - iLBCdec_inst->blockl) * sizeof(*enh_buf)); |
| 81 | 83 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 92 plc_blockl=40; | 94 plc_blockl=40; |
| 93 new_blocks=2; | 95 new_blocks=2; |
| 94 startPos=440; /* Start position for enhancement | 96 startPos=440; /* Start position for enhancement |
| 95 (640-new_blocks*ENH_BLOCKL-40) */ | 97 (640-new_blocks*ENH_BLOCKL-40) */ |
| 96 } | 98 } |
| 97 | 99 |
| 98 /* Update the pitch prediction for each enhancer block, move the old ones */ | 100 /* Update the pitch prediction for each enhancer block, move the old ones */ |
| 99 memmove(enh_period, &enh_period[new_blocks], | 101 memmove(enh_period, &enh_period[new_blocks], |
| 100 (ENH_NBLOCKS_TOT - new_blocks) * sizeof(*enh_period)); | 102 (ENH_NBLOCKS_TOT - new_blocks) * sizeof(*enh_period)); |
| 101 | 103 |
| 102 k = WebRtcSpl_DownsampleFast( | 104 WebRtcSpl_DownsampleFast( |
| 103 enh_buf+ENH_BUFL-inLen, /* Input samples */ | 105 enh_buf+ENH_BUFL-inLen, /* Input samples */ |
| 104 inLen + ENH_BUFL_FILTEROVERHEAD, | 106 inLen + ENH_BUFL_FILTEROVERHEAD, |
| 105 downsampled, | 107 downsampled, |
| 106 inLen / 2, | 108 inLen / 2, |
| 107 (int16_t*)WebRtcIlbcfix_kLpFiltCoefs, /* Coefficients in Q12 */ | 109 (int16_t*)WebRtcIlbcfix_kLpFiltCoefs, /* Coefficients in Q12 */ |
| 108 FILTERORDER_DS_PLUS1, /* Length of filter (order-1) */ | 110 FILTERORDER_DS_PLUS1, /* Length of filter (order-1) */ |
| 109 FACTOR_DS, | 111 FACTOR_DS, |
| 110 DELAY_DS); | 112 DELAY_DS); |
| 111 | 113 |
| 112 /* Estimate the pitch in the down sampled domain. */ | 114 /* Estimate the pitch in the down sampled domain. */ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 124 /* compute cross correlation */ | 126 /* compute cross correlation */ |
| 125 WebRtcSpl_CrossCorrelation(corr32, target, regressor, ENH_BLOCKL_HALF, 50, | 127 WebRtcSpl_CrossCorrelation(corr32, target, regressor, ENH_BLOCKL_HALF, 50, |
| 126 shifts, -1); | 128 shifts, -1); |
| 127 | 129 |
| 128 /* Find 3 highest correlations that should be compared for the | 130 /* Find 3 highest correlations that should be compared for the |
| 129 highest (corr*corr)/ener */ | 131 highest (corr*corr)/ener */ |
| 130 | 132 |
| 131 for (i=0;i<2;i++) { | 133 for (i=0;i<2;i++) { |
| 132 lagmax[i] = WebRtcSpl_MaxIndexW32(corr32, 50); | 134 lagmax[i] = WebRtcSpl_MaxIndexW32(corr32, 50); |
| 133 corrmax[i] = corr32[lagmax[i]]; | 135 corrmax[i] = corr32[lagmax[i]]; |
| 134 start = lagmax[i] - 2; | 136 start = WEBRTC_SPL_MAX(2, lagmax[i]) - 2; |
| 135 stop = lagmax[i] + 2; | 137 stop = WEBRTC_SPL_MIN(47, lagmax[i]) + 2; |
| 136 start = WEBRTC_SPL_MAX(0, start); | 138 for (k = start; k <= stop; k++) { |
| 137 stop = WEBRTC_SPL_MIN(49, stop); | |
| 138 for (k=start; k<=stop; k++) { | |
| 139 corr32[k] = 0; | 139 corr32[k] = 0; |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 lagmax[2] = WebRtcSpl_MaxIndexW32(corr32, 50); | 142 lagmax[2] = WebRtcSpl_MaxIndexW32(corr32, 50); |
| 143 corrmax[2] = corr32[lagmax[2]]; | 143 corrmax[2] = corr32[lagmax[2]]; |
| 144 | 144 |
| 145 /* Calculate normalized corr^2 and ener */ | 145 /* Calculate normalized corr^2 and ener */ |
| 146 for (i=0;i<3;i++) { | 146 for (i=0;i<3;i++) { |
| 147 corrSh = 15-WebRtcSpl_GetSizeInBits(corrmax[i]); | 147 corrSh = 15-WebRtcSpl_GetSizeInBits(corrmax[i]); |
| 148 ener = WebRtcSpl_DotProductWithScale(®ressor[-lagmax[i]], | 148 ener = WebRtcSpl_DotProductWithScale(regressor - lagmax[i], |
| 149 ®ressor[-lagmax[i]], | 149 regressor - lagmax[i], |
| 150 ENH_BLOCKL_HALF, shifts); | 150 ENH_BLOCKL_HALF, shifts); |
| 151 enerSh = 15-WebRtcSpl_GetSizeInBits(ener); | 151 enerSh = 15-WebRtcSpl_GetSizeInBits(ener); |
| 152 corr16[i] = (int16_t)WEBRTC_SPL_SHIFT_W32(corrmax[i], corrSh); | 152 corr16[i] = (int16_t)WEBRTC_SPL_SHIFT_W32(corrmax[i], corrSh); |
| 153 corr16[i] = (int16_t)((corr16[i] * corr16[i]) >> 16); | 153 corr16[i] = (int16_t)((corr16[i] * corr16[i]) >> 16); |
| 154 en16[i] = (int16_t)WEBRTC_SPL_SHIFT_W32(ener, enerSh); | 154 en16[i] = (int16_t)WEBRTC_SPL_SHIFT_W32(ener, enerSh); |
| 155 totsh[i] = enerSh - (corrSh << 1); | 155 totsh[i] = enerSh - (corrSh << 1); |
| 156 } | 156 } |
| 157 | 157 |
| 158 /* Compare lagmax[0..3] for the (corr^2)/ener criteria */ | 158 /* Compare lagmax[0..3] for the (corr^2)/ener criteria */ |
| 159 ind = 0; | 159 ind = 0; |
| 160 for (i=1; i<3; i++) { | 160 for (i=1; i<3; i++) { |
| 161 if (totsh[ind] > totsh[i]) { | 161 if (totsh[ind] > totsh[i]) { |
| 162 sh = WEBRTC_SPL_MIN(31, totsh[ind]-totsh[i]); | 162 sh = WEBRTC_SPL_MIN(31, totsh[ind]-totsh[i]); |
| 163 if (corr16[ind] * en16[i] < (corr16[i] * en16[ind]) >> sh) { | 163 if (corr16[ind] * en16[i] < (corr16[i] * en16[ind]) >> sh) { |
| 164 ind = i; | 164 ind = i; |
| 165 } | 165 } |
| 166 } else { | 166 } else { |
| 167 sh = WEBRTC_SPL_MIN(31, totsh[i]-totsh[ind]); | 167 sh = WEBRTC_SPL_MIN(31, totsh[i]-totsh[ind]); |
| 168 if ((corr16[ind] * en16[i]) >> sh < corr16[i] * en16[ind]) { | 168 if ((corr16[ind] * en16[i]) >> sh < corr16[i] * en16[ind]) { |
| 169 ind = i; | 169 ind = i; |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 lag = (size_t)(lagmax[ind] + 10); | 174 lag = lagmax[ind] + 10; |
| 175 | 175 |
| 176 /* Store the estimated lag in the non-downsampled domain */ | 176 /* Store the estimated lag in the non-downsampled domain */ |
| 177 enh_period[ENH_NBLOCKS_TOT - new_blocks + iblock] = (int16_t)(lag * 8); | 177 enh_period[ENH_NBLOCKS_TOT - new_blocks + iblock] = lag * 8; |
| 178 | 178 |
| 179 /* Store the estimated lag for backward PLC */ | 179 /* Store the estimated lag for backward PLC */ |
| 180 if (iLBCdec_inst->prev_enh_pl==1) { | 180 if (iLBCdec_inst->prev_enh_pl==1) { |
| 181 if (!iblock) { | 181 if (!iblock) { |
| 182 tlag = lag * 2; | 182 tlag = lag * 2; |
| 183 } | 183 } |
| 184 } else { | 184 } else { |
| 185 if (iblock==1) { | 185 if (iblock==1) { |
| 186 tlag = lag * 2; | 186 tlag = lag * 2; |
| 187 } | 187 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 361 } |
| 362 } | 362 } |
| 363 | 363 |
| 364 | 364 |
| 365 /* Perform enhancement block by block */ | 365 /* Perform enhancement block by block */ |
| 366 | 366 |
| 367 for (iblock = 0; iblock<new_blocks; iblock++) { | 367 for (iblock = 0; iblock<new_blocks; iblock++) { |
| 368 WebRtcIlbcfix_Enhancer(out + iblock * ENH_BLOCKL, | 368 WebRtcIlbcfix_Enhancer(out + iblock * ENH_BLOCKL, |
| 369 enh_buf, | 369 enh_buf, |
| 370 ENH_BUFL, | 370 ENH_BUFL, |
| 371 (int16_t)(iblock * ENH_BLOCKL + startPos), | 371 iblock * ENH_BLOCKL + startPos, |
| 372 enh_period, | 372 enh_period, |
| 373 (int16_t*)WebRtcIlbcfix_kEnhPlocs, ENH_NBLOCKS_TOT); | 373 WebRtcIlbcfix_kEnhPlocs, ENH_NBLOCKS_TOT); |
| 374 } | 374 } |
| 375 | 375 |
| 376 return (lag); | 376 return (lag); |
| 377 } | 377 } |
| OLD | NEW |