comparison liba52/bitstream.c @ 1072:68d0a38bd802 libavcodec

* sync with main liba52 sources
author kabi
date Tue, 18 Feb 2003 11:48:57 +0000
parents dd4f4c3d7171
children e101d1cffec6
comparison
equal deleted inserted replaced
1071:0a48dd404167 1072:68d0a38bd802
1 /* 1 /*
2 * bitstream.c 2 * bitstream.c
3 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org> 3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5 * 5 *
6 * This file is part of a52dec, a free ATSC A-52 stream decoder. 6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates. 7 * See http://liba52.sourceforge.net/ for updates.
8 * 8 *
19 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software 20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */ 22 */
23 23
24 #include "config.h"
25
26 #include <inttypes.h>
27
24 #include "a52.h" 28 #include "a52.h"
25 #include "a52_internal.h" 29 #include "a52_internal.h"
26 #include "bitstream.h" 30 #include "bitstream.h"
27 31
28 #define BUFFER_SIZE 4096 32 #define BUFFER_SIZE 4096
29 33
30 static uint32_t * buffer_start; 34 void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf)
31
32 uint32_t a52_bits_left;
33 uint32_t a52_current_word;
34
35 void a52_bitstream_set_ptr (uint8_t * buf)
36 { 35 {
37 int align; 36 int align;
38 37
39 align = (long)buf & 3; 38 align = (long)buf & 3;
40 buffer_start = (uint32_t *) (buf - align); 39 state->buffer_start = (uint32_t *) (buf - align);
41 a52_bits_left = 0; 40 state->bits_left = 0;
42 bitstream_get (align * 8); 41 state->current_word = 0;
42 bitstream_get (state, align * 8);
43 } 43 }
44 44
45 static inline void 45 static inline void bitstream_fill_current (a52_state_t * state)
46 bitstream_fill_current()
47 { 46 {
48 uint32_t tmp; 47 uint32_t tmp;
49 48
50 tmp = *(buffer_start++); 49 tmp = *(state->buffer_start++);
51 a52_current_word = swab32 (tmp); 50 state->current_word = swab32 (tmp);
52 } 51 }
53 52
54 /* 53 /*
55 * The fast paths for _get is in the 54 * The fast paths for _get is in the
56 * bitstream.h header file so it can be inlined. 55 * bitstream.h header file so it can be inlined.
58 * The "bottom half" of this routine is suffixed _bh 57 * The "bottom half" of this routine is suffixed _bh
59 * 58 *
60 * -ah 59 * -ah
61 */ 60 */
62 61
63 uint32_t 62 uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits)
64 a52_bitstream_get_bh(uint32_t num_bits)
65 { 63 {
66 uint32_t result; 64 uint32_t result;
67 65
68 num_bits -= a52_bits_left; 66 num_bits -= state->bits_left;
69 result = ((a52_current_word << (32 - a52_bits_left)) >> 67 result = ((state->current_word << (32 - state->bits_left)) >>
70 (32 - a52_bits_left)); 68 (32 - state->bits_left));
71 69
72 bitstream_fill_current(); 70 bitstream_fill_current (state);
73 71
74 if(num_bits != 0) 72 if (num_bits != 0)
75 result = (result << num_bits) | (a52_current_word >> (32 - num_bits)); 73 result = (result << num_bits) | (state->current_word >> (32 - num_bits));
76 74
77 a52_bits_left = 32 - num_bits; 75 state->bits_left = 32 - num_bits;
78 76
79 return result; 77 return result;
80 } 78 }
81 79
82 int32_t 80 int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits)
83 a52_bitstream_get_bh_2(uint32_t num_bits)
84 { 81 {
85 int32_t result; 82 int32_t result;
86 83
87 num_bits -= a52_bits_left; 84 num_bits -= state->bits_left;
88 result = ((((int32_t)a52_current_word) << (32 - a52_bits_left)) >> 85 result = ((((int32_t)state->current_word) << (32 - state->bits_left)) >>
89 (32 - a52_bits_left)); 86 (32 - state->bits_left));
90 87
91 bitstream_fill_current(); 88 bitstream_fill_current(state);
92 89
93 if(num_bits != 0) 90 if (num_bits != 0)
94 result = (result << num_bits) | (a52_current_word >> (32 - num_bits)); 91 result = (result << num_bits) | (state->current_word >> (32 - num_bits));
95 92
96 a52_bits_left = 32 - num_bits; 93 state->bits_left = 32 - num_bits;
97 94
98 return result; 95 return result;
99 } 96 }