summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/bit.c
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/libmad/bit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/bit.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/core/multimedia/opieplayer/libmad/bit.c b/core/multimedia/opieplayer/libmad/bit.c
index 2466c5f..4a4661b 100644
--- a/core/multimedia/opieplayer/libmad/bit.c
+++ b/core/multimedia/opieplayer/libmad/bit.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 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 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 7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version. 8 * (at your option) any later version.
@@ -194,27 +194,44 @@ void mad_bit_write(struct mad_bitptr *bitptr, unsigned int len,
194 * NAME:bit->crc() 194 * NAME:bit->crc()
195 * DESCRIPTION:compute CRC-check word 195 * DESCRIPTION:compute CRC-check word
196 */ 196 */
197unsigned short mad_bit_crc(struct mad_bitptr bitptr, unsigned int len, 197unsigned short mad_bit_crc(struct mad_bitptr bitptr, unsigned int len,
198 unsigned short init) 198 unsigned short init)
199{ 199{
200 register unsigned int crc, data; 200 register unsigned int crc;
201 201
202# if CHAR_BIT == 8 202 for (crc = init; len >= 32; len -= 32) {
203 for (crc = init; len >= 8; len -= 8) { 203 register unsigned long data;
204 crc = (crc << 8) ^ 204
205 crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff]; 205 data = mad_bit_read(&bitptr, 32);
206
207 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 24)) & 0xff];
208 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 16)) & 0xff];
209 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 8)) & 0xff];
210 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 0)) & 0xff];
211 }
212
213 switch (len / 8) {
214 case 3: crc = (crc << 8) ^
215 crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
216 case 2: crc = (crc << 8) ^
217 crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
218 case 1: crc = (crc << 8) ^
219 crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
220
221 len %= 8;
222
223 case 0: break;
206 } 224 }
207# else
208 crc = init;
209# endif
210 225
211 while (len--) { 226 while (len--) {
212 data = mad_bit_read(&bitptr, 1) ^ (crc >> 15); 227 register unsigned int msb;
228
229 msb = mad_bit_read(&bitptr, 1) ^ (crc >> 15);
213 230
214 crc <<= 1; 231 crc <<= 1;
215 if (data & 1) 232 if (msb & 1)
216 crc ^= CRC_POLY; 233 crc ^= CRC_POLY;
217 } 234 }
218 235
219 return crc & 0xffff; 236 return crc & 0xffff;
220} 237}