annotate src/aac/libfaad2/bits.c @ 681:1d8b08df98c3 trunk

[svn] - synchronise with FAAD 2.5
author nenolod
date Tue, 20 Feb 2007 04:37:37 -0800
parents 3da1b8942b8b
children e6c5fdae6e88
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
3 ** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
4 **
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
8 ** (at your option) any later version.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
9 **
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
13 ** GNU General Public License for more details.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
14 **
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
18 **
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
20 ** forbidden.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
21 **
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
22 ** Software using this code must display the following message visibly in or
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
23 ** on each copy of the software:
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
24 ** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Nero AG, www.nero.com"
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
25 ** in, for example, the about-box or help/startup screen.
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
26 **
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
27 ** Commercial non-GPL licensing of this software is possible.
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
28 ** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
29 **
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
30 ** $Id: bits.c,v 1.42 2006/07/07 12:35:24 sur Exp $
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
31 **/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
32
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
33 #include "common.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
34 #include "structs.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
35
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
36 #include <stdlib.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
37 #include "bits.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
38
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
39 /* initialize buffer, call once before first getbits or showbits */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
40 void faad_initbits(bitfile *ld, const void *_buffer, const uint32_t buffer_size)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
41 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
42 uint32_t tmp;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
43
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
44 if (ld == NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
45 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
46
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
47 // useless
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
48 //memset(ld, 0, sizeof(bitfile));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
49
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
50 if (buffer_size == 0 || _buffer == NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
51 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
52 ld->error = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
53 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
54 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
55
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
56 ld->buffer = _buffer;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
57
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
58 ld->buffer_size = buffer_size;
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
59 ld->bytes_left = buffer_size;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
60
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
61 if (ld->bytes_left >= 4)
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
62 {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
63 tmp = getdword((uint32_t*)ld->buffer);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
64 ld->bytes_left -= 4;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
65 } else {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
66 tmp = getdword_n((uint32_t*)ld->buffer, ld->bytes_left);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
67 ld->bytes_left = 0;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
68 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
69 ld->bufa = tmp;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
70
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
71 if (ld->bytes_left >= 4)
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
72 {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
73 tmp = getdword((uint32_t*)ld->buffer + 1);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
74 ld->bytes_left -= 4;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
75 } else {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
76 tmp = getdword_n((uint32_t*)ld->buffer + 1, ld->bytes_left);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
77 ld->bytes_left = 0;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
78 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
79 ld->bufb = tmp;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
80
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
81 ld->start = (uint32_t*)ld->buffer;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
82 ld->tail = ((uint32_t*)ld->buffer + 2);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
83
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
84 ld->bits_left = 32;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
85
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
86 ld->error = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
87 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
88
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
89 void faad_endbits(bitfile *ld)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
90 {
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
91 // void
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
92 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
93
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
94 uint32_t faad_get_processed_bits(bitfile *ld)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
95 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
96 return (uint32_t)(8 * (4*(ld->tail - ld->start) - 4) - (ld->bits_left));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
97 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
98
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
99 uint8_t faad_byte_align(bitfile *ld)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
100 {
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
101 int remainder = (32 - ld->bits_left) & 0x7;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
102
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
103 if (remainder)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
104 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
105 faad_flushbits(ld, 8 - remainder);
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
106 return (uint8_t)(8 - remainder);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
107 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
108 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
109 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
110
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
111 void faad_flushbits_ex(bitfile *ld, uint32_t bits)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
112 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
113 uint32_t tmp;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
114
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
115 ld->bufa = ld->bufb;
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
116 if (ld->bytes_left >= 4)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
117 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
118 tmp = getdword(ld->tail);
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
119 ld->bytes_left -= 4;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
120 } else {
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
121 tmp = getdword_n(ld->tail, ld->bytes_left);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
122 ld->bytes_left = 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
123 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
124 ld->bufb = tmp;
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
125 ld->tail++;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
126 ld->bits_left += (32 - bits);
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
127 //ld->bytes_left -= 4;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
128 // if (ld->bytes_left == 0)
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
129 // ld->no_more_reading = 1;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
130 // if (ld->bytes_left < 0)
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
131 // ld->error = 1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
132 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
133
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
134 /* rewind to beginning */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
135 void faad_rewindbits(bitfile *ld)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
136 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
137 uint32_t tmp;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
138
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
139 ld->bytes_left = ld->buffer_size;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
140
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
141 if (ld->bytes_left >= 4)
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
142 {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
143 tmp = getdword((uint32_t*)&ld->start[0]);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
144 ld->bytes_left -= 4;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
145 } else {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
146 tmp = getdword_n((uint32_t*)&ld->start[0], ld->bytes_left);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
147 ld->bytes_left = 0;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
148 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
149 ld->bufa = tmp;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
150
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
151 if (ld->bytes_left >= 4)
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
152 {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
153 tmp = getdword((uint32_t*)&ld->start[1]);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
154 ld->bytes_left -= 4;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
155 } else {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
156 tmp = getdword_n((uint32_t*)&ld->start[1], ld->bytes_left);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
157 ld->bytes_left = 0;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
158 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
159 ld->bufb = tmp;
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
160
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
161 ld->bits_left = 32;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
162 ld->tail = &ld->start[2];
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
163 }
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
164
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
165 /* reset to a certain point */
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
166 void faad_resetbits(bitfile *ld, int bits)
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
167 {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
168 uint32_t tmp;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
169 int words = bits >> 5;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
170 int remainder = bits & 0x1F;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
171
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
172 ld->bytes_left = ld->buffer_size - words*4;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
173
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
174 if (ld->bytes_left >= 4)
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
175 {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
176 tmp = getdword(&ld->start[words]);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
177 ld->bytes_left -= 4;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
178 } else {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
179 tmp = getdword_n(&ld->start[words], ld->bytes_left);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
180 ld->bytes_left = 0;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
181 }
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
182 ld->bufa = tmp;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
183
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
184 if (ld->bytes_left >= 4)
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
185 {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
186 tmp = getdword(&ld->start[words+1]);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
187 ld->bytes_left -= 4;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
188 } else {
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
189 tmp = getdword_n(&ld->start[words+1], ld->bytes_left);
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
190 ld->bytes_left = 0;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
191 }
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
192 ld->bufb = tmp;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
193
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
194 ld->bits_left = 32 - remainder;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
195 ld->tail = &ld->start[words+2];
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
196
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
197 /* recheck for reading too many bytes */
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
198 ld->error = 0;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
199 // if (ld->bytes_left == 0)
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
200 // ld->no_more_reading = 1;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
201 // if (ld->bytes_left < 0)
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
202 // ld->error = 1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
203 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
204
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
205 uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
206 DEBUGDEC)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
207 {
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
208 int i;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
209 unsigned int temp;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
210 int bytes = bits >> 3;
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
211 int remainder = bits & 0x7;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
212
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
213 uint8_t *buffer = (uint8_t*)faad_malloc((bytes+1)*sizeof(uint8_t));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
214
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
215 for (i = 0; i < bytes; i++)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
216 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
217 buffer[i] = (uint8_t)faad_getbits(ld, 8 DEBUGVAR(print,var,dbg));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
218 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
219
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
220 if (remainder)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
221 {
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
222 temp = faad_getbits(ld, remainder DEBUGVAR(print,var,dbg)) << (8-remainder);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
223
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
224 buffer[bytes] = (uint8_t)temp;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
225 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
226
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
227 return buffer;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
228 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
229
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
230 #ifdef DRM
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
231 /* return the original data buffer */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
232 void *faad_origbitbuffer(bitfile *ld)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
233 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
234 return (void*)ld->start;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
235 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
236
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
237 /* return the original data buffer size */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
238 uint32_t faad_origbitbuffer_size(bitfile *ld)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
239 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
240 return ld->buffer_size;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
241 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
242 #endif
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
243
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
244 /* reversed bit reading routines, used for RVLC and HCR */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
245 void faad_initbits_rev(bitfile *ld, void *buffer,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
246 uint32_t bits_in_buffer)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
247 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
248 uint32_t tmp;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
249 int32_t index;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
250
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
251 ld->buffer_size = bit2byte(bits_in_buffer);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
252
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
253 index = (bits_in_buffer+31)/32 - 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
254
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
255 ld->start = (uint32_t*)buffer + index - 2;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
256
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
257 tmp = getdword((uint32_t*)buffer + index);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
258 ld->bufa = tmp;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
259
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
260 tmp = getdword((uint32_t*)buffer + index - 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
261 ld->bufb = tmp;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
262
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
263 ld->tail = (uint32_t*)buffer + index;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
264
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
265 ld->bits_left = bits_in_buffer % 32;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
266 if (ld->bits_left == 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
267 ld->bits_left = 32;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
268
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
269 ld->bytes_left = ld->buffer_size;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
270 ld->error = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
271 }
681
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
272
1d8b08df98c3 [svn] - synchronise with FAAD 2.5
nenolod
parents: 12
diff changeset
273 /* EOF */