Replaces log2() with celt_log2() and fixes a potential divide-by-zero

This commit is contained in:
Jean-Marc Valin 2013-10-01 19:27:30 -04:00
parent 1ad6f6d557
commit 942fc816d1
3 changed files with 7 additions and 5 deletions

View file

@ -1179,7 +1179,7 @@ static int compute_vbr(const CELTMode *mode, AnalysisInfo *analysis, opus_int32
tonal_target = target + (opus_int32)((coded_bins<<BITRES)*1.2f*tonal);
if (pitch_change)
tonal_target += (opus_int32)((coded_bins<<BITRES)*.8f);
/*printf("%f %f ", st->analysis.tonality, tonal);*/
/*printf("%f %f ", analysis->tonality, tonal);*/
target = tonal_target;
}
#endif
@ -1543,7 +1543,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
opus_val32 mask_avg=0;
opus_val32 diff=0;
int count=0;
mask_end = st->lastCodedBands;
mask_end = IMAX(2,st->lastCodedBands);
for (c=0;c<C;c++)
{
for(i=0;i<mask_end;i++)

View file

@ -165,6 +165,7 @@ opus_val32 celt_sqrt(opus_val32 x);
opus_val16 celt_cos_norm(opus_val32 x);
/** Base-2 logarithm approximation (log2(x)). (Q14 input, Q10 output) */
static inline opus_val16 celt_log2(opus_val32 x)
{
int i;

View file

@ -227,6 +227,7 @@ void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *b
int pos[8] = {0};
int upsample;
int frame_size;
opus_val16 channel_offset;
opus_val32 bandE[21];
opus_val16 maskLogE[3][21];
VARDECL(opus_val32, in);
@ -293,7 +294,6 @@ void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *b
#if 0
for (i=0;i<21;i++)
printf("%f ", bandLogE[21*c+i]);
//#else
float sum=0;
for (i=0;i<21;i++)
sum += bandLogE[21*c+i];
@ -303,9 +303,10 @@ void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *b
}
for (i=0;i<21;i++)
maskLogE[1][i] = MIN32(maskLogE[0][i],maskLogE[2][i]);
channel_offset = HALF16(celt_log2(QCONST32(2.f,14)/(channels-1)));
for (c=0;c<3;c++)
for (i=0;i<21;i++)
maskLogE[c][i] += QCONST16(.5f, DB_SHIFT)*log2(2.f/(channels-1));
maskLogE[c][i] += channel_offset;
#if 0
for (c=0;c<3;c++)
{
@ -334,7 +335,7 @@ void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *b
float sum=0;
for (i=0;i<21;i++)
sum += bandLogE[21*c+i];
printf("%f ", sum/21);
printf("%f ", sum/(float)QCONST32(21.f, DB_SHIFT));
printf("\n");
#endif
}