Issue description

Bluez SBC (Sub-Band Codec) had presented some troubles involving sound quality in fixed point source code version, caused, probably, by overflow.

Basic tasks

  • Look for overflow point in source code. Loud volume input causes the encoder to overflow.
  • sbc_analyze_{four,eight} functions should be changed to move around pointers
  • sbc_encode() has the main loop "unrolled" in _sbc_analyze_{four,eight} to try to optimize it. It needs to be rolled up again.
  • Implement Dynamic Compression on encoder input to reduce overflow. It's a way to avoid it.

Overflow trouble

  • Decoder:

Atenuation point has been found and modified and some variables were modified to 64bits size.
A Dynamic Range Analysis revealed that to keep a high precision a 64-bit variable should be used

  • Encoder:

First effort: "heuristic" method. It is known that we can increase sound volume through scb_math (shifting), but we aren't sure if sound atenuation is done in that point yet.
Second effort: Dynamic range analysis was used to testify if fixed point variables are capable to represent the values correctly.

Pointers in sbc_analyze_() function

Function declaration:
static inline void _sbc_analyze_four(const int32_t in[40], int32_t out[4]) and
static inline void _sbc_analyze_eight(const int32_t in[80], int32_t out[8])

were moved to:
static inline void _sbc_analyze_four(const int32_t *in, int32_t *out)
static inline void _sbc_analyze_eight(const int32_t *in, int32_t *out)
respectively.

rolled/unrolled main loop

It was agreed that it's better keep the current approach.

  • Keep loop unrolled because (num_of_iterations)*(num_of_operations) isn't too large
  • Keep loop unrolled because the serial execution of loop iterations causes overhead. That is, it isn't tolerated any extra latency, intrinsical of rolled loops.

Dynamic Compression

After solving overflow problem, dynamic compression is not necessary anymore.

Testing

  • Sub-Band Codec has been tested only through self perception.
  • SBC works in N800 (only coding/decoding tested, no bluez stack).

Conclusion

  • Codec is finnshed. Decoder is very simple and isn't possible to improve decoding quality because decoder output is deterministic.
  • Encoder is determinist as well. There is no such place to implement better algorithms.
  • The coded can be 'optimizated' to run on some platforms (N800 - INdT current target)