GNU Radio 3.3.0 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2001 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef _ATSC_RANDOMIZER_H_ 00024 #define _ATSC_RANDOMIZER_H_ 00025 00026 #include <atsc_types.h> 00027 00028 /*! 00029 * \brief ATSC data "whitener" 00030 * 00031 * The data randomizer described in ATSC standard A/53B. 00032 * See figure D4 on page 54. 00033 */ 00034 00035 class atsci_randomizer { 00036 friend class qa_atsci_randomizer; 00037 00038 public: 00039 atsci_randomizer(); 00040 00041 /*! \brief reset randomizer LFSR 00042 * 00043 * must be called during the Data Segment Sync interval prior to the 00044 * first data segment. I.e., the LFSR is reset prior to the first 00045 * field of each VSB data frame. 00046 */ 00047 void reset (); 00048 00049 //! randomize (whiten) mpeg packet and remove leading MPEG-2 sync byte 00050 void randomize (atsc_mpeg_packet_no_sync &out, const atsc_mpeg_packet &in); 00051 00052 //! derandomize (de-whiten) mpeg packet and add leading MPEG-2 sync byte 00053 void derandomize (atsc_mpeg_packet &out, const atsc_mpeg_packet_no_sync &in); 00054 00055 unsigned int state() const { return d_state; } 00056 00057 private: 00058 static void initialize_output_map (); 00059 static unsigned char slow_output_map (int st); 00060 00061 static unsigned char fast_output_map (int st){ 00062 return s_output_map[(st & 0xb23c) >> 2]; // Magic const with 8 bits set improves cache 00063 // utilization. The bits correspond to the taps 00064 // used in output calculation. Others may be 00065 // safely ignored. 00066 } 00067 00068 //! return current output value 00069 unsigned char output (){ 00070 return fast_output_map (d_state); 00071 } 00072 00073 //! clock LFSR; advance to next state. 00074 void clk (){ 00075 if (d_state & 0x1) 00076 d_state = ((d_state ^ MASK) >> 1) | 0x8000; 00077 else 00078 d_state = d_state >> 1; 00079 } 00080 00081 //! return current output value and advance to next state 00082 unsigned char output_and_clk (){ 00083 unsigned char r = output (); 00084 clk (); 00085 return r; 00086 } 00087 00088 unsigned int d_state; 00089 00090 static const unsigned int PRELOAD_VALUE = 0x018f; /* 0xf180 bit reversed */ 00091 static const unsigned int MASK = 0xa638; 00092 static unsigned char s_output_map[1 << 14]; 00093 static bool s_output_map_initialized_p; 00094 }; 00095 00096 #endif /* _ATSC_RANDOMIZER_H_ */