GNU Radio Manual and C++ API Reference  3.7.5.1
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
atsc_randomize.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2014 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 INCLUDED_ATSC_RANDOMIZE_H
24 #define INCLUDED_ATSC_RANDOMIZE_H
25 
26 #include "atsc_types.h"
27 
28 namespace gr {
29  namespace dtv {
30 
32  {
33  public:
35 
36  /*! \brief reset randomizer LFSR
37  *
38  * must be called during the Data Segment Sync interval prior to the
39  * first data segment. I.e., the LFSR is reset prior to the first
40  * field of each VSB data frame.
41  */
42  void reset ();
43 
44  //! randomize (whiten) mpeg packet and remove leading MPEG-2 sync byte
46 
47  //! derandomize (de-whiten) mpeg packet and add leading MPEG-2 sync byte
49 
50  unsigned int state() const { return d_state; }
51  private:
52  static void initialize_output_map ();
53  static unsigned char slow_output_map (int st);
54 
55  static unsigned char fast_output_map (int st){
56  return s_output_map[(st & 0xb23c) >> 2]; // Magic const with 8 bits set improves cache
57  // utilization. The bits correspond to the taps
58  // used in output calculation. Others may be
59  // safely ignored.
60  }
61 
62  //! return current output value
63  unsigned char output (){
64  return fast_output_map (d_state);
65  }
66 
67  //! clock LFSR; advance to next state.
68  void clk (){
69  if (d_state & 0x1)
70  d_state = ((d_state ^ MASK) >> 1) | 0x8000;
71  else
72  d_state = d_state >> 1;
73  }
74 
75  //! return current output value and advance to next state
76  unsigned char output_and_clk (){
77  unsigned char r = output ();
78  clk ();
79  return r;
80  }
81 
82  unsigned int d_state;
83 
84  static const unsigned int PRELOAD_VALUE = 0x018f; /* 0xf180 bit reversed */
85  static const unsigned int MASK = 0xa638;
86  static unsigned char s_output_map[1 << 14];
87  static bool s_output_map_initialized_p;
88  };
89  } /* namespace dtv */
90 } /* namespace gr */
91 
92 #endif /* INCLUDED_ATSC_RANDOMIZE_H */
void reset()
reset randomizer LFSR
Definition: atsc_types.h:189
Definition: atsc_randomize.h:31
Definition: atsc_types.h:173
void randomize(atsc_mpeg_packet_no_sync &out, const atsc_mpeg_packet &in)
randomize (whiten) mpeg packet and remove leading MPEG-2 sync byte
void derandomize(atsc_mpeg_packet &out, const atsc_mpeg_packet_no_sync &in)
derandomize (de-whiten) mpeg packet and add leading MPEG-2 sync byte
unsigned int state() const
Definition: atsc_randomize.h:50