~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpg123_artsplugin/mpg123/getbits.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "mpg123.h"
 
2
#include "common.h"
 
3
 
 
4
void backbits(struct bitstream_info *bitbuf,int number_of_bits)
 
5
{
 
6
  bitbuf->bitindex    -= number_of_bits;
 
7
  bitbuf->wordpointer += (bitbuf->bitindex>>3);
 
8
  bitbuf->bitindex    &= 0x7;
 
9
}
 
10
 
 
11
int getbitoffset(struct bitstream_info *bitbuf) 
 
12
{
 
13
  return (-bitbuf->bitindex)&0x7;
 
14
}
 
15
 
 
16
int getbyte(struct bitstream_info *bitbuf)
 
17
{
 
18
#ifdef DEBUG_GETBITS
 
19
  if(bitbuf->bitindex) 
 
20
    fprintf(stderr,"getbyte called unsynched!\n");
 
21
#endif
 
22
  return *bitbuf->wordpointer++;
 
23
}
 
24
 
 
25
unsigned int getbits(struct bitstream_info *bitbuf,int number_of_bits)
 
26
{
 
27
  unsigned long rval;
 
28
 
 
29
#ifdef DEBUG_GETBITS
 
30
fprintf(stderr,"g%d",number_of_bits);
 
31
#endif
 
32
 
 
33
  if(!number_of_bits)
 
34
    return 0;
 
35
 
 
36
#if 0
 
37
   check_buffer_range(number_of_bits+bitbuf->bitindex);
 
38
#endif
 
39
 
 
40
  {
 
41
    rval = bitbuf->wordpointer[0];
 
42
    rval <<= 8;
 
43
    rval |= bitbuf->wordpointer[1];
 
44
    rval <<= 8;
 
45
    rval |= bitbuf->wordpointer[2];
 
46
 
 
47
    rval <<= bitbuf->bitindex;
 
48
    rval &= 0xffffff;
 
49
 
 
50
    bitbuf->bitindex += number_of_bits;
 
51
 
 
52
    rval >>= (24-number_of_bits);
 
53
 
 
54
    bitbuf->wordpointer += (bitbuf->bitindex>>3);
 
55
    bitbuf->bitindex &= 7;
 
56
  }
 
57
 
 
58
#ifdef DEBUG_GETBITS
 
59
fprintf(stderr,":%x ",rval);
 
60
#endif
 
61
 
 
62
  return rval;
 
63
}
 
64
 
 
65
unsigned int getbits_fast(struct bitstream_info *bitbuf,int number_of_bits)
 
66
{
 
67
  unsigned int rval;
 
68
#ifdef DEBUG_GETBITS
 
69
fprintf(stderr,"g%d",number_of_bits);
 
70
#endif
 
71
 
 
72
#if 0
 
73
   check_buffer_range(number_of_bits+bitbuf->bitindex);
 
74
#endif
 
75
 
 
76
  rval =  (unsigned char) (bitbuf->wordpointer[0] << bitbuf->bitindex);
 
77
  rval |= ((unsigned int) bitbuf->wordpointer[1]<<bitbuf->bitindex)>>8;
 
78
  rval <<= number_of_bits;
 
79
  rval >>= 8;
 
80
 
 
81
  bitbuf->bitindex += number_of_bits;
 
82
 
 
83
  bitbuf->wordpointer += (bitbuf->bitindex>>3);
 
84
  bitbuf->bitindex &= 7;
 
85
 
 
86
#ifdef DEBUG_GETBITS
 
87
fprintf(stderr,":%x ",rval);
 
88
#endif
 
89
  return rval;
 
90
}
 
91
 
 
92
unsigned int get1bit(struct bitstream_info *bitbuf)
 
93
{
 
94
  unsigned char rval;
 
95
 
 
96
#ifdef DEBUG_GETBITS
 
97
fprintf(stderr,"g%d",1);
 
98
#endif
 
99
 
 
100
#if 0
 
101
   check_buffer_range(1+bitbuf->bitindex);
 
102
#endif
 
103
 
 
104
  rval = *(bitbuf->wordpointer) << bitbuf->bitindex;
 
105
 
 
106
  bitbuf->bitindex++;
 
107
  bitbuf->wordpointer += (bitbuf->bitindex>>3);
 
108
  bitbuf->bitindex &= 7;
 
109
 
 
110
#ifdef DEBUG_GETBITS
 
111
fprintf(stderr,":%d ",rval>>7);
 
112
#endif
 
113
 
 
114
  return rval>>7;
 
115
}
 
116