From d87b2319b09acaddabda9706d742b68d98ea2669 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Tue, 6 Oct 2015 20:01:24 +1100 Subject: [PATCH] src/sndfile.c: Fix SFC_SET_SCALE_FLOAT_INT_READ Before this fix it was possible for a the float/double to short/int conversion to cause wrap-around distortion. --- src/sndfile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sndfile.c b/src/sndfile.c index ff437e02..cc74f97d 100644 --- a/src/sndfile.c +++ b/src/sndfile.c @@ -964,7 +964,8 @@ sf_command (SNDFILE *sndfile, int command, void *data, int datasize) psf->float_int_mult = (datasize != 0) ? SF_TRUE : SF_FALSE ; if (psf->float_int_mult && psf->float_max < 0.0) - psf->float_max = psf_calc_signal_max (psf, SF_FALSE) ; + /* Scale to prevent wrap-around distortion. */ + psf->float_max = (32768.0 / 32767.0) * psf_calc_signal_max (psf, SF_FALSE) ; return old_value ; case SFC_SET_SCALE_INT_FLOAT_WRITE :