diff options
author | Siarhei Siamashka <siarhei.siamashka@nokia.com> | 2008-12-17 22:32:11 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2012-07-29 19:48:27 -0700 |
commit | 83bbf018cda76ce780a0af013499760a3c37c087 (patch) | |
tree | e955076463ecf9595a46014bb8ea1a14eb228bce | |
parent | 24c059a3c52ae349c1159cc8f71cd461aedfab86 (diff) | |
download | sbc-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.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -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]); |