Diffstat (limited to 'core/multimedia/opieplayer/libmad/bit.c') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/bit.c | 37 |
1 files changed, 27 insertions, 10 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 @@ /* - * mad - MPEG audio decoder + * libmad - MPEG audio decoder library * Copyright (C) 2000-2001 Robert Leslie * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. @@ -194,27 +194,44 @@ void mad_bit_write(struct mad_bitptr *bitptr, unsigned int len, * NAME: bit->crc() * DESCRIPTION: compute CRC-check word */ unsigned short mad_bit_crc(struct mad_bitptr bitptr, unsigned int len, unsigned short init) { - register unsigned int crc, data; + register unsigned int crc; -# if CHAR_BIT == 8 - for (crc = init; len >= 8; len -= 8) { - crc = (crc << 8) ^ + for (crc = init; len >= 32; len -= 32) { + register unsigned long data; + + data = mad_bit_read(&bitptr, 32); + + crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 24)) & 0xff]; + crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 16)) & 0xff]; + crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 8)) & 0xff]; + crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 0)) & 0xff]; + } + + switch (len / 8) { + case 3: crc = (crc << 8) ^ + crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff]; + case 2: crc = (crc << 8) ^ + crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff]; + case 1: crc = (crc << 8) ^ crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff]; + + len %= 8; + + case 0: break; } -# else - crc = init; -# endif while (len--) { - data = mad_bit_read(&bitptr, 1) ^ (crc >> 15); + register unsigned int msb; + + msb = mad_bit_read(&bitptr, 1) ^ (crc >> 15); crc <<= 1; - if (data & 1) + if (msb & 1) crc ^= CRC_POLY; } return crc & 0xffff; } |