- uint16_t fec = 0, output;
- uint8_t byte, bit;
-
- for (byte = 0; byte < len; byte++) {
- fec = (fec & 0x700) | in[byte];
- output = 0;
- for (bit = 0; bit < 8; bit++) {
- output = output << 2 | ao_fec_encode_table[fec >> 7];
- fec = (fec << 1) & 0x7ff;
+ uint8_t extra[AO_FEC_PREPARE_EXTRA];
+ uint8_t extra_len;
+ uint32_t encode, interleave;
+ uint8_t pair, byte, bit;
+ uint16_t fec = 0;
+ const uint8_t *whiten = ao_fec_whiten_table;
+
+ extra_len = ao_fec_prepare(in, len, extra);
+ for (pair = 0; pair < len + extra_len; pair += 2) {
+ encode = 0;
+ for (byte = 0; byte < 2; byte++) {
+ if (pair + byte == len)
+ in = extra;
+ fec |= *in++ ^ *whiten++;
+ for (bit = 0; bit < 8; bit++) {
+ encode = encode << 2 | ao_fec_encode_table[fec >> 7];
+ fec = (fec << 1) & 0x7ff;
+ }