1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
13 function: packing variable sized words into an octet stream
14 last mod: $Id: bitwise.c 7675 2004-09-01 00:34:39Z xiphmont $
16 ********************************************************************/
17 #if !defined(_bitwise_H)
18 # define _bitwise_H (1)
21 void theorapackB_reset(oggpack_buffer
*b
);
22 void theorapackB_readinit(oggpack_buffer
*b
,unsigned char *buf
,int bytes
);
23 /* Read in bits without advancing the bitptr; bits <= 32 */
24 static int theorapackB_look(oggpack_buffer
*b
,int bits
,long *_ret
);
25 int theorapackB_look1(oggpack_buffer
*b
,long *_ret
);
26 static void theorapackB_adv(oggpack_buffer
*b
,int bits
);
27 void theorapackB_adv1(oggpack_buffer
*b
);
29 int theorapackB_read(oggpack_buffer
*b
,int bits
,long *_ret
);
30 int theorapackB_read1(oggpack_buffer
*b
,long *_ret
);
31 long theorapackB_bytes(oggpack_buffer
*b
);
32 long theorapackB_bits(oggpack_buffer
*b
);
33 unsigned char *theorapackB_get_buffer(oggpack_buffer
*b
);
35 /*These two functions are only used in one place, and declaring them static so
36 they can be inlined saves considerable function call overhead.*/
38 /* Read in bits without advancing the bitptr; bits <= 32 */
39 static int theorapackB_look(oggpack_buffer
*b
,int bits
,long *_ret
){
44 if(b
->endbyte
+4>=b
->storage
){
45 /* not the main path */
46 if(b
->endbyte
>=b
->storage
){
50 /*If we have some bits left, but not enough, return the ones we have.*/
51 if((b
->storage
-b
->endbyte
)*8<bits
)bits
=(b
->storage
-b
->endbyte
)*8;
53 ret
=b
->ptr
[0]<<(24+b
->endbit
);
55 ret
|=b
->ptr
[1]<<(16+b
->endbit
);
57 ret
|=b
->ptr
[2]<<(8+b
->endbit
);
59 ret
|=b
->ptr
[3]<<(b
->endbit
);
60 if(bits
>32&&b
->endbit
)
61 ret
|=b
->ptr
[4]>>(8-b
->endbit
);
65 *_ret
=((ret
&0xffffffff)>>(m
>>1))>>((m
+1)>>1);
69 static void theorapackB_adv(oggpack_buffer
*b
,int bits
){