MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / mad_bit_crc

Function mad_bit_crc

modules/data/mp3/libmad/bit.c:202–246  ·  view source on GitHub ↗

* NAME: bit->crc() * DESCRIPTION: compute CRC-check word */

Source from the content-addressed store, hash-verified

200 * DESCRIPTION: compute CRC-check word
201 */
202unsigned short mad_bit_crc(struct mad_bitptr bitptr, unsigned int len,
203 unsigned short init)
204{
205 unsigned int crc;
206stack(__FUNCTION__, __FILE__, __LINE__);
207
208 for (crc = init; len >= 32; len -= 32) {
209 unsigned long data;
210
211 data = mad_bit_read(&bitptr, 32);
212
213 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 24)) & 0xff];
214 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 16)) & 0xff];
215 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 8)) & 0xff];
216 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 0)) & 0xff];
217 }
218
219 switch (len / 8) {
220 case 3: crc = (crc << 8) ^
221 crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
222 /* Falls Through. */
223 case 2: crc = (crc << 8) ^
224 crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
225 /* Falls Through. */
226 case 1: crc = (crc << 8) ^
227 crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
228
229 len %= 8;
230 /* Falls Through. */
231
232 case 0: break;
233 }
234
235 while (len--) {
236 unsigned int msb;
237
238 msb = mad_bit_read(&bitptr, 1) ^ (crc >> 15);
239
240 crc <<= 1;
241 if (msb & 1)
242 crc ^= CRC_POLY;
243 }
244
245 return crc & 0xffff;
246}

Callers 2

decode_headerFunction · 0.85
mad_layer_IIIFunction · 0.85

Calls 1

mad_bit_readFunction · 0.85

Tested by

no test coverage detected