Skip to content

Commit 8a9980f

Browse files
committed
Better intensity_stereo() fixed-point accuracy
1 parent 866d860 commit 8a9980f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

celt/bands.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,15 @@ static void intensity_stereo(const CELTMode *m, celt_norm * OPUS_RESTRICT X, con
389389
left = VSHR32(bandE[i],shift);
390390
right = VSHR32(bandE[i+m->nbEBands],shift);
391391
norm = EPSILON + celt_sqrt(EPSILON+MULT16_16(left,left)+MULT16_16(right,right));
392-
a1 = DIV32_16(SHL32(EXTEND32(left),14),norm);
393-
a2 = DIV32_16(SHL32(EXTEND32(right),14),norm);
392+
#ifdef FIXED_POINT
393+
left = MIN32(left, norm-1);
394+
right = MIN32(right, norm-1);
395+
#endif
396+
a1 = DIV32_16(SHL32(EXTEND32(left),15),norm);
397+
a2 = DIV32_16(SHL32(EXTEND32(right),15),norm);
394398
for (j=0;j<N;j++)
395399
{
396-
opus_val16 r, l;
397-
l = EXTRACT16(PSHR32(X[j], NORM_SHIFT-14));
398-
r = EXTRACT16(PSHR32(Y[j], NORM_SHIFT-14));
399-
X[j] = PSHR32(MAC16_16(MULT16_16(a1, l), a2, r), 28-NORM_SHIFT);
400+
X[j] = ADD32(MULT16_32_Q15(a1, X[j]), MULT16_32_Q15(a2, Y[j]));
400401
/* Side is not encoded, no need to calculate */
401402
}
402403
}

0 commit comments

Comments
 (0)