CRC8 and CRC16 Calculation
The CRC calculation used by flac are not fully documented.
The parameters for the CRC8 are:
data bitorder: msbit-first p-bitorder: msbit-first polynomial: x8 + x2 + x + 1 p-factor 0x07 pre-invert: NO post-invert: NOThe lookup table is generated using:
// for each of the 256 entries for (lv_N = 0; lv_N < 256; ++lv_N) { // for each bit of a byte // - data-bitorder = msb therefore start with high-byte (shift left) for (lv_C = (UINT8)lv_N, lv_K = 0; lv_K < 8; ++lv_K) { // if bit is set then shift and xor with polynomial, otherwise only shift // - p-bitorder = msb therefore 0x07 // - data-bitorder = msb therefore test high-bit and shift left if (lv_C & 0x80) lv_C = (UINT8)(0x07 ^ (lv_C << 1)); else lv_C <<= 1; } // store entry gv_FlacCrc8Table = lv_C; }
The parameters for the CRC16 are:
The lookup table is generated using:
// for each of the 256 entries for (lv_N = 0; lv_N < 256; ++lv_N) { // for each bit of a byte // - data-bitorder = msb therefore start with high-byte (shift left) for (lv_C = (UINT16)(lv_N<<8), lv_K = 0; lv_K < 8; ++lv_K) { // if bit is set then shift and xor with polynomial, otherwise only shift // - p-bitorder = msb therefore 0x8005 // - data-bitorder = msb therefore test high-bit and shift left if (lv_C & 0x8000) lv_C = (UINT16)(0x8005 ^ (lv_C << 1)); else lv_C <<= 1; } // store entry gv_FlacCrc16Table = lv_C; }Read more about this topic: FLAC
Famous quotes containing the word calculation:
“Common sense is the measure of the possible; it is composed of experience and prevision; it is calculation appled to life.”
—Henri-Frédéric Amiel (18211881)
Related Subjects
Related Phrases
Related Words