atsci_randomizer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _ATSC_RANDOMIZER_H_
00024 #define _ATSC_RANDOMIZER_H_
00025
00026 #include <atsc_types.h>
00027
00035 class atsci_randomizer {
00036 friend class qa_atsci_randomizer;
00037
00038 public:
00039 atsci_randomizer();
00040
00047 void reset ();
00048
00050 void randomize (atsc_mpeg_packet_no_sync &out, const atsc_mpeg_packet &in);
00051
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];
00063
00064
00065
00066 }
00067
00069 unsigned char output (){
00070 return fast_output_map (d_state);
00071 }
00072
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
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;
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