GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
randomizer_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2001 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22 
23 #ifndef _ATSC_RANDOMIZER_H_
24 #define _ATSC_RANDOMIZER_H_
25 
26 #include <gnuradio/atsc/api.h>
27 #include <gnuradio/atsc/types.h>
28 
29 /*!
30  * \brief ATSC data "whitener"
31  *
32  * The data randomizer described in ATSC standard A/53B.
33  * See figure D4 on page 54.
34  */
35 
37  friend class qa_atsci_randomizer;
38 
39  public:
41 
42  /*! \brief reset randomizer LFSR
43  *
44  * must be called during the Data Segment Sync interval prior to the
45  * first data segment. I.e., the LFSR is reset prior to the first
46  * field of each VSB data frame.
47  */
48  void reset ();
49 
50  //! randomize (whiten) mpeg packet and remove leading MPEG-2 sync byte
51  void randomize (atsc_mpeg_packet_no_sync &out, const atsc_mpeg_packet &in);
52 
53  //! derandomize (de-whiten) mpeg packet and add leading MPEG-2 sync byte
54  void derandomize (atsc_mpeg_packet &out, const atsc_mpeg_packet_no_sync &in);
55 
56  unsigned int state() const { return d_state; }
57 
58  private:
59  static void initialize_output_map ();
60  static unsigned char slow_output_map (int st);
61 
62  static unsigned char fast_output_map (int st){
63  return s_output_map[(st & 0xb23c) >> 2]; // Magic const with 8 bits set improves cache
64  // utilization. The bits correspond to the taps
65  // used in output calculation. Others may be
66  // safely ignored.
67  }
68 
69  //! return current output value
70  unsigned char output (){
71  return fast_output_map (d_state);
72  }
73 
74  //! clock LFSR; advance to next state.
75  void clk (){
76  if (d_state & 0x1)
77  d_state = ((d_state ^ MASK) >> 1) | 0x8000;
78  else
79  d_state = d_state >> 1;
80  }
81 
82  //! return current output value and advance to next state
83  unsigned char output_and_clk (){
84  unsigned char r = output ();
85  clk ();
86  return r;
87  }
88 
89  unsigned int d_state;
90 
91  static const unsigned int PRELOAD_VALUE = 0x018f; /* 0xf180 bit reversed */
92  static const unsigned int MASK = 0xa638;
93  static unsigned char s_output_map[1 << 14];
94  static bool s_output_map_initialized_p;
95 };
96 
97 #endif /* _ATSC_RANDOMIZER_H_ */
#define ATSC_API
Definition: gr-atsc/include/gnuradio/atsc/api.h:30
Definition: gr-atsc/include/gnuradio/atsc/types.h:160
Definition: gr-atsc/include/gnuradio/atsc/types.h:144
unsigned int state() const
Definition: randomizer_impl.h:56
ATSC data "whitener".
Definition: randomizer_impl.h:36