GNU Radio Manual and C++ API Reference 3.7.14.0
The Free & Open Software Radio Ecosystem
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{
38 friend class qa_atsci_randomizer;
39
40public:
42
43 /*! \brief reset randomizer LFSR
44 *
45 * must be called during the Data Segment Sync interval prior to the
46 * first data segment. I.e., the LFSR is reset prior to the first
47 * field of each VSB data frame.
48 */
49 void reset();
50
51 //! randomize (whiten) mpeg packet and remove leading MPEG-2 sync byte
53
54 //! derandomize (de-whiten) mpeg packet and add leading MPEG-2 sync byte
56
57 unsigned int state() const { return d_state; }
58
59private:
60 static void initialize_output_map();
61 static unsigned char slow_output_map(int st);
62
63 static unsigned char fast_output_map(int st)
64 {
65 return s_output_map[(st & 0xb23c) >>
66 2]; // Magic const with 8 bits set improves cache
67 // utilization. The bits correspond to the taps
68 // used in output calculation. Others may be
69 // safely ignored.
70 }
71
72 //! return current output value
73 unsigned char output() { return fast_output_map(d_state); }
74
75 //! clock LFSR; advance to next state.
76 void clk()
77 {
78 if (d_state & 0x1)
79 d_state = ((d_state ^ MASK) >> 1) | 0x8000;
80 else
81 d_state = d_state >> 1;
82 }
83
84 //! return current output value and advance to next state
85 unsigned char output_and_clk()
86 {
87 unsigned char r = output();
88 clk();
89 return r;
90 }
91
92 unsigned int d_state;
93
94 static const unsigned int PRELOAD_VALUE = 0x018f; /* 0xf180 bit reversed */
95 static const unsigned int MASK = 0xa638;
96 static unsigned char s_output_map[1 << 14];
97 static bool s_output_map_initialized_p;
98};
99
100#endif /* _ATSC_RANDOMIZER_H_ */
Definition: gr-atsc/include/gnuradio/atsc/types.h:166
Definition: gr-atsc/include/gnuradio/atsc/types.h:147
ATSC data "whitener".
Definition: randomizer_impl.h:37
void reset()
reset randomizer LFSR
unsigned int state() const
Definition: randomizer_impl.h:57
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
void randomize(atsc_mpeg_packet_no_sync &out, const atsc_mpeg_packet &in)
randomize (whiten) mpeg packet and remove leading MPEG-2 sync byte
#define ATSC_API
Definition: gr-atsc/include/gnuradio/atsc/api.h:30