From 84c89f378d23232054cdc9a16ac76f089bd6cba2 Mon Sep 17 00:00:00 2001 From: waker Date: Sun, 20 May 2012 21:46:00 +0200 Subject: added workaround for integer overflow when converting float32->int32 --- premix.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'premix.c') diff --git a/premix.c b/premix.c index 67b3b18a..e012df3f 100644 --- a/premix.c +++ b/premix.c @@ -369,7 +369,14 @@ static inline void pcm_write_samples_float_to_32 (const ddb_waveformat_t * restrict inputfmt, const char * restrict input, const ddb_waveformat_t * restrict outputfmt, char * restrict output, int nsamples, int * restrict channelmap, int outputsamplesize) { for (int s = 0; s < nsamples; s++) { for (int c = 0; c < outputfmt->channels; c++) { - int sample = (*((float*)(input + channelmap[c] * 4))) * (float)0x7fffffff; + float fsample = (*((float*)(input + channelmap[c] * 4))); + if (fsample > 0.999f) { + fsample = 0.999f; + } + else if (fsample < -0.999f) { + fsample = -0.999f; + } + int sample = fsample * (float)0x7fffffff; *((int32_t *)(output + 4 * c)) = sample; } input += 4 * inputfmt->channels; -- cgit v1.2.3