summaryrefslogtreecommitdiffstats
path: root/sbc
diff options
context:
space:
mode:
authorSiarhei Siamashka <siarhei.siamashka@nokia.com>2008-12-17 22:32:11 +0200
committerMarcel Holtmann <marcel@holtmann.org>2008-12-18 23:46:05 +0100
commit91a3fc0c35014d43da84700204178ef594746b1f (patch)
tree01b00dafe69f1c215ce6667039b6a4ee7846c593 /sbc
parent037a47214cf85251ea61c611b1aaf1d73b772ce3 (diff)
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.
Diffstat (limited to 'sbc')
-rw-r--r--sbc/sbc.c2
1 files changed, 1 insertions, 1 deletions
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]);