diff options
Diffstat (limited to 'sbc/sbc.c')
-rw-r--r-- | sbc/sbc.c | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -1162,20 +1162,21 @@ static int sbc_pack_frame(uint8_t *data, struct sbc_frame *frame, size_t len) audio_sample = 0; if (bits[ch][sb] != 0) { + audio_sample <<= 16 - bits[ch][sb]; for (bit = 0; bit < bits[ch][sb]; bit++) { - int b; /* A bit */ - if (produced % 8 == 0) - data[produced >> 3] = 0; - b = ((audio_sample) >> - (bits[ch][sb] - bit - 1)) & 0x01; - data[produced >> 3] |= b << (7 - (produced % 8)); + data[produced >> 3] <<= 1; + if(audio_sample & 0x8000) + data[produced >> 3] |= 0x1; + audio_sample <<= 1; produced++; } } } } } - + /* align the last byte */ + if(produced % 8) data[produced >> 3] <<= 8 - (produced % 8); + return (produced + 7) >> 3; } |