Commit 20a2100d authored by Erik de Castro Lopo's avatar Erik de Castro Lopo

replaygain_synthesis.c: Fix a cppcheck warning

Cppcheck was incorrectly warning that `doubletmp` was being used
un-initialized. This was due to the fact that it was being used
and initialized in a pre-processor macro. Chaning the macro to
an inline function stops cppcheck from raising a warning.
parent f7cd466c
...@@ -223,20 +223,27 @@ void FLAC__replaygain_synthesis__init_dither_context(DitherContext *d, int bits, ...@@ -223,20 +223,27 @@ void FLAC__replaygain_synthesis__init_dither_context(DitherContext *d, int bits,
d->LastHistoryIndex = 0; d->LastHistoryIndex = 0;
} }
static inline int64_t
ROUND64 (DitherContext *d, double x)
{
union {
double d;
int64_t i;
} doubletmp;
doubletmp.d = x + d->Add + (int64_t)FLAC__I64L(0x001FFFFD80000000);
return doubletmp.i - (int64_t)FLAC__I64L(0x433FFFFD80000000);
}
/* /*
* the following is based on parts of wavegain.c * the following is based on parts of wavegain.c
*/ */
static FLAC__int64 dither_output_(DitherContext *d, FLAC__bool do_dithering, int shapingtype, int i, double Sum, int k) static int64_t dither_output_(DitherContext *d, FLAC__bool do_dithering, int shapingtype, int i, double Sum, int k)
{ {
union {
double d;
FLAC__int64 i;
} doubletmp;
double Sum2; double Sum2;
FLAC__int64 val; int64_t val;
#define ROUND64(x) ( doubletmp.d = (x) + d->Add + (FLAC__int64)FLAC__I64L(0x001FFFFD80000000), doubletmp.i - (FLAC__int64)FLAC__I64L(0x433FFFFD80000000) )
if(do_dithering) { if(do_dithering) {
if(shapingtype == 0) { if(shapingtype == 0) {
...@@ -244,21 +251,19 @@ static FLAC__int64 dither_output_(DitherContext *d, FLAC__bool do_dithering, int ...@@ -244,21 +251,19 @@ static FLAC__int64 dither_output_(DitherContext *d, FLAC__bool do_dithering, int
Sum2 = tmp - d->LastRandomNumber [k]; Sum2 = tmp - d->LastRandomNumber [k];
d->LastRandomNumber [k] = (int)tmp; d->LastRandomNumber [k] = (int)tmp;
Sum2 = Sum += Sum2; Sum2 = Sum += Sum2;
val = ROUND64(Sum2) & d->Mask; val = ROUND64(d, Sum2) & d->Mask;
} }
else { else {
Sum2 = random_triangular_(d->Dither) - scalar16_(d->DitherHistory[k], d->FilterCoeff + i); Sum2 = random_triangular_(d->Dither) - scalar16_(d->DitherHistory[k], d->FilterCoeff + i);
Sum += d->DitherHistory [k] [(-1-i)&15] = (float)Sum2; Sum += d->DitherHistory [k] [(-1-i)&15] = (float)Sum2;
Sum2 = Sum + scalar16_(d->ErrorHistory [k], d->FilterCoeff + i); Sum2 = Sum + scalar16_(d->ErrorHistory [k], d->FilterCoeff + i);
val = ROUND64(Sum2) & d->Mask; val = ROUND64(d, Sum2) & d->Mask;
d->ErrorHistory [k] [(-1-i)&15] = (float)(Sum - val); d->ErrorHistory [k] [(-1-i)&15] = (float)(Sum - val);
} }
return val; return val;
} }
else
return ROUND64(Sum);
#undef ROUND64 return ROUND64(d, Sum);
} }
#if 0 #if 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment