Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
576 | serge | 1 | /* |
2 | getbits |
||
3 | |||
4 | copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1 |
||
5 | see COPYING and AUTHORS files in distribution or http://mpg123.de |
||
6 | initially written by Michael Hipp |
||
7 | */ |
||
8 | |||
9 | #include "mpg123.h" |
||
10 | |||
11 | #if 0 |
||
12 | static void check_buffer_range(int size) |
||
13 | { |
||
14 | int pos = (bsi.wordpointer-bsbuf) + (size>>3); |
||
15 | |||
16 | if( pos >= fsizeold) { |
||
17 | fprintf(stderr,"Pointer out of range (%d,%d)!\n",pos,fsizeold); |
||
18 | } |
||
19 | } |
||
20 | #endif |
||
21 | |||
22 | void backbits(int number_of_bits) |
||
23 | { |
||
24 | bsi.bitindex -= number_of_bits; |
||
25 | bsi.wordpointer += (bsi.bitindex>>3); |
||
26 | bsi.bitindex &= 0x7; |
||
27 | } |
||
28 | |||
29 | int getbitoffset(void) |
||
30 | { |
||
31 | return (-bsi.bitindex)&0x7; |
||
32 | } |
||
33 | |||
34 | int getbyte(void) |
||
35 | { |
||
36 | #ifdef DEBUG_GETBITS |
||
37 | if(bsi.bitindex) |
||
38 | fprintf(stderr,"getbyte called unsynched!\n"); |
||
39 | #endif |
||
40 | return *bsi.wordpointer++; |
||
41 | } |
||
42 | |||
43 | unsigned int getbits(int number_of_bits) |
||
44 | { |
||
45 | unsigned long rval; |
||
46 | |||
47 | #ifdef DEBUG_GETBITS |
||
48 | fprintf(stderr,"g%d",number_of_bits); |
||
49 | #endif |
||
50 | |||
51 | if(!number_of_bits) |
||
52 | return 0; |
||
53 | |||
54 | #if 0 |
||
55 | check_buffer_range(number_of_bits+bsi.bitindex); |
||
56 | #endif |
||
57 | |||
58 | { |
||
59 | rval = bsi.wordpointer[0]; |
||
60 | rval <<= 8; |
||
61 | rval |= bsi.wordpointer[1]; |
||
62 | rval <<= 8; |
||
63 | rval |= bsi.wordpointer[2]; |
||
64 | |||
65 | rval <<= bsi.bitindex; |
||
66 | rval &= 0xffffff; |
||
67 | |||
68 | bsi.bitindex += number_of_bits; |
||
69 | |||
70 | rval >>= (24-number_of_bits); |
||
71 | |||
72 | bsi.wordpointer += (bsi.bitindex>>3); |
||
73 | bsi.bitindex &= 7; |
||
74 | } |
||
75 | |||
76 | #ifdef DEBUG_GETBITS |
||
77 | fprintf(stderr,":%x ",rval); |
||
78 | #endif |
||
79 | |||
80 | return rval; |
||
81 | } |
||
82 | |||
83 | unsigned int getbits_fast(int number_of_bits) |
||
84 | { |
||
85 | unsigned int rval; |
||
86 | #ifdef DEBUG_GETBITS |
||
87 | fprintf(stderr,"g%d",number_of_bits); |
||
88 | #endif |
||
89 | |||
90 | #if 0 |
||
91 | check_buffer_range(number_of_bits+bsi.bitindex); |
||
92 | #endif |
||
93 | |||
94 | rval = (unsigned char) (bsi.wordpointer[0] << bsi.bitindex); |
||
95 | rval |= ((unsigned int) bsi.wordpointer[1]< |
||
96 | rval <<= number_of_bits; |
||
97 | rval >>= 8; |
||
98 | |||
99 | bsi.bitindex += number_of_bits; |
||
100 | |||
101 | bsi.wordpointer += (bsi.bitindex>>3); |
||
102 | bsi.bitindex &= 7; |
||
103 | |||
104 | #ifdef DEBUG_GETBITS |
||
105 | fprintf(stderr,":%x ",rval); |
||
106 | #endif |
||
107 | return rval; |
||
108 | } |
||
109 | |||
110 | unsigned int get1bit(void) |
||
111 | { |
||
112 | unsigned char rval; |
||
113 | |||
114 | #ifdef DEBUG_GETBITS |
||
115 | fprintf(stderr,"g%d",1); |
||
116 | #endif |
||
117 | |||
118 | #if 0 |
||
119 | check_buffer_range(1+bsi.bitindex); |
||
120 | #endif |
||
121 | |||
122 | rval = *bsi.wordpointer << bsi.bitindex; |
||
123 | |||
124 | bsi.bitindex++; |
||
125 | bsi.wordpointer += (bsi.bitindex>>3); |
||
126 | bsi.bitindex &= 7; |
||
127 | |||
128 | #ifdef DEBUG_GETBITS |
||
129 | fprintf(stderr,":%d ",rval>>7); |
||
130 | #endif |
||
131 | |||
132 | return rval>>7; |
||
133 | }><>=><=> |
||
134 |