diff options
-rw-r--r-- | sbc/sbc.c | 11 | ||||
-rw-r--r-- | sbc/sbc_tables.h | 6 |
2 files changed, 11 insertions, 6 deletions
@@ -383,7 +383,7 @@ static int sbc_unpack_frame(const uint8_t *data, struct sbc_frame *frame, int crc_pos = 0; int32_t temp; - int audio_sample; + uint32_t audio_sample; int ch, sb, blk, bit; /* channel, subband, block and bit standard counters */ int bits[2][8]; /* bits distribution */ @@ -494,6 +494,9 @@ static int sbc_unpack_frame(const uint8_t *data, struct sbc_frame *frame, for (ch = 0; ch < frame->channels; ch++) { for (sb = 0; sb < frame->subbands; sb++) { if (levels[ch][sb] > 0) { + uint32_t shift = + frame->scale_factor[ch][sb] + + 1 + SBCDEC_FIXED_EXTRA_BITS; audio_sample = 0; for (bit = 0; bit < bits[ch][sb]; bit++) { if (consumed > len * 8) @@ -505,9 +508,9 @@ static int sbc_unpack_frame(const uint8_t *data, struct sbc_frame *frame, consumed++; } - frame->sb_sample[blk][ch][sb] = - (((audio_sample << 1) | 1) << frame->scale_factor[ch][sb]) / - levels[ch][sb] - (1 << frame->scale_factor[ch][sb]); + frame->sb_sample[blk][ch][sb] = (int32_t) + (((((uint64_t) audio_sample << 1) | 1) << shift) / + levels[ch][sb]) - (1 << shift); } else frame->sb_sample[blk][ch][sb] = 0; } diff --git a/sbc/sbc_tables.h b/sbc/sbc_tables.h index 28c0d54..25e24e6 100644 --- a/sbc/sbc_tables.h +++ b/sbc/sbc_tables.h @@ -40,11 +40,13 @@ static const int sbc_offset8[4][8] = { { -4, 0, 0, 0, 0, 0, 1, 2 } }; +/* extra bits of precision for the synthesis filter input data */ +#define SBCDEC_FIXED_EXTRA_BITS 2 #define SS4(val) ASR(val, SCALE_SPROTO4_TBL) #define SS8(val) ASR(val, SCALE_SPROTO8_TBL) -#define SN4(val) ASR(val, SCALE_NPROTO4_TBL) -#define SN8(val) ASR(val, SCALE_NPROTO8_TBL) +#define SN4(val) ASR(val, SCALE_NPROTO4_TBL + 1 + SBCDEC_FIXED_EXTRA_BITS) +#define SN8(val) ASR(val, SCALE_NPROTO8_TBL + 1 + SBCDEC_FIXED_EXTRA_BITS) static const int32_t sbc_proto_4_40m0[] = { SS4(0x00000000), SS4(0xffa6982f), SS4(0xfba93848), SS4(0x0456c7b8), |