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 2, 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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include <atsci_reed_solomon.h>
30 static const int rs_init_symsize = 8;
31 static const int rs_init_gfpoly = 0x11d;
32 static const int rs_init_fcr = 0; // first consecutive root
33 static const int rs_init_prim = 1; // primitive is 1 (alpha)
34 static const int rs_init_nroots = 20;
36 static const int N = (1 << rs_init_symsize) - 1; // 255
37 static const int K = N - rs_init_nroots; // 235
39 static const int amount_of_pad = N - ATSC_MPEG_RS_ENCODED_LENGTH; // 48
41 atsci_reed_solomon::atsci_reed_solomon ()
43 d_rs = init_rs_char (rs_init_symsize, rs_init_gfpoly,
44 rs_init_fcr, rs_init_prim, rs_init_nroots);
49 atsci_reed_solomon::~atsci_reed_solomon ()
57 atsci_reed_solomon::encode (atsc_mpeg_packet_rs_encoded &out, const atsc_mpeg_packet_no_sync &in)
61 assert ((int)(amount_of_pad + sizeof (in.data)) == K);
63 // add missing prefix zero padding to message
64 memset (tmp, 0, amount_of_pad);
65 memcpy (&tmp[amount_of_pad], in.data, sizeof (in.data));
67 // copy message portion to output packet
68 memcpy (out.data, in.data, sizeof (in.data));
70 // now compute parity bytes and add them to tail end of output packet
71 encode_rs_char (d_rs, tmp, &out.data[sizeof (in.data)]);
75 atsci_reed_solomon::decode (atsc_mpeg_packet_no_sync &out, const atsc_mpeg_packet_rs_encoded &in)
80 assert ((int)(amount_of_pad + sizeof (in.data)) == N);
82 // add missing prefix zero padding to message
83 memset (tmp, 0, amount_of_pad);
84 memcpy (&tmp[amount_of_pad], in.data, sizeof (in.data));
87 ncorrections = decode_rs_char (d_rs, tmp, 0, 0);
89 // copy corrected message to output, skipping prefix zero padding
90 memcpy (out.data, &tmp[amount_of_pad], sizeof (out.data));