The bug proved to be pretty elusive, but was found by Simon Hosie.
QUOTE
gain_analysis.c: 111:
#define MAX_SAMPLES_PER_WINDOW (size_t) (MAX_SAMP_FREQ * RMS_WINDOW_TIME)
and gain_analysis.c: 234
sampleWindow = (int) ceil (samplefreq * RMS_WINDOW_TIME);
sampleWindow may be > MAX_SAMPLES_PER_WINDOW because of the ceil() call.
Here's my fix:
#define MAX_SAMPLES_PER_WINDOW (size_t) (MAX_SAMP_FREQ * RMS_WINDOW_TIME + 1)
#define MAX_SAMPLES_PER_WINDOW (size_t) (MAX_SAMP_FREQ * RMS_WINDOW_TIME)
and gain_analysis.c: 234
sampleWindow = (int) ceil (samplefreq * RMS_WINDOW_TIME);
sampleWindow may be > MAX_SAMPLES_PER_WINDOW because of the ceil() call.
Here's my fix:
#define MAX_SAMPLES_PER_WINDOW (size_t) (MAX_SAMP_FREQ * RMS_WINDOW_TIME + 1)
The bug will be in all ReplayGain implementations, but may not show up due to the sensitivity to rounding. It may cause programs to randomly stop working when compiled with a different compiler or settings.