3 * Copyright 2001 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 #ifndef _ATSC_RANDOMIZER_H_
24 #define _ATSC_RANDOMIZER_H_
26 #include <atsc_types.h>
29 * \brief ATSC data "whitener"
31 * The data randomizer described in ATSC standard A/53B.
32 * See figure D4 on page 54.
35 class atsci_randomizer {
36 friend class qa_atsci_randomizer;
41 /*! \brief reset randomizer LFSR
43 * must be called during the Data Segment Sync interval prior to the
44 * first data segment. I.e., the LFSR is reset prior to the first
45 * field of each VSB data frame.
49 //! randomize (whiten) mpeg packet and remove leading MPEG-2 sync byte
50 void randomize (atsc_mpeg_packet_no_sync &out, const atsc_mpeg_packet &in);
52 //! derandomize (de-whiten) mpeg packet and add leading MPEG-2 sync byte
53 void derandomize (atsc_mpeg_packet &out, const atsc_mpeg_packet_no_sync &in);
55 unsigned int state() const { return d_state; }
58 static void initialize_output_map ();
59 static unsigned char slow_output_map (int st);
61 static unsigned char fast_output_map (int st){
62 return s_output_map[(st & 0xb23c) >> 2]; // Magic const with 8 bits set improves cache
63 // utilization. The bits correspond to the taps
64 // used in output calculation. Others may be
68 //! return current output value
69 unsigned char output (){
70 return fast_output_map (d_state);
73 //! clock LFSR; advance to next state.
76 d_state = ((d_state ^ MASK) >> 1) | 0x8000;
78 d_state = d_state >> 1;
81 //! return current output value and advance to next state
82 unsigned char output_and_clk (){
83 unsigned char r = output ();
90 static const unsigned int PRELOAD_VALUE = 0x018f; /* 0xf180 bit reversed */
91 static const unsigned int MASK = 0xa638;
92 static unsigned char s_output_map[1 << 14];
93 static bool s_output_map_initialized_p;
96 #endif /* _ATSC_RANDOMIZER_H_ */