From 91a3fc0c35014d43da84700204178ef594746b1f Mon Sep 17 00:00:00 2001 From: Siarhei Siamashka Date: Wed, 17 Dec 2008 22:32:11 +0200 Subject: Fix for overflow bug in SBC quantization code The result of multiplication does not always fit into 32-bits. Using 64-bit calculations helps to avoid overflows and sound quality problems in encoded audio. Overflows are more likely to show up when using high values for bitpool setting. --- sbc/sbc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sbc') diff --git a/sbc/sbc.c b/sbc/sbc.c index c495a75c..f766642e 100644 --- a/sbc/sbc.c +++ b/sbc/sbc.c @@ -1104,7 +1104,7 @@ static int sbc_pack_frame(uint8_t *data, struct sbc_frame *frame, size_t len) for (sb = 0; sb < frame->subbands; sb++) { if (levels[ch][sb] > 0) { audio_sample = - (uint16_t) ((((frame->sb_sample_f[blk][ch][sb]*levels[ch][sb]) >> + (uint16_t) (((((int64_t)frame->sb_sample_f[blk][ch][sb]*levels[ch][sb]) >> (frame->scale_factor[ch][sb] + 1)) + levels[ch][sb]) >> 1); PUT_BITS(audio_sample & levels[ch][sb], bits[ch][sb]); -- cgit