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_randomizer.h>
26 unsigned char atsci_randomizer::s_output_map[1 << 14];
27 bool atsci_randomizer::s_output_map_initialized_p = false;
29 atsci_randomizer::atsci_randomizer ()
31 d_state = PRELOAD_VALUE;
33 if (!s_output_map_initialized_p)
34 initialize_output_map ();
38 * \brief Generate the table used in the fast_output_map function.
40 * The table has 16K byte entries, but because of how is is used, only
41 * 256 entries end up being resident in the cache. This seems
42 * like a good use of memory. We can get away with a 16K table
43 * because the low two bits of the state do not affect the output
44 * function. By shifting right those two bits we shrink the table,
45 * and also get better cache line utilization.
48 atsci_randomizer::initialize_output_map ()
50 s_output_map_initialized_p = true;
52 for (int i = 0; i < (1 << 14); i++)
53 s_output_map[i] = slow_output_map (i << 2);
58 atsci_randomizer::reset ()
60 d_state = PRELOAD_VALUE;
64 atsci_randomizer::randomize (atsc_mpeg_packet_no_sync &out, const atsc_mpeg_packet &in)
66 assert (in.data[0] == MPEG_SYNC_BYTE); // confirm it's there, then drop
68 for (int i = 0; i < ATSC_MPEG_DATA_LENGTH; i++)
69 out.data[i] = in.data[i + 1] ^ output_and_clk ();
73 atsci_randomizer::derandomize (atsc_mpeg_packet &out, const atsc_mpeg_packet_no_sync &in)
75 out.data[0] = MPEG_SYNC_BYTE; // add sync byte to beginning of packet
77 for (int i = 0; i < ATSC_MPEG_DATA_LENGTH; i++)
78 out.data[i + 1] = in.data[i] ^ output_and_clk ();
83 atsci_randomizer::slow_output_map (int st)