aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/audio_coding/codecs
diff options
context:
space:
mode:
authorPeter Kasting <pkasting@google.com>2015-08-28 17:31:03 -0700
committerPeter Kasting <pkasting@google.com>2015-08-29 00:31:15 +0000
commit1380e266ff48be9718ce0867cfd65058cb09c5fc (patch)
treee5132dc01f1bcdece3f8de78e50de5d61cc231fd /webrtc/modules/audio_coding/codecs
parente8386d21992b6683b6fadd315ea631875b4256fb (diff)
downloadwebrtc-1380e266ff48be9718ce0867cfd65058cb09c5fc.tar.gz
Convert some more things to size_t.
These changes stem from requests by Andrew on https://codereview.webrtc.org/1228823002/ to eliminate some "return -1"s and change to using asserts plus returning size_ts. I then also converted the relevant connected bits. This also cleans up a bunch of style issues, e.g. no spaces around operators. BUG=chromium:81439 TEST=none R=andrew@webrtc.org, henrik.lundin@webrtc.org, niklas.enbom@webrtc.org Review URL: https://codereview.webrtc.org/1305983003 . Cr-Commit-Position: refs/heads/master@{#9813}
Diffstat (limited to 'webrtc/modules/audio_coding/codecs')
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c2
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/constants.c2
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/constants.h2
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/defines.h2
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/enhancer.c10
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/enhancer.h8
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c38
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/frame_classify.c2
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.c80
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.h10
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c35
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.h9
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/refiner.c101
-rw-r--r--webrtc/modules/audio_coding/codecs/ilbc/refiner.h8
14 files changed, 141 insertions, 168 deletions
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c b/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c
index d297b1556c..fafa39f69b 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c
@@ -103,7 +103,7 @@ void WebRtcIlbcfix_CbSearchCore(
}
/* Find the index of the best value */
- *bestIndex = (size_t)WebRtcSpl_MaxIndexW32(Crit, range);
+ *bestIndex = WebRtcSpl_MaxIndexW32(Crit, range);
*bestCrit = Crit[*bestIndex];
/* Calculate total shifts of this criteria */
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/constants.c b/webrtc/modules/audio_coding/codecs/ilbc/constants.c
index f726ae2a6f..9e341942e6 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/constants.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/constants.c
@@ -647,7 +647,7 @@ const int16_t WebRtcIlbcfix_kEnhWt[3] = {
4800, 16384, 27968 /* Q16 */
};
-const int16_t WebRtcIlbcfix_kEnhPlocs[ENH_NBLOCKS_TOT] = {
+const size_t WebRtcIlbcfix_kEnhPlocs[ENH_NBLOCKS_TOT] = {
160, 480, 800, 1120, 1440, 1760, 2080, 2400 /* Q(-2) */
};
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/constants.h b/webrtc/modules/audio_coding/codecs/ilbc/constants.h
index 1f4de4d69f..7c4ad4d928 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/constants.h
+++ b/webrtc/modules/audio_coding/codecs/ilbc/constants.h
@@ -81,7 +81,7 @@ extern const int16_t WebRtcIlbcfix_kAlpha[];
extern const int16_t WebRtcIlbcfix_kEnhPolyPhaser[ENH_UPS0][ENH_FLO_MULT2_PLUS1];
extern const int16_t WebRtcIlbcfix_kEnhWt[];
-extern const int16_t WebRtcIlbcfix_kEnhPlocs[];
+extern const size_t WebRtcIlbcfix_kEnhPlocs[];
/* PLC tables */
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/defines.h b/webrtc/modules/audio_coding/codecs/ilbc/defines.h
index 5fcd4a01e4..2faaea15fc 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/defines.h
+++ b/webrtc/modules/audio_coding/codecs/ilbc/defines.h
@@ -213,7 +213,7 @@ typedef struct IlbcDecoder_ {
/* enhancer state information */
int use_enhancer;
int16_t enh_buf[ENH_BUFL+ENH_BUFL_FILTEROVERHEAD];
- int16_t enh_period[ENH_NBLOCKS_TOT];
+ size_t enh_period[ENH_NBLOCKS_TOT];
} IlbcDecoder;
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/enhancer.c b/webrtc/modules/audio_coding/codecs/ilbc/enhancer.c
index 5683597006..521d00441c 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/enhancer.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/enhancer.c
@@ -29,10 +29,10 @@
void WebRtcIlbcfix_Enhancer(
int16_t *odata, /* (o) smoothed block, dimension blockl */
int16_t *idata, /* (i) data buffer used for enhancing */
- int16_t idatal, /* (i) dimension idata */
- int16_t centerStartPos, /* (i) first sample current block within idata */
- int16_t *period, /* (i) pitch period array (pitch bward-in time) */
- int16_t *plocs, /* (i) locations where period array values valid */
+ size_t idatal, /* (i) dimension idata */
+ size_t centerStartPos, /* (i) first sample current block within idata */
+ size_t *period, /* (i) pitch period array (pitch bward-in time) */
+ const size_t *plocs, /* (i) locations where period array values valid */
size_t periodl /* (i) dimension of period and plocs */
){
/* Stack based */
@@ -47,5 +47,5 @@ void WebRtcIlbcfix_Enhancer(
/* compute the smoothed output from said second sequence */
- WebRtcIlbcfix_Smooth(odata, idata+centerStartPos, surround);
+ WebRtcIlbcfix_Smooth(odata, idata + centerStartPos, surround);
}
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/enhancer.h b/webrtc/modules/audio_coding/codecs/ilbc/enhancer.h
index 78a12d34cb..ed219fb1bb 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/enhancer.h
+++ b/webrtc/modules/audio_coding/codecs/ilbc/enhancer.h
@@ -29,10 +29,10 @@
void WebRtcIlbcfix_Enhancer(
int16_t *odata, /* (o) smoothed block, dimension blockl */
int16_t *idata, /* (i) data buffer used for enhancing */
- int16_t idatal, /* (i) dimension idata */
- int16_t centerStartPos, /* (i) first sample current block within idata */
- int16_t *period, /* (i) pitch period array (pitch bward-in time) */
- int16_t *plocs, /* (i) locations where period array values valid */
+ size_t idatal, /* (i) dimension idata */
+ size_t centerStartPos, /* (i) first sample current block within idata */
+ size_t *period, /* (i) pitch period array (pitch bward-in time) */
+ const size_t *plocs, /* (i) locations where period array values valid */
size_t periodl /* (i) dimension of period and plocs */
);
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c b/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c
index f15aee6676..1c0fd42383 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c
@@ -35,22 +35,24 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
int16_t *in, /* (i) unenhanced signal */
IlbcDecoder *iLBCdec_inst /* (i) buffers etc */
){
- int iblock;
+ size_t iblock;
size_t lag=20, tlag=20;
size_t inLen=iLBCdec_inst->blockl+120;
int16_t scale, scale1;
size_t plc_blockl;
- int16_t *enh_buf, *enh_period;
- int32_t tmp1, tmp2, max, new_blocks;
+ int16_t *enh_buf;
+ size_t *enh_period;
+ int32_t tmp1, tmp2, max;
+ size_t new_blocks;
int16_t *enh_bufPtr1;
size_t i;
- int k;
+ size_t k;
int16_t EnChange;
int16_t SqrtEnChange;
int16_t inc;
int16_t win;
int16_t *tmpW16ptr;
- int16_t startPos;
+ size_t startPos;
int16_t *plc_pred;
int16_t *target, *regressor;
int16_t max16;
@@ -60,7 +62,7 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
int16_t corrSh;
size_t ind;
int16_t sh;
- int16_t start, stop;
+ size_t start, stop;
/* Stack based */
int16_t totsh[3];
int16_t downsampled[(BLOCKL_MAX+120)>>1]; /* length 180 */
@@ -68,7 +70,7 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
int32_t corrmax[3];
int16_t corr16[3];
int16_t en16[3];
- int16_t lagmax[3];
+ size_t lagmax[3];
plc_pred = downsampled; /* Reuse memory since plc_pred[ENH_BLOCKL] and
downsampled are non overlapping */
@@ -99,7 +101,7 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
memmove(enh_period, &enh_period[new_blocks],
(ENH_NBLOCKS_TOT - new_blocks) * sizeof(*enh_period));
- k = WebRtcSpl_DownsampleFast(
+ WebRtcSpl_DownsampleFast(
enh_buf+ENH_BUFL-inLen, /* Input samples */
inLen + ENH_BUFL_FILTEROVERHEAD,
downsampled,
@@ -131,11 +133,9 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
for (i=0;i<2;i++) {
lagmax[i] = WebRtcSpl_MaxIndexW32(corr32, 50);
corrmax[i] = corr32[lagmax[i]];
- start = lagmax[i] - 2;
- stop = lagmax[i] + 2;
- start = WEBRTC_SPL_MAX(0, start);
- stop = WEBRTC_SPL_MIN(49, stop);
- for (k=start; k<=stop; k++) {
+ start = WEBRTC_SPL_MAX(2, lagmax[i]) - 2;
+ stop = WEBRTC_SPL_MIN(47, lagmax[i]) + 2;
+ for (k = start; k <= stop; k++) {
corr32[k] = 0;
}
}
@@ -145,8 +145,8 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
/* Calculate normalized corr^2 and ener */
for (i=0;i<3;i++) {
corrSh = 15-WebRtcSpl_GetSizeInBits(corrmax[i]);
- ener = WebRtcSpl_DotProductWithScale(&regressor[-lagmax[i]],
- &regressor[-lagmax[i]],
+ ener = WebRtcSpl_DotProductWithScale(regressor - lagmax[i],
+ regressor - lagmax[i],
ENH_BLOCKL_HALF, shifts);
enerSh = 15-WebRtcSpl_GetSizeInBits(ener);
corr16[i] = (int16_t)WEBRTC_SPL_SHIFT_W32(corrmax[i], corrSh);
@@ -171,10 +171,10 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
}
}
- lag = (size_t)(lagmax[ind] + 10);
+ lag = lagmax[ind] + 10;
/* Store the estimated lag in the non-downsampled domain */
- enh_period[ENH_NBLOCKS_TOT - new_blocks + iblock] = (int16_t)(lag * 8);
+ enh_period[ENH_NBLOCKS_TOT - new_blocks + iblock] = lag * 8;
/* Store the estimated lag for backward PLC */
if (iLBCdec_inst->prev_enh_pl==1) {
@@ -368,9 +368,9 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
WebRtcIlbcfix_Enhancer(out + iblock * ENH_BLOCKL,
enh_buf,
ENH_BUFL,
- (int16_t)(iblock * ENH_BLOCKL + startPos),
+ iblock * ENH_BLOCKL + startPos,
enh_period,
- (int16_t*)WebRtcIlbcfix_kEnhPlocs, ENH_NBLOCKS_TOT);
+ WebRtcIlbcfix_kEnhPlocs, ENH_NBLOCKS_TOT);
}
return (lag);
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/frame_classify.c b/webrtc/modules/audio_coding/codecs/ilbc/frame_classify.c
index f442f6a285..48332808e4 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/frame_classify.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/frame_classify.c
@@ -82,7 +82,7 @@ size_t WebRtcIlbcfix_FrameClassify(
}
/* Extract the best choise of start state */
- pos = (size_t)WebRtcSpl_MaxIndexW32(ssqEn, iLBCenc_inst->nsub - 1) + 1;
+ pos = WebRtcSpl_MaxIndexW32(ssqEn, iLBCenc_inst->nsub - 1) + 1;
return(pos);
}
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.c b/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.c
index 66dfafbe7a..a98a96cdf1 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.c
@@ -27,72 +27,68 @@
void WebRtcIlbcfix_GetSyncSeq(
int16_t *idata, /* (i) original data */
- int16_t idatal, /* (i) dimension of data */
- int16_t centerStartPos, /* (i) where current block starts */
- int16_t *period, /* (i) rough-pitch-period array (Q-2) */
- int16_t *plocs, /* (i) where periods of period array are taken (Q-2) */
+ size_t idatal, /* (i) dimension of data */
+ size_t centerStartPos, /* (i) where current block starts */
+ size_t *period, /* (i) rough-pitch-period array (Q-2) */
+ const size_t *plocs, /* (i) where periods of period array are taken (Q-2) */
size_t periodl, /* (i) dimension period array */
- int16_t hl, /* (i) 2*hl+1 is the number of sequences */
+ size_t hl, /* (i) 2*hl+1 is the number of sequences */
int16_t *surround /* (i/o) The contribution from this sequence
summed with earlier contributions */
){
- size_t i;
- int16_t centerEndPos,q;
+ size_t i, centerEndPos, q;
/* Stack based */
- int16_t lagBlock[2*ENH_HL+1];
- int16_t blockStartPos[2*ENH_HL+1]; /* Defines the position to search around (Q2) */
- int16_t plocs2[ENH_PLOCSL];
+ size_t lagBlock[2 * ENH_HL + 1];
+ size_t blockStartPos[2 * ENH_HL + 1]; /* The position to search around (Q2) */
+ size_t plocs2[ENH_PLOCSL];
- centerEndPos=centerStartPos+ENH_BLOCKL-1;
+ centerEndPos = centerStartPos + ENH_BLOCKL - 1;
/* present (find predicted lag from this position) */
WebRtcIlbcfix_NearestNeighbor(lagBlock + hl,
plocs,
- (int16_t)(2 * (centerStartPos + centerEndPos)),
+ 2 * (centerStartPos + centerEndPos),
periodl);
- blockStartPos[hl] = (int16_t)(4 * centerStartPos);
+ blockStartPos[hl] = 4 * centerStartPos;
/* past (find predicted position and perform a refined
search to find the best sequence) */
- for(q=hl-1;q>=0;q--) {
- blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]];
-
- WebRtcIlbcfix_NearestNeighbor(
- lagBlock + q,
- plocs,
- (int16_t)(blockStartPos[q] + 4 * ENH_BLOCKL_HALF -
- period[lagBlock[q + 1]]),
- periodl);
-
- if (blockStartPos[q] - 4 * ENH_OVERHANG >= 0) {
-
- /* Find the best possible sequence in the 4 times upsampled
- domain around blockStartPos+q */
- WebRtcIlbcfix_Refiner(blockStartPos+q,idata,idatal,
- centerStartPos,blockStartPos[q],surround,WebRtcIlbcfix_kEnhWt[q]);
-
- } else {
- /* Don't add anything since this sequence would
- be outside the buffer */
- }
+ for (q = hl; q > 0; q--) {
+ size_t qq = q - 1;
+ size_t period_q = period[lagBlock[q]];
+ /* Stop if this sequence would be outside the buffer; that means all
+ further-past sequences would also be outside the buffer. */
+ if (blockStartPos[q] < period_q + (4 * ENH_OVERHANG))
+ break;
+ blockStartPos[qq] = blockStartPos[q] - period_q;
+
+ size_t value = blockStartPos[qq] + 4 * ENH_BLOCKL_HALF;
+ value = (value > period_q) ? (value - period_q) : 0;
+ WebRtcIlbcfix_NearestNeighbor(lagBlock + qq, plocs, value, periodl);
+
+ /* Find the best possible sequence in the 4 times upsampled
+ domain around blockStartPos+q */
+ WebRtcIlbcfix_Refiner(blockStartPos + qq, idata, idatal, centerStartPos,
+ blockStartPos[qq], surround,
+ WebRtcIlbcfix_kEnhWt[qq]);
}
/* future (find predicted position and perform a refined
search to find the best sequence) */
- for(i=0;i<periodl;i++) {
- plocs2[i]=(plocs[i]-period[i]);
+ for (i = 0; i < periodl; i++) {
+ plocs2[i] = plocs[i] - period[i];
}
- for (q = hl + 1; q <= (int16_t)(2 * hl); q++) {
+ for (q = hl + 1; q <= (2 * hl); q++) {
WebRtcIlbcfix_NearestNeighbor(
lagBlock + q,
plocs2,
- (int16_t)(blockStartPos[q - 1] + 4 * ENH_BLOCKL_HALF),
+ blockStartPos[q - 1] + 4 * ENH_BLOCKL_HALF,
periodl);
blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]];
@@ -101,11 +97,11 @@ void WebRtcIlbcfix_GetSyncSeq(
/* Find the best possible sequence in the 4 times upsampled
domain around blockStartPos+q */
- WebRtcIlbcfix_Refiner(blockStartPos+q, idata, idatal,
- centerStartPos,blockStartPos[q],surround,WebRtcIlbcfix_kEnhWt[2*hl-q]);
+ WebRtcIlbcfix_Refiner(blockStartPos + q, idata, idatal, centerStartPos,
+ blockStartPos[q], surround,
+ WebRtcIlbcfix_kEnhWt[2 * hl - q]);
- }
- else {
+ } else {
/* Don't add anything since this sequence would
be outside the buffer */
}
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.h b/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.h
index 5b59f98563..0e3b207753 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.h
+++ b/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.h
@@ -27,12 +27,12 @@
void WebRtcIlbcfix_GetSyncSeq(
int16_t *idata, /* (i) original data */
- int16_t idatal, /* (i) dimension of data */
- int16_t centerStartPos, /* (i) where current block starts */
- int16_t *period, /* (i) rough-pitch-period array (Q-2) */
- int16_t *plocs, /* (i) where periods of period array are taken (Q-2) */
+ size_t idatal, /* (i) dimension of data */
+ size_t centerStartPos, /* (i) where current block starts */
+ size_t *period, /* (i) rough-pitch-period array (Q-2) */
+ const size_t *plocs, /* (i) where periods of period array are taken (Q-2) */
size_t periodl, /* (i) dimension period array */
- int16_t hl, /* (i) 2*hl+1 is the number of sequences */
+ size_t hl, /* (i) 2*hl+1 is the number of sequences */
int16_t *surround /* (i/o) The contribution from this sequence
summed with earlier contributions */
);
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c b/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c
index b6cc240683..2b58abc4f9 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c
@@ -18,29 +18,18 @@
#include "defines.h"
-/*----------------------------------------------------------------*
- * Find index in array such that the array element with said
- * index is the element of said array closest to "value"
- * according to the squared-error criterion
- *---------------------------------------------------------------*/
-
-void WebRtcIlbcfix_NearestNeighbor(
- int16_t *index, /* (o) index of array element closest to value */
- int16_t *array, /* (i) data array (Q2) */
- int16_t value, /* (i) value (Q2) */
- size_t arlength /* (i) dimension of data array (==8) */
- ){
+void WebRtcIlbcfix_NearestNeighbor(size_t* index,
+ const size_t* array,
+ size_t value,
+ size_t arlength) {
size_t i;
- int16_t diff;
- /* Stack based */
- int32_t crit[8];
-
- /* Calculate square distance */
- for(i=0;i<arlength;i++){
- diff=array[i]-value;
- crit[i] = diff * diff;
+ size_t min_diff = (size_t)-1;
+ for (i = 0; i < arlength; i++) {
+ const size_t diff =
+ (array[i] < value) ? (value - array[i]) : (array[i] - value);
+ if (diff < min_diff) {
+ *index = i;
+ min_diff = diff;
+ }
}
-
- /* Find the minimum square distance */
- *index=WebRtcSpl_MinIndexW32(crit, arlength);
}
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.h b/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.h
index 4c7ed3e633..7d7fb6fccc 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.h
+++ b/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.h
@@ -24,14 +24,13 @@
/*----------------------------------------------------------------*
* Find index in array such that the array element with said
* index is the element of said array closest to "value"
- * according to the squared-error criterion
*---------------------------------------------------------------*/
void WebRtcIlbcfix_NearestNeighbor(
- int16_t *index, /* (o) index of array element closest to value */
- int16_t *array, /* (i) data array (Q2) */
- int16_t value, /* (i) value (Q2) */
- size_t arlength /* (i) dimension of data array (==8) */
+ size_t* index, /* (o) index of array element closest to value */
+ const size_t* array, /* (i) data array (Q2) */
+ size_t value, /* (i) value (Q2) */
+ size_t arlength /* (i) dimension of data array (==ENH_NBLOCKS_TOT) */
);
#endif
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/refiner.c b/webrtc/modules/audio_coding/codecs/ilbc/refiner.c
index 86df81c460..3c1265e5d5 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/refiner.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/refiner.c
@@ -30,18 +30,17 @@
*---------------------------------------------------------------*/
void WebRtcIlbcfix_Refiner(
- int16_t *updStartPos, /* (o) updated start point (Q-2) */
+ size_t *updStartPos, /* (o) updated start point (Q-2) */
int16_t *idata, /* (i) original data buffer */
- int16_t idatal, /* (i) dimension of idata */
- int16_t centerStartPos, /* (i) beginning center segment */
- int16_t estSegPos, /* (i) estimated beginning other segment (Q-2) */
+ size_t idatal, /* (i) dimension of idata */
+ size_t centerStartPos, /* (i) beginning center segment */
+ size_t estSegPos, /* (i) estimated beginning other segment (Q-2) */
int16_t *surround, /* (i/o) The contribution from this sequence
summed with earlier contributions */
int16_t gain /* (i) Gain to use for this sequence */
){
- int16_t estSegPosRounded,searchSegStartPos,searchSegEndPos;
- size_t corrdim,i;
- int16_t tloc,tloc2,st,en,fraction;
+ size_t estSegPosRounded, searchSegStartPos, searchSegEndPos, corrdim;
+ size_t tloc, tloc2, i;
int32_t maxtemp, scalefact;
int16_t *filtStatePtr, *polyPtr;
@@ -56,96 +55,86 @@ void WebRtcIlbcfix_Refiner(
estSegPosRounded = (estSegPos - 2) >> 2;
- searchSegStartPos=estSegPosRounded-ENH_SLOP;
+ searchSegStartPos =
+ (estSegPosRounded < ENH_SLOP) ? 0 : (estSegPosRounded - ENH_SLOP);
- if (searchSegStartPos<0) {
- searchSegStartPos=0;
+ searchSegEndPos = estSegPosRounded + ENH_SLOP;
+ if ((searchSegEndPos + ENH_BLOCKL) >= idatal) {
+ searchSegEndPos = idatal - ENH_BLOCKL - 1;
}
- searchSegEndPos=estSegPosRounded+ENH_SLOP;
- if(searchSegEndPos+ENH_BLOCKL >= idatal) {
- searchSegEndPos=idatal-ENH_BLOCKL-1;
- }
- corrdim=(size_t)(searchSegEndPos-searchSegStartPos+1);
+ corrdim = searchSegEndPos + 1 - searchSegStartPos;
/* compute upsampled correlation and find
location of max */
- WebRtcIlbcfix_MyCorr(corrVecTemp,idata+searchSegStartPos,
- corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL);
+ WebRtcIlbcfix_MyCorr(corrVecTemp, idata + searchSegStartPos,
+ corrdim + ENH_BLOCKL - 1, idata + centerStartPos,
+ ENH_BLOCKL);
/* Calculate the rescaling factor for the correlation in order to
put the correlation in a int16_t vector instead */
- maxtemp=WebRtcSpl_MaxAbsValueW32(corrVecTemp, corrdim);
+ maxtemp = WebRtcSpl_MaxAbsValueW32(corrVecTemp, corrdim);
- scalefact=WebRtcSpl_GetSizeInBits(maxtemp)-15;
+ scalefact = WebRtcSpl_GetSizeInBits(maxtemp) - 15;
- if (scalefact>0) {
- for (i=0;i<corrdim;i++) {
+ if (scalefact > 0) {
+ for (i = 0; i < corrdim; i++) {
corrVec[i] = (int16_t)(corrVecTemp[i] >> scalefact);
}
} else {
- for (i=0;i<corrdim;i++) {
- corrVec[i]=(int16_t)corrVecTemp[i];
+ for (i = 0; i < corrdim; i++) {
+ corrVec[i] = (int16_t)corrVecTemp[i];
}
}
/* In order to guarantee that all values are initialized */
- for (i=corrdim;i<ENH_CORRDIM;i++) {
- corrVec[i]=0;
+ for (i = corrdim; i < ENH_CORRDIM; i++) {
+ corrVec[i] = 0;
}
/* Upsample the correlation */
- WebRtcIlbcfix_EnhUpsample(corrVecUps,corrVec);
+ WebRtcIlbcfix_EnhUpsample(corrVecUps, corrVec);
/* Find maximum */
- tloc=WebRtcSpl_MaxIndexW32(corrVecUps, ENH_UPS0 * corrdim);
+ tloc = WebRtcSpl_MaxIndexW32(corrVecUps, ENH_UPS0 * corrdim);
/* make vector can be upsampled without ever running outside
bounds */
- *updStartPos = (int16_t)(searchSegStartPos * 4) + tloc + 4;
+ *updStartPos = searchSegStartPos * 4 + tloc + 4;
tloc2 = (tloc + 3) >> 2;
- st=searchSegStartPos+tloc2-ENH_FL0;
-
/* initialize the vector to be filtered, stuff with zeros
when data is outside idata buffer */
- if(st<0){
- WebRtcSpl_MemSetW16(vect, 0, (size_t)(-st));
- WEBRTC_SPL_MEMCPY_W16(&vect[-st], idata, (ENH_VECTL+st));
- }
- else{
- en=st+ENH_VECTL;
-
- if(en>idatal){
- WEBRTC_SPL_MEMCPY_W16(vect, &idata[st],
- (ENH_VECTL-(en-idatal)));
- WebRtcSpl_MemSetW16(&vect[ENH_VECTL-(en-idatal)], 0,
- (size_t)(en-idatal));
- }
- else {
+ if (ENH_FL0 > (searchSegStartPos + tloc2)) {
+ const size_t st = ENH_FL0 - searchSegStartPos - tloc2;
+ WebRtcSpl_MemSetW16(vect, 0, st);
+ WEBRTC_SPL_MEMCPY_W16(&vect[st], idata, ENH_VECTL - st);
+ } else {
+ const size_t st = searchSegStartPos + tloc2 - ENH_FL0;
+ if ((st + ENH_VECTL) > idatal) {
+ const size_t en = st + ENH_VECTL - idatal;
+ WEBRTC_SPL_MEMCPY_W16(vect, &idata[st], ENH_VECTL - en);
+ WebRtcSpl_MemSetW16(&vect[ENH_VECTL - en], 0, en);
+ } else {
WEBRTC_SPL_MEMCPY_W16(vect, &idata[st], ENH_VECTL);
}
}
- /* Calculate which of the 4 fractions to use */
- fraction = (int16_t)(tloc2 * ENH_UPS0) - tloc;
/* compute the segment (this is actually a convolution) */
-
filtStatePtr = filt + 6;
- polyPtr = (int16_t*)WebRtcIlbcfix_kEnhPolyPhaser[fraction];
- for (i=0;i<7;i++) {
+ polyPtr = (int16_t*)WebRtcIlbcfix_kEnhPolyPhaser[tloc2 * ENH_UPS0 - tloc];
+ for (i = 0; i < 7; i++) {
*filtStatePtr-- = *polyPtr++;
}
- WebRtcSpl_FilterMAFastQ12(
- &vect[6], vect, filt,
- ENH_FLO_MULT2_PLUS1, ENH_BLOCKL);
+ WebRtcSpl_FilterMAFastQ12(&vect[6], vect, filt, ENH_FLO_MULT2_PLUS1,
+ ENH_BLOCKL);
- /* Add the contribution from this vector (scaled with gain) to the total surround vector */
- WebRtcSpl_AddAffineVectorToVector(
- surround, vect, gain,
- (int32_t)32768, 16, ENH_BLOCKL);
+ /* Add the contribution from this vector (scaled with gain) to the total
+ surround vector */
+ WebRtcSpl_AddAffineVectorToVector(surround, vect, gain, 32768, 16,
+ ENH_BLOCKL);
return;
}
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/refiner.h b/webrtc/modules/audio_coding/codecs/ilbc/refiner.h
index d13996152d..f8a2abc2d6 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/refiner.h
+++ b/webrtc/modules/audio_coding/codecs/ilbc/refiner.h
@@ -30,11 +30,11 @@
*---------------------------------------------------------------*/
void WebRtcIlbcfix_Refiner(
- int16_t *updStartPos, /* (o) updated start point (Q-2) */
+ size_t *updStartPos, /* (o) updated start point (Q-2) */
int16_t *idata, /* (i) original data buffer */
- int16_t idatal, /* (i) dimension of idata */
- int16_t centerStartPos, /* (i) beginning center segment */
- int16_t estSegPos, /* (i) estimated beginning other segment (Q-2) */
+ size_t idatal, /* (i) dimension of idata */
+ size_t centerStartPos, /* (i) beginning center segment */
+ size_t estSegPos, /* (i) estimated beginning other segment (Q-2) */
int16_t *surround, /* (i/o) The contribution from this sequence
summed with earlier contributions */
int16_t gain /* (i) Gain to use for this sequence */