ReactOS  0.4.14-dev-50-g13bb5e2
getbits.h
Go to the documentation of this file.
1 /*
2  getbits
3 
4  copyright ?-2009 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.org
6  initially written by Michael Hipp
7 
8  All code is in the header to suggest/force inlining of these small often-used functions.
9  This indeed has some impact on performance.
10 */
11 
12 #ifndef _MPG123_GETBITS_H_
13 #define _MPG123_GETBITS_H_
14 
15 #include "mpg123lib_intern.h"
16 
17 #define backbits(fr,nob) ((void)( \
18  fr->bitindex -= nob, \
19  fr->wordpointer += (fr->bitindex>>3), \
20  fr->bitindex &= 0x7 ))
21 
22 #define getbitoffset(fr) ((-fr->bitindex)&0x7)
23 #define getbyte(fr) (*fr->wordpointer++)
24 
25 /* There is something wrong with that macro... the function below works also for the layer1 test case. */
26 #define macro_getbits(fr, nob) ( \
27  fr->ultmp = fr->wordpointer[0],\
28  fr->ultmp <<= 8, \
29  fr->ultmp |= fr->wordpointer[1], \
30  fr->ultmp <<= 8, \
31  fr->ultmp |= fr->wordpointer[2], \
32  fr->ultmp <<= fr->bitindex, \
33  fr->ultmp &= 0xffffff, \
34  fr->bitindex += nob, \
35  fr->ultmp >>= (24-nob), \
36  fr->wordpointer += (fr->bitindex>>3), \
37  fr->bitindex &= 7, \
38  fr->ultmp)
39 
40 static unsigned int getbits(mpg123_handle *fr, int number_of_bits)
41 {
42  unsigned long rval;
43 
44 #ifdef DEBUG_GETBITS
45 fprintf(stderr,"g%d",number_of_bits);
46 #endif
47  /* Safety catch until we got the nasty code fully figured out. */
48  /* No, that catch stays here, even if we think we got it figured out! */
49  if( (long)(fr->wordpointer-fr->bsbuf)*8
50  + fr->bitindex+number_of_bits > (long)fr->framesize*8 )
51  return 0;
52 /* This is actually slow: if(!number_of_bits)
53  return 0; */
54 
55 #if 0
56  check_buffer_range(number_of_bits+fr->bitindex);
57 #endif
58 
59  {
60  rval = fr->wordpointer[0];
61  rval <<= 8;
62  rval |= fr->wordpointer[1];
63  rval <<= 8;
64  rval |= fr->wordpointer[2];
65 
66  rval <<= fr->bitindex;
67  rval &= 0xffffff;
68 
69  fr->bitindex += number_of_bits;
70 
71  rval >>= (24-number_of_bits);
72 
73  fr->wordpointer += (fr->bitindex>>3);
74  fr->bitindex &= 7;
75  }
76 
77 #ifdef DEBUG_GETBITS
78 fprintf(stderr,":%lx\n",rval);
79 #endif
80 
81  return rval;
82 }
83 
84 
85 #define skipbits(fr, nob) fr->ultmp = ( \
86  fr->ultmp = fr->wordpointer[0], fr->ultmp <<= 8, fr->ultmp |= fr->wordpointer[1], \
87  fr->ultmp <<= 8, fr->ultmp |= fr->wordpointer[2], fr->ultmp <<= fr->bitindex, \
88  fr->ultmp &= 0xffffff, fr->bitindex += nob, \
89  fr->ultmp >>= (24-nob), fr->wordpointer += (fr->bitindex>>3), \
90  fr->bitindex &= 7 )
91 
92 #define getbits_fast(fr, nob) ( \
93  fr->ultmp = (unsigned char) (fr->wordpointer[0] << fr->bitindex), \
94  fr->ultmp |= ((unsigned long) fr->wordpointer[1]<<fr->bitindex)>>8, \
95  fr->ultmp <<= nob, fr->ultmp >>= 8, \
96  fr->bitindex += nob, fr->wordpointer += (fr->bitindex>>3), \
97  fr->bitindex &= 7, fr->ultmp )
98 
99 #define get1bit(fr) ( \
100  fr->uctmp = *fr->wordpointer << fr->bitindex, fr->bitindex++, \
101  fr->wordpointer += (fr->bitindex>>3), fr->bitindex &= 7, fr->uctmp>>7 )
102 
103 
104 #endif
unsigned char * wordpointer
Definition: frame.h:227
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static unsigned int getbits(mpg123_handle *fr, int number_of_bits)
Definition: getbits.h:40
float rval
Definition: cylfrac.c:48
FILE * stderr
unsigned char * bsbuf
Definition: frame.h:252