/proc/self/cwd/libfaad/bits.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding |
3 | | ** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com |
4 | | ** |
5 | | ** This program is free software; you can redistribute it and/or modify |
6 | | ** it under the terms of the GNU General Public License as published by |
7 | | ** the Free Software Foundation; either version 2 of the License, or |
8 | | ** (at your option) any later version. |
9 | | ** |
10 | | ** This program is distributed in the hope that it will be useful, |
11 | | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | ** GNU General Public License for more details. |
14 | | ** |
15 | | ** You should have received a copy of the GNU General Public License |
16 | | ** along with this program; if not, write to the Free Software |
17 | | ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | | ** |
19 | | ** Any non-GPL usage of this software or parts of this software is strictly |
20 | | ** forbidden. |
21 | | ** |
22 | | ** The "appropriate copyright message" mentioned in section 2c of the GPLv2 |
23 | | ** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com" |
24 | | ** |
25 | | ** Commercial non-GPL licensing of this software is possible. |
26 | | ** For more info contact Nero AG through Mpeg4AAClicense@nero.com. |
27 | | ** |
28 | | ** $Id: bits.h,v 1.45 2007/11/01 12:33:29 menno Exp $ |
29 | | **/ |
30 | | |
31 | | #ifndef __BITS_H__ |
32 | | #define __BITS_H__ |
33 | | |
34 | | #ifdef __cplusplus |
35 | | extern "C" { |
36 | | #endif |
37 | | |
38 | | #include "analysis.h" |
39 | | #ifdef ANALYSIS |
40 | | #include <stdio.h> |
41 | | #endif |
42 | | |
43 | | #define BYTE_NUMBIT 8 |
44 | 0 | #define BYTE_NUMBIT_LD 3 |
45 | | //#define bit2byte(a) ((a+7)/BYTE_NUMBIT) |
46 | 0 | #define bit2byte(a) ((a+7)>>BYTE_NUMBIT_LD) |
47 | | |
48 | | typedef struct _bitfile |
49 | | { |
50 | | const void *buffer; |
51 | | uint32_t *tail; |
52 | | uint32_t *start; |
53 | | /* bit input */ |
54 | | uint32_t bufa; |
55 | | uint32_t bufb; |
56 | | uint32_t bits_left; |
57 | | uint32_t buffer_size; /* size of the buffer in bytes */ |
58 | | uint32_t bytes_left; |
59 | | uint8_t error; |
60 | | } bitfile; |
61 | | |
62 | | |
63 | | #if 0 |
64 | | static uint32_t const bitmask[] = { |
65 | | 0x0, 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF, |
66 | | 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF, |
67 | | 0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF, |
68 | | 0x7FFFFF, 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF, |
69 | | 0xFFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF |
70 | | /* added bitmask 32, correct?!?!?! */ |
71 | | , 0xFFFFFFFF |
72 | | }; |
73 | | #endif |
74 | | |
75 | | void faad_initbits(bitfile *ld, const void *buffer, const uint32_t buffer_size); |
76 | | void faad_endbits(bitfile *ld); |
77 | | #if 0 |
78 | | void faad_initbits_rev(bitfile *ld, void *buffer, |
79 | | uint32_t bits_in_buffer); |
80 | | #endif |
81 | | uint8_t faad_byte_align(bitfile *ld); |
82 | | uint32_t faad_get_processed_bits(bitfile *ld); |
83 | | void faad_flushbits_ex(bitfile *ld, uint32_t bits); |
84 | | #ifdef DRM |
85 | | void faad_rewindbits(bitfile *ld); |
86 | | #endif |
87 | | void faad_resetbits(bitfile *ld, uint32_t bits); |
88 | | uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits |
89 | | DEBUGDEC); |
90 | | #ifdef DRM |
91 | | void *faad_origbitbuffer(bitfile *ld); |
92 | | uint32_t faad_origbitbuffer_size(bitfile *ld); |
93 | | #endif |
94 | | |
95 | | /* circumvent memory alignment errors on ARM */ |
96 | | static INLINE uint32_t getdword(void *mem) |
97 | 2.37k | { |
98 | 2.37k | uint8_t* m8 = (uint8_t*)mem; |
99 | 2.37k | return (uint32_t)m8[3] | ((uint32_t)m8[2] << 8) | ((uint32_t)m8[1] << 16) | ((uint32_t)m8[0] << 24); |
100 | 2.37k | } Unexecuted instantiation: decoder.c:getdword Unexecuted instantiation: common.c:getdword Line | Count | Source | 97 | 2.37k | { | 98 | 2.37k | uint8_t* m8 = (uint8_t*)mem; | 99 | 2.37k | return (uint32_t)m8[3] | ((uint32_t)m8[2] << 8) | ((uint32_t)m8[1] << 16) | ((uint32_t)m8[0] << 24); | 100 | 2.37k | } |
Unexecuted instantiation: drc.c:getdword Unexecuted instantiation: filtbank.c:getdword Unexecuted instantiation: mdct.c:getdword Unexecuted instantiation: cfft.c:getdword Unexecuted instantiation: mp4.c:getdword Unexecuted instantiation: output.c:getdword Unexecuted instantiation: sbr_dec.c:getdword Unexecuted instantiation: ps_dec.c:getdword Unexecuted instantiation: sbr_hfadj.c:getdword Unexecuted instantiation: sbr_hfgen.c:getdword Unexecuted instantiation: sbr_fbt.c:getdword Unexecuted instantiation: sbr_qmf.c:getdword Unexecuted instantiation: syntax.c:getdword Unexecuted instantiation: specrec.c:getdword Unexecuted instantiation: ic_predict.c:getdword Unexecuted instantiation: lt_predict.c:getdword Unexecuted instantiation: pns.c:getdword Unexecuted instantiation: ms.c:getdword Unexecuted instantiation: is.c:getdword Unexecuted instantiation: sbr_syntax.c:getdword Unexecuted instantiation: sbr_huff.c:getdword Unexecuted instantiation: sbr_e_nf.c:getdword Unexecuted instantiation: sbr_tf_grid.c:getdword Unexecuted instantiation: ps_syntax.c:getdword Unexecuted instantiation: rvlc.c:getdword Unexecuted instantiation: hcr.c:getdword Unexecuted instantiation: huffman.c:getdword Unexecuted instantiation: pulse.c:getdword Unexecuted instantiation: tns.c:getdword |
101 | | |
102 | | static INLINE uint32_t faad_showbits(bitfile *ld, uint32_t bits) |
103 | 17.2k | { |
104 | 17.2k | if (bits <= ld->bits_left) |
105 | 16.4k | { |
106 | | //return (ld->bufa >> (ld->bits_left - bits)) & bitmask[bits]; |
107 | 16.4k | return (ld->bufa << (32 - ld->bits_left)) >> (32 - bits); |
108 | 16.4k | } |
109 | | |
110 | 789 | bits -= ld->bits_left; |
111 | | //return ((ld->bufa & bitmask[ld->bits_left]) << bits) | (ld->bufb >> (32 - bits)); |
112 | 789 | return ((ld->bufa & ((1u<<ld->bits_left)-1)) << bits) | (ld->bufb >> (32 - bits)); |
113 | 17.2k | } Unexecuted instantiation: decoder.c:faad_showbits Unexecuted instantiation: common.c:faad_showbits Unexecuted instantiation: bits.c:faad_showbits Unexecuted instantiation: drc.c:faad_showbits Unexecuted instantiation: filtbank.c:faad_showbits Unexecuted instantiation: mdct.c:faad_showbits Unexecuted instantiation: cfft.c:faad_showbits Line | Count | Source | 103 | 1.39k | { | 104 | 1.39k | if (bits <= ld->bits_left) | 105 | 1.31k | { | 106 | | //return (ld->bufa >> (ld->bits_left - bits)) & bitmask[bits]; | 107 | 1.31k | return (ld->bufa << (32 - ld->bits_left)) >> (32 - bits); | 108 | 1.31k | } | 109 | | | 110 | 81 | bits -= ld->bits_left; | 111 | | //return ((ld->bufa & bitmask[ld->bits_left]) << bits) | (ld->bufb >> (32 - bits)); | 112 | 81 | return ((ld->bufa & ((1u<<ld->bits_left)-1)) << bits) | (ld->bufb >> (32 - bits)); | 113 | 1.39k | } |
Unexecuted instantiation: output.c:faad_showbits Unexecuted instantiation: sbr_dec.c:faad_showbits Unexecuted instantiation: ps_dec.c:faad_showbits Unexecuted instantiation: sbr_hfadj.c:faad_showbits Unexecuted instantiation: sbr_hfgen.c:faad_showbits Unexecuted instantiation: sbr_fbt.c:faad_showbits Unexecuted instantiation: sbr_qmf.c:faad_showbits Line | Count | Source | 103 | 15.8k | { | 104 | 15.8k | if (bits <= ld->bits_left) | 105 | 15.1k | { | 106 | | //return (ld->bufa >> (ld->bits_left - bits)) & bitmask[bits]; | 107 | 15.1k | return (ld->bufa << (32 - ld->bits_left)) >> (32 - bits); | 108 | 15.1k | } | 109 | | | 110 | 708 | bits -= ld->bits_left; | 111 | | //return ((ld->bufa & bitmask[ld->bits_left]) << bits) | (ld->bufb >> (32 - bits)); | 112 | 708 | return ((ld->bufa & ((1u<<ld->bits_left)-1)) << bits) | (ld->bufb >> (32 - bits)); | 113 | 15.8k | } |
Unexecuted instantiation: specrec.c:faad_showbits Unexecuted instantiation: ic_predict.c:faad_showbits Unexecuted instantiation: lt_predict.c:faad_showbits Unexecuted instantiation: pns.c:faad_showbits Unexecuted instantiation: ms.c:faad_showbits Unexecuted instantiation: is.c:faad_showbits Unexecuted instantiation: sbr_syntax.c:faad_showbits Unexecuted instantiation: sbr_huff.c:faad_showbits Unexecuted instantiation: sbr_e_nf.c:faad_showbits Unexecuted instantiation: sbr_tf_grid.c:faad_showbits Unexecuted instantiation: ps_syntax.c:faad_showbits Unexecuted instantiation: rvlc.c:faad_showbits Unexecuted instantiation: hcr.c:faad_showbits Unexecuted instantiation: huffman.c:faad_showbits Unexecuted instantiation: pulse.c:faad_showbits Unexecuted instantiation: tns.c:faad_showbits |
114 | | |
115 | | static INLINE void faad_flushbits(bitfile *ld, uint32_t bits) |
116 | 17.4k | { |
117 | | /* do nothing if error */ |
118 | 17.4k | if (ld->error != 0) |
119 | 0 | return; |
120 | | |
121 | 17.4k | if (bits < ld->bits_left) |
122 | 13.9k | { |
123 | 13.9k | ld->bits_left -= bits; |
124 | 13.9k | } else { |
125 | 3.49k | faad_flushbits_ex(ld, bits); |
126 | 3.49k | } |
127 | 17.4k | } Unexecuted instantiation: decoder.c:faad_flushbits Unexecuted instantiation: common.c:faad_flushbits Line | Count | Source | 116 | 183 | { | 117 | | /* do nothing if error */ | 118 | 183 | if (ld->error != 0) | 119 | 0 | return; | 120 | | | 121 | 183 | if (bits < ld->bits_left) | 122 | 119 | { | 123 | 119 | ld->bits_left -= bits; | 124 | 119 | } else { | 125 | 64 | faad_flushbits_ex(ld, bits); | 126 | 64 | } | 127 | 183 | } |
Unexecuted instantiation: drc.c:faad_flushbits Unexecuted instantiation: filtbank.c:faad_flushbits Unexecuted instantiation: mdct.c:faad_flushbits Unexecuted instantiation: cfft.c:faad_flushbits Line | Count | Source | 116 | 1.39k | { | 117 | | /* do nothing if error */ | 118 | 1.39k | if (ld->error != 0) | 119 | 0 | return; | 120 | | | 121 | 1.39k | if (bits < ld->bits_left) | 122 | 1.31k | { | 123 | 1.31k | ld->bits_left -= bits; | 124 | 1.31k | } else { | 125 | 88 | faad_flushbits_ex(ld, bits); | 126 | 88 | } | 127 | 1.39k | } |
Unexecuted instantiation: output.c:faad_flushbits Unexecuted instantiation: sbr_dec.c:faad_flushbits Unexecuted instantiation: ps_dec.c:faad_flushbits Unexecuted instantiation: sbr_hfadj.c:faad_flushbits Unexecuted instantiation: sbr_hfgen.c:faad_flushbits Unexecuted instantiation: sbr_fbt.c:faad_flushbits Unexecuted instantiation: sbr_qmf.c:faad_flushbits Line | Count | Source | 116 | 15.8k | { | 117 | | /* do nothing if error */ | 118 | 15.8k | if (ld->error != 0) | 119 | 0 | return; | 120 | | | 121 | 15.8k | if (bits < ld->bits_left) | 122 | 12.5k | { | 123 | 12.5k | ld->bits_left -= bits; | 124 | 12.5k | } else { | 125 | 3.34k | faad_flushbits_ex(ld, bits); | 126 | 3.34k | } | 127 | 15.8k | } |
Unexecuted instantiation: specrec.c:faad_flushbits Unexecuted instantiation: ic_predict.c:faad_flushbits Unexecuted instantiation: lt_predict.c:faad_flushbits Unexecuted instantiation: pns.c:faad_flushbits Unexecuted instantiation: ms.c:faad_flushbits Unexecuted instantiation: is.c:faad_flushbits Unexecuted instantiation: sbr_syntax.c:faad_flushbits Unexecuted instantiation: sbr_huff.c:faad_flushbits Unexecuted instantiation: sbr_e_nf.c:faad_flushbits Unexecuted instantiation: sbr_tf_grid.c:faad_flushbits Unexecuted instantiation: ps_syntax.c:faad_flushbits Unexecuted instantiation: rvlc.c:faad_flushbits Unexecuted instantiation: hcr.c:faad_flushbits Unexecuted instantiation: huffman.c:faad_flushbits Unexecuted instantiation: pulse.c:faad_flushbits Unexecuted instantiation: tns.c:faad_flushbits |
128 | | |
129 | | /* return next n bits (right adjusted) */ |
130 | | static /*INLINE*/ uint32_t faad_getbits(bitfile *ld, uint32_t n DEBUGDEC) |
131 | 17.2k | { |
132 | 17.2k | uint32_t ret; |
133 | | |
134 | 17.2k | if (n == 0) |
135 | 0 | return 0; |
136 | | |
137 | 17.2k | ret = faad_showbits(ld, n); |
138 | 17.2k | faad_flushbits(ld, n); |
139 | | |
140 | | #ifdef ANALYSIS |
141 | | if (print) |
142 | | fprintf(stdout, "%4d %2d bits, val: %4d, variable: %d %s\n", dbg_count++, n, ret, var, dbg); |
143 | | #endif |
144 | | |
145 | 17.2k | return ret; |
146 | 17.2k | } Unexecuted instantiation: decoder.c:faad_getbits Unexecuted instantiation: common.c:faad_getbits Unexecuted instantiation: bits.c:faad_getbits Unexecuted instantiation: drc.c:faad_getbits Unexecuted instantiation: filtbank.c:faad_getbits Unexecuted instantiation: mdct.c:faad_getbits Unexecuted instantiation: cfft.c:faad_getbits Line | Count | Source | 131 | 1.39k | { | 132 | 1.39k | uint32_t ret; | 133 | | | 134 | 1.39k | if (n == 0) | 135 | 0 | return 0; | 136 | | | 137 | 1.39k | ret = faad_showbits(ld, n); | 138 | 1.39k | faad_flushbits(ld, n); | 139 | | | 140 | | #ifdef ANALYSIS | 141 | | if (print) | 142 | | fprintf(stdout, "%4d %2d bits, val: %4d, variable: %d %s\n", dbg_count++, n, ret, var, dbg); | 143 | | #endif | 144 | | | 145 | 1.39k | return ret; | 146 | 1.39k | } |
Unexecuted instantiation: output.c:faad_getbits Unexecuted instantiation: sbr_dec.c:faad_getbits Unexecuted instantiation: ps_dec.c:faad_getbits Unexecuted instantiation: sbr_hfadj.c:faad_getbits Unexecuted instantiation: sbr_hfgen.c:faad_getbits Unexecuted instantiation: sbr_fbt.c:faad_getbits Unexecuted instantiation: sbr_qmf.c:faad_getbits Line | Count | Source | 131 | 15.8k | { | 132 | 15.8k | uint32_t ret; | 133 | | | 134 | 15.8k | if (n == 0) | 135 | 0 | return 0; | 136 | | | 137 | 15.8k | ret = faad_showbits(ld, n); | 138 | 15.8k | faad_flushbits(ld, n); | 139 | | | 140 | | #ifdef ANALYSIS | 141 | | if (print) | 142 | | fprintf(stdout, "%4d %2d bits, val: %4d, variable: %d %s\n", dbg_count++, n, ret, var, dbg); | 143 | | #endif | 144 | | | 145 | 15.8k | return ret; | 146 | 15.8k | } |
Unexecuted instantiation: specrec.c:faad_getbits Unexecuted instantiation: ic_predict.c:faad_getbits Unexecuted instantiation: lt_predict.c:faad_getbits Unexecuted instantiation: pns.c:faad_getbits Unexecuted instantiation: ms.c:faad_getbits Unexecuted instantiation: is.c:faad_getbits Unexecuted instantiation: sbr_syntax.c:faad_getbits Unexecuted instantiation: sbr_huff.c:faad_getbits Unexecuted instantiation: sbr_e_nf.c:faad_getbits Unexecuted instantiation: sbr_tf_grid.c:faad_getbits Unexecuted instantiation: ps_syntax.c:faad_getbits Unexecuted instantiation: rvlc.c:faad_getbits Unexecuted instantiation: hcr.c:faad_getbits Unexecuted instantiation: huffman.c:faad_getbits Unexecuted instantiation: pulse.c:faad_getbits Unexecuted instantiation: tns.c:faad_getbits |
147 | | |
148 | | static INLINE uint8_t faad_get1bit(bitfile *ld DEBUGDEC) |
149 | 4.79k | { |
150 | 4.79k | uint8_t r; |
151 | | |
152 | 4.79k | if (ld->bits_left > 0) |
153 | 4.78k | { |
154 | 4.78k | ld->bits_left--; |
155 | 4.78k | r = (uint8_t)((ld->bufa >> ld->bits_left) & 1); |
156 | 4.78k | return r; |
157 | 4.78k | } |
158 | | |
159 | | /* bits_left == 0 */ |
160 | | #if 0 |
161 | | r = (uint8_t)(ld->bufb >> 31); |
162 | | faad_flushbits_ex(ld, 1); |
163 | | #else |
164 | 8 | r = (uint8_t)faad_getbits(ld, 1); |
165 | 8 | #endif |
166 | 8 | return r; |
167 | 4.79k | } Unexecuted instantiation: decoder.c:faad_get1bit Unexecuted instantiation: common.c:faad_get1bit Unexecuted instantiation: bits.c:faad_get1bit Unexecuted instantiation: drc.c:faad_get1bit Unexecuted instantiation: filtbank.c:faad_get1bit Unexecuted instantiation: mdct.c:faad_get1bit Unexecuted instantiation: cfft.c:faad_get1bit Line | Count | Source | 149 | 15 | { | 150 | 15 | uint8_t r; | 151 | | | 152 | 15 | if (ld->bits_left > 0) | 153 | 15 | { | 154 | 15 | ld->bits_left--; | 155 | 15 | r = (uint8_t)((ld->bufa >> ld->bits_left) & 1); | 156 | 15 | return r; | 157 | 15 | } | 158 | | | 159 | | /* bits_left == 0 */ | 160 | | #if 0 | 161 | | r = (uint8_t)(ld->bufb >> 31); | 162 | | faad_flushbits_ex(ld, 1); | 163 | | #else | 164 | 0 | r = (uint8_t)faad_getbits(ld, 1); | 165 | 0 | #endif | 166 | 0 | return r; | 167 | 15 | } |
Unexecuted instantiation: output.c:faad_get1bit Unexecuted instantiation: sbr_dec.c:faad_get1bit Unexecuted instantiation: ps_dec.c:faad_get1bit Unexecuted instantiation: sbr_hfadj.c:faad_get1bit Unexecuted instantiation: sbr_hfgen.c:faad_get1bit Unexecuted instantiation: sbr_fbt.c:faad_get1bit Unexecuted instantiation: sbr_qmf.c:faad_get1bit Line | Count | Source | 149 | 4.78k | { | 150 | 4.78k | uint8_t r; | 151 | | | 152 | 4.78k | if (ld->bits_left > 0) | 153 | 4.77k | { | 154 | 4.77k | ld->bits_left--; | 155 | 4.77k | r = (uint8_t)((ld->bufa >> ld->bits_left) & 1); | 156 | 4.77k | return r; | 157 | 4.77k | } | 158 | | | 159 | | /* bits_left == 0 */ | 160 | | #if 0 | 161 | | r = (uint8_t)(ld->bufb >> 31); | 162 | | faad_flushbits_ex(ld, 1); | 163 | | #else | 164 | 8 | r = (uint8_t)faad_getbits(ld, 1); | 165 | 8 | #endif | 166 | 8 | return r; | 167 | 4.78k | } |
Unexecuted instantiation: specrec.c:faad_get1bit Unexecuted instantiation: ic_predict.c:faad_get1bit Unexecuted instantiation: lt_predict.c:faad_get1bit Unexecuted instantiation: pns.c:faad_get1bit Unexecuted instantiation: ms.c:faad_get1bit Unexecuted instantiation: is.c:faad_get1bit Unexecuted instantiation: sbr_syntax.c:faad_get1bit Unexecuted instantiation: sbr_huff.c:faad_get1bit Unexecuted instantiation: sbr_e_nf.c:faad_get1bit Unexecuted instantiation: sbr_tf_grid.c:faad_get1bit Unexecuted instantiation: ps_syntax.c:faad_get1bit Unexecuted instantiation: rvlc.c:faad_get1bit Unexecuted instantiation: hcr.c:faad_get1bit Unexecuted instantiation: huffman.c:faad_get1bit Unexecuted instantiation: pulse.c:faad_get1bit Unexecuted instantiation: tns.c:faad_get1bit |
168 | | |
169 | | #if 0 |
170 | | /* reversed bitreading routines */ |
171 | | static INLINE uint32_t faad_showbits_rev(bitfile *ld, uint32_t bits) |
172 | | { |
173 | | uint8_t i; |
174 | | uint32_t B = 0; |
175 | | |
176 | | if (bits <= ld->bits_left) |
177 | | { |
178 | | for (i = 0; i < bits; i++) |
179 | | { |
180 | | if (ld->bufa & (1u << (i + (32 - ld->bits_left)))) |
181 | | B |= (1u << (bits - i - 1)); |
182 | | } |
183 | | return B; |
184 | | } else { |
185 | | for (i = 0; i < ld->bits_left; i++) |
186 | | { |
187 | | if (ld->bufa & (1u << (i + (32 - ld->bits_left)))) |
188 | | B |= (1u << (bits - i - 1)); |
189 | | } |
190 | | for (i = 0; i < bits - ld->bits_left; i++) |
191 | | { |
192 | | if (ld->bufb & (1u << (i + (32-ld->bits_left)))) |
193 | | B |= (1u << (bits - ld->bits_left - i - 1)); |
194 | | } |
195 | | return B; |
196 | | } |
197 | | } |
198 | | |
199 | | static INLINE void faad_flushbits_rev(bitfile *ld, uint32_t bits) |
200 | | { |
201 | | /* do nothing if error */ |
202 | | if (ld->error != 0) |
203 | | return; |
204 | | |
205 | | if (bits < ld->bits_left) |
206 | | { |
207 | | ld->bits_left -= bits; |
208 | | } else { |
209 | | uint32_t tmp; |
210 | | |
211 | | ld->bufa = ld->bufb; |
212 | | tmp = getdword(ld->start); |
213 | | ld->bufb = tmp; |
214 | | ld->start--; |
215 | | ld->bits_left += (32 - bits); |
216 | | |
217 | | if (ld->bytes_left < 4) |
218 | | { |
219 | | ld->error = 1; |
220 | | ld->bytes_left = 0; |
221 | | } else { |
222 | | ld->bytes_left -= 4; |
223 | | } |
224 | | // if (ld->bytes_left == 0) |
225 | | // ld->no_more_reading = 1; |
226 | | } |
227 | | } |
228 | | |
229 | | static /*INLINE*/ uint32_t faad_getbits_rev(bitfile *ld, uint32_t n |
230 | | DEBUGDEC) |
231 | | { |
232 | | uint32_t ret; |
233 | | |
234 | | if (n == 0) |
235 | | return 0; |
236 | | |
237 | | ret = faad_showbits_rev(ld, n); |
238 | | faad_flushbits_rev(ld, n); |
239 | | |
240 | | #ifdef ANALYSIS |
241 | | if (print) |
242 | | fprintf(stdout, "%4d %2d bits, val: %4d, variable: %d %s\n", dbg_count++, n, ret, var, dbg); |
243 | | #endif |
244 | | |
245 | | return ret; |
246 | | } |
247 | | #endif |
248 | | |
249 | | #ifdef DRM |
250 | | /* CRC lookup table for G8 polynome in DRM standard */ |
251 | | static const uint8_t crc_table_G8[256] = { |
252 | | 0x0, 0x1d, 0x3a, 0x27, 0x74, 0x69, 0x4e, 0x53, |
253 | | 0xe8, 0xf5, 0xd2, 0xcf, 0x9c, 0x81, 0xa6, 0xbb, |
254 | | 0xcd, 0xd0, 0xf7, 0xea, 0xb9, 0xa4, 0x83, 0x9e, |
255 | | 0x25, 0x38, 0x1f, 0x2, 0x51, 0x4c, 0x6b, 0x76, |
256 | | 0x87, 0x9a, 0xbd, 0xa0, 0xf3, 0xee, 0xc9, 0xd4, |
257 | | 0x6f, 0x72, 0x55, 0x48, 0x1b, 0x6, 0x21, 0x3c, |
258 | | 0x4a, 0x57, 0x70, 0x6d, 0x3e, 0x23, 0x4, 0x19, |
259 | | 0xa2, 0xbf, 0x98, 0x85, 0xd6, 0xcb, 0xec, 0xf1, |
260 | | 0x13, 0xe, 0x29, 0x34, 0x67, 0x7a, 0x5d, 0x40, |
261 | | 0xfb, 0xe6, 0xc1, 0xdc, 0x8f, 0x92, 0xb5, 0xa8, |
262 | | 0xde, 0xc3, 0xe4, 0xf9, 0xaa, 0xb7, 0x90, 0x8d, |
263 | | 0x36, 0x2b, 0xc, 0x11, 0x42, 0x5f, 0x78, 0x65, |
264 | | 0x94, 0x89, 0xae, 0xb3, 0xe0, 0xfd, 0xda, 0xc7, |
265 | | 0x7c, 0x61, 0x46, 0x5b, 0x8, 0x15, 0x32, 0x2f, |
266 | | 0x59, 0x44, 0x63, 0x7e, 0x2d, 0x30, 0x17, 0xa, |
267 | | 0xb1, 0xac, 0x8b, 0x96, 0xc5, 0xd8, 0xff, 0xe2, |
268 | | 0x26, 0x3b, 0x1c, 0x1, 0x52, 0x4f, 0x68, 0x75, |
269 | | 0xce, 0xd3, 0xf4, 0xe9, 0xba, 0xa7, 0x80, 0x9d, |
270 | | 0xeb, 0xf6, 0xd1, 0xcc, 0x9f, 0x82, 0xa5, 0xb8, |
271 | | 0x3, 0x1e, 0x39, 0x24, 0x77, 0x6a, 0x4d, 0x50, |
272 | | 0xa1, 0xbc, 0x9b, 0x86, 0xd5, 0xc8, 0xef, 0xf2, |
273 | | 0x49, 0x54, 0x73, 0x6e, 0x3d, 0x20, 0x7, 0x1a, |
274 | | 0x6c, 0x71, 0x56, 0x4b, 0x18, 0x5, 0x22, 0x3f, |
275 | | 0x84, 0x99, 0xbe, 0xa3, 0xf0, 0xed, 0xca, 0xd7, |
276 | | 0x35, 0x28, 0xf, 0x12, 0x41, 0x5c, 0x7b, 0x66, |
277 | | 0xdd, 0xc0, 0xe7, 0xfa, 0xa9, 0xb4, 0x93, 0x8e, |
278 | | 0xf8, 0xe5, 0xc2, 0xdf, 0x8c, 0x91, 0xb6, 0xab, |
279 | | 0x10, 0xd, 0x2a, 0x37, 0x64, 0x79, 0x5e, 0x43, |
280 | | 0xb2, 0xaf, 0x88, 0x95, 0xc6, 0xdb, 0xfc, 0xe1, |
281 | | 0x5a, 0x47, 0x60, 0x7d, 0x2e, 0x33, 0x14, 0x9, |
282 | | 0x7f, 0x62, 0x45, 0x58, 0xb, 0x16, 0x31, 0x2c, |
283 | | 0x97, 0x8a, 0xad, 0xb0, 0xe3, 0xfe, 0xd9, 0xc4, |
284 | | }; |
285 | | |
286 | | static INLINE uint8_t faad_check_CRC(bitfile *ld, uint16_t len) |
287 | | { |
288 | | int bytes, rem; |
289 | | unsigned int CRC; |
290 | | unsigned int r=255; /* Initialize to all ones */ |
291 | | |
292 | | /* CRC polynome used x^8 + x^4 + x^3 + x^2 +1 */ |
293 | | #define GPOLY 0435 |
294 | | |
295 | | faad_rewindbits(ld); |
296 | | |
297 | | CRC = (unsigned int) ~faad_getbits(ld, 8 |
298 | | DEBUGVAR(1,999,"faad_check_CRC(): CRC")) & 0xFF; /* CRC is stored inverted */ |
299 | | |
300 | | bytes = len >> 3; |
301 | | rem = len & 0x7; |
302 | | |
303 | | for (; bytes > 0; bytes--) |
304 | | { |
305 | | r = crc_table_G8[( r ^ faad_getbits(ld, 8 DEBUGVAR(1,998,"")) ) & 0xFF]; |
306 | | } |
307 | | for (; rem > 0; rem--) |
308 | | { |
309 | | r = ( (r << 1) ^ (( ( faad_get1bit(ld |
310 | | DEBUGVAR(1,998,"")) & 1) ^ ((r >> 7) & 1)) * GPOLY )) & 0xFF; |
311 | | } |
312 | | |
313 | | if (r != CRC) |
314 | | // if (0) |
315 | | { |
316 | | return 28; |
317 | | } else { |
318 | | return 0; |
319 | | } |
320 | | } |
321 | | |
322 | | #ifdef SBR_DEC |
323 | | static uint8_t tabFlipbits[256] = { |
324 | | 0,128,64,192,32,160,96,224,16,144,80,208,48,176,112,240, |
325 | | 8,136,72,200,40,168,104,232,24,152,88,216,56,184,120,248, |
326 | | 4,132,68,196,36,164,100,228,20,148,84,212,52,180,116,244, |
327 | | 12,140,76,204,44,172,108,236,28,156,92,220,60,188,124,252, |
328 | | 2,130,66,194,34,162,98,226,18,146,82,210,50,178,114,242, |
329 | | 10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250, |
330 | | 6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246, |
331 | | 14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254, |
332 | | 1,129,65,193,33,161,97,225,17,145,81,209,49,177,113,241, |
333 | | 9,137,73,201,41,169,105,233,25,153,89,217,57,185,121,249, |
334 | | 5,133,69,197,37,165,101,229,21,149,85,213,53,181,117,245, |
335 | | 13,141,77,205,45,173,109,237,29,157,93,221,61,189,125,253, |
336 | | 3,131,67,195,35,163,99,227,19,147,83,211,51,179,115,243, |
337 | | 11,139,75,203,43,171,107,235,27,155,91,219,59,187,123,251, |
338 | | 7,135,71,199,39,167,103,231,23,151,87,215,55,183,119,247, |
339 | | 15,143,79,207,47,175,111,239,31,159,95,223,63,191,127,255 |
340 | | }; |
341 | | static INLINE uint8_t reverse_byte(uint8_t b) |
342 | | { |
343 | | return tabFlipbits[b]; |
344 | | } |
345 | | #endif |
346 | | #endif |
347 | | |
348 | | #ifdef ERROR_RESILIENCE |
349 | | |
350 | | /* Modified bit reading functions for HCR */ |
351 | | |
352 | | typedef struct |
353 | | { |
354 | | /* bit input */ |
355 | | uint32_t bufa; |
356 | | uint32_t bufb; |
357 | | int8_t len; |
358 | | } bits_t; |
359 | | |
360 | | /* PRECONDITION: bits <= 32 */ |
361 | | static INLINE uint32_t showbits_hcr(bits_t *ld, uint8_t bits) |
362 | 0 | { |
363 | 0 | uint32_t mask; |
364 | 0 | int8_t tail; |
365 | 0 | if (bits == 0) return 0; |
366 | 0 | if (ld->len == 0) return 0; |
367 | 0 | tail = ld->len - bits; |
368 | 0 | mask = 0xFFFFFFFF >> (32 - bits); |
369 | 0 | if (ld->len <= 32) |
370 | 0 | { |
371 | | /* huffman_spectral_data_2 might request more than available (tail < 0), |
372 | | pad with zeroes then. */ |
373 | 0 | if (tail >= 0) |
374 | 0 | return (ld->bufa >> tail) & mask; /* tail is 0..31 */ |
375 | 0 | else |
376 | 0 | return (ld->bufa << -tail) & mask; /* -tail is 1..31 */ |
377 | 0 | } else { |
378 | | /* tail is 1..63 */ |
379 | 0 | if (tail < 32) |
380 | 0 | return ((ld->bufb << (32 - tail)) | (ld->bufa >> tail)) & mask; |
381 | 0 | else |
382 | 0 | return (ld->bufb >> (tail - 32)) & mask; |
383 | 0 | } |
384 | 0 | } Unexecuted instantiation: decoder.c:showbits_hcr Unexecuted instantiation: common.c:showbits_hcr Unexecuted instantiation: bits.c:showbits_hcr Unexecuted instantiation: drc.c:showbits_hcr Unexecuted instantiation: filtbank.c:showbits_hcr Unexecuted instantiation: mdct.c:showbits_hcr Unexecuted instantiation: cfft.c:showbits_hcr Unexecuted instantiation: mp4.c:showbits_hcr Unexecuted instantiation: output.c:showbits_hcr Unexecuted instantiation: sbr_dec.c:showbits_hcr Unexecuted instantiation: ps_dec.c:showbits_hcr Unexecuted instantiation: sbr_hfadj.c:showbits_hcr Unexecuted instantiation: sbr_hfgen.c:showbits_hcr Unexecuted instantiation: sbr_fbt.c:showbits_hcr Unexecuted instantiation: sbr_qmf.c:showbits_hcr Unexecuted instantiation: syntax.c:showbits_hcr Unexecuted instantiation: specrec.c:showbits_hcr Unexecuted instantiation: ic_predict.c:showbits_hcr Unexecuted instantiation: lt_predict.c:showbits_hcr Unexecuted instantiation: pns.c:showbits_hcr Unexecuted instantiation: ms.c:showbits_hcr Unexecuted instantiation: is.c:showbits_hcr Unexecuted instantiation: sbr_syntax.c:showbits_hcr Unexecuted instantiation: sbr_huff.c:showbits_hcr Unexecuted instantiation: sbr_e_nf.c:showbits_hcr Unexecuted instantiation: sbr_tf_grid.c:showbits_hcr Unexecuted instantiation: ps_syntax.c:showbits_hcr Unexecuted instantiation: rvlc.c:showbits_hcr Unexecuted instantiation: hcr.c:showbits_hcr Unexecuted instantiation: huffman.c:showbits_hcr Unexecuted instantiation: pulse.c:showbits_hcr Unexecuted instantiation: tns.c:showbits_hcr |
385 | | |
386 | | /* return 1 if position is outside of buffer, 0 otherwise */ |
387 | | static INLINE int8_t flushbits_hcr( bits_t *ld, uint8_t bits) |
388 | 0 | { |
389 | 0 | ld->len -= bits; |
390 | |
|
391 | 0 | if (ld->len <0) |
392 | 0 | { |
393 | 0 | ld->len = 0; |
394 | 0 | return 1; |
395 | 0 | } else { |
396 | 0 | return 0; |
397 | 0 | } |
398 | 0 | } Unexecuted instantiation: decoder.c:flushbits_hcr Unexecuted instantiation: common.c:flushbits_hcr Unexecuted instantiation: bits.c:flushbits_hcr Unexecuted instantiation: drc.c:flushbits_hcr Unexecuted instantiation: filtbank.c:flushbits_hcr Unexecuted instantiation: mdct.c:flushbits_hcr Unexecuted instantiation: cfft.c:flushbits_hcr Unexecuted instantiation: mp4.c:flushbits_hcr Unexecuted instantiation: output.c:flushbits_hcr Unexecuted instantiation: sbr_dec.c:flushbits_hcr Unexecuted instantiation: ps_dec.c:flushbits_hcr Unexecuted instantiation: sbr_hfadj.c:flushbits_hcr Unexecuted instantiation: sbr_hfgen.c:flushbits_hcr Unexecuted instantiation: sbr_fbt.c:flushbits_hcr Unexecuted instantiation: sbr_qmf.c:flushbits_hcr Unexecuted instantiation: syntax.c:flushbits_hcr Unexecuted instantiation: specrec.c:flushbits_hcr Unexecuted instantiation: ic_predict.c:flushbits_hcr Unexecuted instantiation: lt_predict.c:flushbits_hcr Unexecuted instantiation: pns.c:flushbits_hcr Unexecuted instantiation: ms.c:flushbits_hcr Unexecuted instantiation: is.c:flushbits_hcr Unexecuted instantiation: sbr_syntax.c:flushbits_hcr Unexecuted instantiation: sbr_huff.c:flushbits_hcr Unexecuted instantiation: sbr_e_nf.c:flushbits_hcr Unexecuted instantiation: sbr_tf_grid.c:flushbits_hcr Unexecuted instantiation: ps_syntax.c:flushbits_hcr Unexecuted instantiation: rvlc.c:flushbits_hcr Unexecuted instantiation: hcr.c:flushbits_hcr Unexecuted instantiation: huffman.c:flushbits_hcr Unexecuted instantiation: pulse.c:flushbits_hcr Unexecuted instantiation: tns.c:flushbits_hcr |
399 | | |
400 | | static INLINE int8_t getbits_hcr(bits_t *ld, uint8_t n, uint32_t *result) |
401 | 0 | { |
402 | 0 | *result = showbits_hcr(ld, n); |
403 | 0 | return flushbits_hcr(ld, n); |
404 | 0 | } Unexecuted instantiation: decoder.c:getbits_hcr Unexecuted instantiation: common.c:getbits_hcr Unexecuted instantiation: bits.c:getbits_hcr Unexecuted instantiation: drc.c:getbits_hcr Unexecuted instantiation: filtbank.c:getbits_hcr Unexecuted instantiation: mdct.c:getbits_hcr Unexecuted instantiation: cfft.c:getbits_hcr Unexecuted instantiation: mp4.c:getbits_hcr Unexecuted instantiation: output.c:getbits_hcr Unexecuted instantiation: sbr_dec.c:getbits_hcr Unexecuted instantiation: ps_dec.c:getbits_hcr Unexecuted instantiation: sbr_hfadj.c:getbits_hcr Unexecuted instantiation: sbr_hfgen.c:getbits_hcr Unexecuted instantiation: sbr_fbt.c:getbits_hcr Unexecuted instantiation: sbr_qmf.c:getbits_hcr Unexecuted instantiation: syntax.c:getbits_hcr Unexecuted instantiation: specrec.c:getbits_hcr Unexecuted instantiation: ic_predict.c:getbits_hcr Unexecuted instantiation: lt_predict.c:getbits_hcr Unexecuted instantiation: pns.c:getbits_hcr Unexecuted instantiation: ms.c:getbits_hcr Unexecuted instantiation: is.c:getbits_hcr Unexecuted instantiation: sbr_syntax.c:getbits_hcr Unexecuted instantiation: sbr_huff.c:getbits_hcr Unexecuted instantiation: sbr_e_nf.c:getbits_hcr Unexecuted instantiation: sbr_tf_grid.c:getbits_hcr Unexecuted instantiation: ps_syntax.c:getbits_hcr Unexecuted instantiation: rvlc.c:getbits_hcr Unexecuted instantiation: hcr.c:getbits_hcr Unexecuted instantiation: huffman.c:getbits_hcr Unexecuted instantiation: pulse.c:getbits_hcr Unexecuted instantiation: tns.c:getbits_hcr |
405 | | |
406 | | static INLINE int8_t get1bit_hcr(bits_t *ld, uint8_t *result) |
407 | 0 | { |
408 | 0 | uint32_t res; |
409 | 0 | int8_t ret; |
410 | |
|
411 | 0 | ret = getbits_hcr(ld, 1, &res); |
412 | 0 | *result = (int8_t)(res & 1); |
413 | 0 | return ret; |
414 | 0 | } Unexecuted instantiation: decoder.c:get1bit_hcr Unexecuted instantiation: common.c:get1bit_hcr Unexecuted instantiation: bits.c:get1bit_hcr Unexecuted instantiation: drc.c:get1bit_hcr Unexecuted instantiation: filtbank.c:get1bit_hcr Unexecuted instantiation: mdct.c:get1bit_hcr Unexecuted instantiation: cfft.c:get1bit_hcr Unexecuted instantiation: mp4.c:get1bit_hcr Unexecuted instantiation: output.c:get1bit_hcr Unexecuted instantiation: sbr_dec.c:get1bit_hcr Unexecuted instantiation: ps_dec.c:get1bit_hcr Unexecuted instantiation: sbr_hfadj.c:get1bit_hcr Unexecuted instantiation: sbr_hfgen.c:get1bit_hcr Unexecuted instantiation: sbr_fbt.c:get1bit_hcr Unexecuted instantiation: sbr_qmf.c:get1bit_hcr Unexecuted instantiation: syntax.c:get1bit_hcr Unexecuted instantiation: specrec.c:get1bit_hcr Unexecuted instantiation: ic_predict.c:get1bit_hcr Unexecuted instantiation: lt_predict.c:get1bit_hcr Unexecuted instantiation: pns.c:get1bit_hcr Unexecuted instantiation: ms.c:get1bit_hcr Unexecuted instantiation: is.c:get1bit_hcr Unexecuted instantiation: sbr_syntax.c:get1bit_hcr Unexecuted instantiation: sbr_huff.c:get1bit_hcr Unexecuted instantiation: sbr_e_nf.c:get1bit_hcr Unexecuted instantiation: sbr_tf_grid.c:get1bit_hcr Unexecuted instantiation: ps_syntax.c:get1bit_hcr Unexecuted instantiation: rvlc.c:get1bit_hcr Unexecuted instantiation: hcr.c:get1bit_hcr Unexecuted instantiation: huffman.c:get1bit_hcr Unexecuted instantiation: pulse.c:get1bit_hcr Unexecuted instantiation: tns.c:get1bit_hcr |
415 | | |
416 | | #endif |
417 | | |
418 | | |
419 | | #ifdef __cplusplus |
420 | | } |
421 | | #endif |
422 | | #endif |