summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiarhei Siamashka <siarhei.siamashka@nokia.com>2008-12-17 22:32:11 +0200
committerMarcel Holtmann <marcel@holtmann.org>2012-07-29 19:48:27 -0700
commit83bbf018cda76ce780a0af013499760a3c37c087 (patch)
treee955076463ecf9595a46014bb8ea1a14eb228bce
parent24c059a3c52ae349c1159cc8f71cd461aedfab86 (diff)
downloadsbc-83bbf018cda76ce780a0af013499760a3c37c087.tar.gz
sbc: 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.
-rw-r--r--sbc/sbc.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/sbc/sbc.c b/sbc/sbc.c
index c495a75..f766642 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]);