annotate libfaad2/bits.h @ 10725:e989150f8216

libfaad2 v2.0rc1 imported
author arpi
date Sat, 30 Aug 2003 22:30:28 +0000
parents
children 125a35fc47a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
25 ** $Id$
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
26 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
27
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 #ifndef __BITS_H__
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29 #define __BITS_H__
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 #ifdef __cplusplus
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 extern "C" {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include "analysis.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #ifdef ANALYSIS
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 #include <stdio.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 #define BYTE_NUMBIT 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 #define bit2byte(a) ((a+7)/BYTE_NUMBIT)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 typedef struct _bitfile
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 /* bit input */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 uint32_t bufa;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 uint32_t bufb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 uint32_t bits_left;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 uint32_t buffer_size; /* size of the buffer in bytes */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 uint32_t bytes_used;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 uint8_t no_more_reading;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52 uint8_t error;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 uint32_t *tail;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54 uint32_t *start;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 void *buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 } bitfile;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 #if defined (_WIN32) && !defined(_WIN32_WCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 #define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 #elif defined(LINUX) || defined(DJGPP)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 #define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 #define BSWAP(a) \
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 ((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 static uint32_t bitmask[] = {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 0x0, 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 0x7FFFFF, 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 0xFFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 void faad_initbits(bitfile *ld, void *buffer, uint32_t buffer_size);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 void faad_endbits(bitfile *ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 void faad_initbits_rev(bitfile *ld, void *buffer,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 uint32_t bits_in_buffer);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 uint8_t faad_byte_align(bitfile *ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 uint32_t faad_get_processed_bits(bitfile *ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 void faad_rewindbits(bitfile *ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 DEBUGDEC);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 /* circumvent memory alignment errors on ARM */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 static INLINE uint32_t getdword(void *mem)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 #ifdef ARM
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 uint32_t tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 ((uint8_t*)&tmp)[0] = ((uint8_t*)mem)[0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 ((uint8_t*)&tmp)[1] = ((uint8_t*)mem)[1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 ((uint8_t*)&tmp)[2] = ((uint8_t*)mem)[2];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 ((uint8_t*)&tmp)[3] = ((uint8_t*)mem)[3];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 return tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 return *(uint32_t*)mem;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 static INLINE uint32_t faad_showbits(bitfile *ld, uint32_t bits)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 if (bits <= ld->bits_left)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 return (ld->bufa >> (ld->bits_left - bits)) & bitmask[bits];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 bits -= ld->bits_left;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 return ((ld->bufa & bitmask[ld->bits_left]) << bits) | (ld->bufb >> (32 - bits));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 static INLINE void faad_flushbits(bitfile *ld, uint32_t bits)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 /* do nothing if error */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 if (ld->error != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 if (bits < ld->bits_left)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 ld->bits_left -= bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 uint32_t tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 ld->bufa = ld->bufb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 tmp = getdword(ld->tail);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 ld->tail++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 #ifndef ARCH_IS_BIG_ENDIAN
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 BSWAP(tmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 ld->bufb = tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 ld->bits_left += (32 - bits);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 ld->bytes_used += 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 if (ld->bytes_used == ld->buffer_size)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 ld->no_more_reading = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 if (ld->bytes_used > ld->buffer_size)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 ld->error = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 /* return next n bits (right adjusted) */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 static INLINE uint32_t faad_getbits(bitfile *ld, uint32_t n DEBUGDEC)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 uint32_t ret;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 if (ld->no_more_reading)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 if (n == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 ret = faad_showbits(ld, n);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 faad_flushbits(ld, n);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 #ifdef ANALYSIS
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 if (print)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 fprintf(stdout, "%4d %2d bits, val: %4d, variable: %d %s\n", dbg_count++, n, ret, var, dbg);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 return ret;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 static INLINE uint8_t faad_get1bit(bitfile *ld DEBUGDEC)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 uint8_t r;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 if (ld->bits_left == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 return (uint8_t)faad_getbits(ld, 1 DEBUGVAR(print,var,dbg));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 ld->bits_left--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 r = (uint8_t)((ld->bufa >> ld->bits_left) & 1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 return r;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176 /* reversed bitreading routines */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 static INLINE uint32_t faad_showbits_rev(bitfile *ld, uint32_t bits)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 uint32_t B = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 if (bits <= ld->bits_left)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 for (i = 0; i < bits; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 if (ld->bufa & (1 << (i + (32 - ld->bits_left))))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 B |= (1 << (bits - i - 1));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 return B;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 for (i = 0; i < ld->bits_left; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 if (ld->bufa & (1 << (i + (32 - ld->bits_left))))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 B |= (1 << (bits - i - 1));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 for (i = 0; i < bits - ld->bits_left; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 if (ld->bufb & (1 << (i + (32-ld->bits_left))))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 B |= (1 << (bits - ld->bits_left - i - 1));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 return B;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 static INLINE void faad_flushbits_rev(bitfile *ld, uint32_t bits)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 /* do nothing if error */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 if (ld->error != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 if (bits < ld->bits_left)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 ld->bits_left -= bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 uint32_t tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 ld->bufa = ld->bufb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 tmp = getdword(ld->start);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 #ifndef ARCH_IS_BIG_ENDIAN
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220 BSWAP(tmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 ld->bufb = tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 ld->start--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 ld->bits_left += (32 - bits);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 ld->bytes_used += 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 if (ld->bytes_used == ld->buffer_size)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 ld->no_more_reading = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 if (ld->bytes_used > ld->buffer_size)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 ld->error = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234 static INLINE uint32_t faad_getbits_rev(bitfile *ld, uint32_t n
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 DEBUGDEC)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 uint32_t ret;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 if (ld->no_more_reading)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 if (n == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 ret = faad_showbits_rev(ld, n);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246 faad_flushbits_rev(ld, n);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 #ifdef ANALYSIS
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 if (print)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 fprintf(stdout, "%4d %2d bits, val: %4d, variable: %d %s\n", dbg_count++, n, ret, var, dbg);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 return ret;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257 #ifdef __cplusplus
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 #endif