diff options
author | waker <wakeroid@gmail.com> | 2012-05-20 21:46:00 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2012-05-20 21:46:00 +0200 |
commit | 84c89f378d23232054cdc9a16ac76f089bd6cba2 (patch) | |
tree | 95b2ce93cd2114ce0211e952ddc9deaf9edab2c9 /premix.c | |
parent | efe1eba51d98dd5bb81397b8b8094e89ccb7df80 (diff) |
added workaround for integer overflow when converting float32->int32
Diffstat (limited to 'premix.c')
-rw-r--r-- | premix.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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; |