diff options
author | Siarhei Siamashka <siarhei.siamashka@nokia.com> | 2008-12-17 22:32:11 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2008-12-18 23:46:05 +0100 |
commit | 91a3fc0c35014d43da84700204178ef594746b1f (patch) | |
tree | 01b00dafe69f1c215ce6667039b6a4ee7846c593 | |
parent | 037a47214cf85251ea61c611b1aaf1d73b772ce3 (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.
-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]); |