OSDN Git Service

change inner loop bit packing to use shift-in-place instead of complex ops
authorBrad Midgley <bmidgley@xmission.com>
Fri, 30 Nov 2007 01:20:01 +0000 (01:20 +0000)
committerBrad Midgley <bmidgley@xmission.com>
Fri, 30 Nov 2007 01:20:01 +0000 (01:20 +0000)
sbc/sbc.c

index 904227b..a785c48 100644 (file)
--- a/sbc/sbc.c
+++ b/sbc/sbc.c
@@ -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;
 }