Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

atsc_randomizer.h

Go to the documentation of this file.
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 2, 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., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  */
00022 
00023 #ifndef _ATSC_RANDOMIZER_H_
00024 #define _ATSC_RANDOMIZER_H_
00025 
00026 #include <atsc_types.h>
00027 
00035 class atsc_randomizer {
00036   friend class qa_atsc_randomizer;
00037   
00038  public:
00039   atsc_randomizer();
00040 
00047   void reset ();
00048 
00050   void randomize (atsc_mpeg_packet_no_sync &out, atsc_mpeg_packet &in);
00051 
00053   void derandomize (atsc_mpeg_packet &out, atsc_mpeg_packet_no_sync &in);
00054 
00055  private:
00056   static void initialize_output_map ();
00057   static unsigned char slow_output_map (int st);
00058 
00059   static unsigned char fast_output_map (int st){
00060     return output_map[(st & 0xb23c) >> 2]; // Magic const with 8 bits set improves cache 
00061                                            // utilization.  The bits correspond to the taps
00062                                            // used in output calculation.  Others may be 
00063                                            // safely ignored.
00064   }
00065     
00067   unsigned char output (){
00068     return fast_output_map (state);
00069   }
00070 
00072   void clk (){
00073     if (state & 0x1)
00074       state = ((state ^ mask) >> 1) | 0x8000;
00075     else
00076       state = state >> 1;
00077   }
00078 
00080   unsigned char output_and_clk (){
00081     unsigned char r = output ();
00082     clk ();
00083     return r;
00084   }
00085 
00086   unsigned int              state;
00087 
00088   static const unsigned int preload_value = 0x018f; /* 0xf180 bit reversed */
00089   static const unsigned int mask = 0xa638;
00090   static unsigned char      output_map[1 << 14];
00091   static bool               output_map_initialized_p;
00092 };
00093 
00094 #endif /* _ATSC_RANDOMIZER_H_ */

Generated on Tue Mar 15 23:48:03 2005 for GNU Radio by  doxygen 1.4.0