comparison alac.c @ 6626:a2f1a461dac6 libavcodec

Factorize more code.
author michael
date Thu, 17 Apr 2008 03:21:15 +0000
parents 1f4a86db7835
children 33a41b13fbfe
comparison
equal deleted inserted replaced
6625:1f4a86db7835 6626:a2f1a461dac6
144 { 144 {
145 return 31-av_log2(input); 145 return 31-av_log2(input);
146 } 146 }
147 147
148 148
149 static inline int decode_postfix(GetBitContext *gb, int x, int k, int limit){ 149 static inline int decode_scalar(GetBitContext *gb, int k, int limit, int readsamplesize){
150 /* read x - number of 1s before 0 represent the rice */
151 int x = get_unary_0_9(gb);
152
153 if (x > 8) { /* RICE THRESHOLD */
154 /* use alternative encoding */
155 x = get_bits(gb, readsamplesize);
156 } else {
150 if (k >= limit) 157 if (k >= limit)
151 k = limit; 158 k = limit;
152 159
153 if (k != 1) { 160 if (k != 1) {
154 int extrabits = show_bits(gb, k); 161 int extrabits = show_bits(gb, k);
159 if (extrabits > 1) { 166 if (extrabits > 1) {
160 x += extrabits - 1; 167 x += extrabits - 1;
161 skip_bits(gb, k); 168 skip_bits(gb, k);
162 } else 169 } else
163 skip_bits(gb, k - 1); 170 skip_bits(gb, k - 1);
171 }
164 } 172 }
165 return x; 173 return x;
166 } 174 }
167 175
168 static void bastardized_rice_decompress(ALACContext *alac, 176 static void bastardized_rice_decompress(ALACContext *alac,
182 for (output_count = 0; output_count < output_size; output_count++) { 190 for (output_count = 0; output_count < output_size; output_count++) {
183 int32_t x; 191 int32_t x;
184 int32_t x_modified; 192 int32_t x_modified;
185 int32_t final_val; 193 int32_t final_val;
186 194
187 /* read x - number of 1s before 0 represent the rice */
188 x = get_unary_0_9(&alac->gb);
189
190 if (x > 8) { /* RICE THRESHOLD */
191 /* use alternative encoding */
192 x = get_bits(&alac->gb, readsamplesize);
193 } else {
194 /* standard rice encoding */ 195 /* standard rice encoding */
195 int k; /* size of extra bits */ 196 int k; /* size of extra bits */
196 197
197 /* read k, that is bits as is */ 198 /* read k, that is bits as is */
198 k = 31 - count_leading_zeros((history >> 9) + 3); 199 k = 31 - count_leading_zeros((history >> 9) + 3);
199 x= decode_postfix(&alac->gb, x, k, rice_kmodifier); 200 x= decode_scalar(&alac->gb, k, rice_kmodifier, readsamplesize);
200 }
201 201
202 x_modified = sign_modifier + x; 202 x_modified = sign_modifier + x;
203 final_val = (x_modified + 1) / 2; 203 final_val = (x_modified + 1) / 2;
204 if (x_modified & 1) final_val *= -1; 204 if (x_modified & 1) final_val *= -1;
205 205
214 if (x_modified > 0xffff) 214 if (x_modified > 0xffff)
215 history = 0xffff; 215 history = 0xffff;
216 216
217 /* special case: there may be compressed blocks of 0 */ 217 /* special case: there may be compressed blocks of 0 */
218 if ((history < 128) && (output_count+1 < output_size)) { 218 if ((history < 128) && (output_count+1 < output_size)) {
219 int block_size; 219 int block_size, k;
220 220
221 sign_modifier = 1; 221 sign_modifier = 1;
222 222
223 x = get_unary_0_9(&alac->gb);
224
225 if (x > 8) {
226 block_size = get_bits(&alac->gb, 16);
227 } else {
228 int k;
229
230 k = count_leading_zeros(history) + ((history + 16) >> 6 /* / 64 */) - 24; 223 k = count_leading_zeros(history) + ((history + 16) >> 6 /* / 64 */) - 24;
231 224
232 block_size= decode_postfix(&alac->gb, x, k, rice_kmodifier); 225 block_size= decode_scalar(&alac->gb, k, rice_kmodifier, 16);
233 }
234 226
235 if (block_size > 0) { 227 if (block_size > 0) {
236 memset(&output_buffer[output_count+1], 0, block_size * 4); 228 memset(&output_buffer[output_count+1], 0, block_size * 4);
237 output_count += block_size; 229 output_count += block_size;
238 } 230 }