3 * Copyright 2002 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #include <atsci_reed_solomon.h>
31 static const int rs_init_symsize = 8;
32 static const int rs_init_gfpoly = 0x11d;
33 static const int rs_init_fcr = 0; // first consecutive root
34 static const int rs_init_prim = 1; // primitive is 1 (alpha)
35 static const int rs_init_nroots = 20;
37 static const int N = (1 << rs_init_symsize) - 1; // 255
38 static const int K = N - rs_init_nroots; // 235
40 static const int amount_of_pad = N - ATSC_MPEG_RS_ENCODED_LENGTH; // 48
42 atsci_reed_solomon::atsci_reed_solomon ()
44 d_rs = init_rs_char (rs_init_symsize, rs_init_gfpoly,
45 rs_init_fcr, rs_init_prim, rs_init_nroots);
50 atsci_reed_solomon::~atsci_reed_solomon ()
58 atsci_reed_solomon::encode (atsc_mpeg_packet_rs_encoded &out, const atsc_mpeg_packet_no_sync &in)
62 assert ((int)(amount_of_pad + sizeof (in.data)) == K);
64 // add missing prefix zero padding to message
65 memset (tmp, 0, amount_of_pad);
66 memcpy (&tmp[amount_of_pad], in.data, sizeof (in.data));
68 // copy message portion to output packet
69 memcpy (out.data, in.data, sizeof (in.data));
71 // now compute parity bytes and add them to tail end of output packet
72 encode_rs_char (d_rs, tmp, &out.data[sizeof (in.data)]);
76 atsci_reed_solomon::decode (atsc_mpeg_packet_no_sync &out, const atsc_mpeg_packet_rs_encoded &in)
81 assert ((int)(amount_of_pad + sizeof (in.data)) == N);
83 // add missing prefix zero padding to message
84 memset (tmp, 0, amount_of_pad);
85 memcpy (&tmp[amount_of_pad], in.data, sizeof (in.data));
88 ncorrections = decode_rs_char (d_rs, tmp, 0, 0);
90 // copy corrected message to output, skipping prefix zero padding
91 memcpy (out.data, &tmp[amount_of_pad], sizeof (out.data));