diff options
Diffstat (limited to 'gr-dtv/lib/atsc/atsc_randomize.h')
-rw-r--r-- | gr-dtv/lib/atsc/atsc_randomize.h | 109 |
1 files changed, 56 insertions, 53 deletions
diff --git a/gr-dtv/lib/atsc/atsc_randomize.h b/gr-dtv/lib/atsc/atsc_randomize.h index 0903240f48..48331cdab8 100644 --- a/gr-dtv/lib/atsc/atsc_randomize.h +++ b/gr-dtv/lib/atsc/atsc_randomize.h @@ -26,67 +26,70 @@ #include "atsc_types.h" namespace gr { - namespace dtv { +namespace dtv { - class atsc_randomize +class atsc_randomize +{ +public: + atsc_randomize(); + + /*! \brief reset randomizer LFSR + * + * must be called during the Data Segment Sync interval prior to the + * first data segment. I.e., the LFSR is reset prior to the first + * field of each VSB data frame. + */ + void reset(); + + //! randomize (whiten) mpeg packet and remove leading MPEG-2 sync byte + void randomize(atsc_mpeg_packet_no_sync& out, const atsc_mpeg_packet& in); + + //! derandomize (de-whiten) mpeg packet and add leading MPEG-2 sync byte + void derandomize(atsc_mpeg_packet& out, const atsc_mpeg_packet_no_sync& in); + + unsigned int state() const { return d_state; } + +private: + static void initialize_output_map(); + static unsigned char slow_output_map(int st); + + static unsigned char fast_output_map(int st) + { + return s_output_map[(st & 0xb23c) >> + 2]; // Magic const with 8 bits set improves cache + // utilization. The bits correspond to the taps + // used in output calculation. Others may be + // safely ignored. + } + + //! return current output value + unsigned char output() { return fast_output_map(d_state); } + + //! clock LFSR; advance to next state. + void clk() { - public: - atsc_randomize(); - - /*! \brief reset randomizer LFSR - * - * must be called during the Data Segment Sync interval prior to the - * first data segment. I.e., the LFSR is reset prior to the first - * field of each VSB data frame. - */ - void reset (); - - //! randomize (whiten) mpeg packet and remove leading MPEG-2 sync byte - void randomize (atsc_mpeg_packet_no_sync &out, const atsc_mpeg_packet &in); - - //! derandomize (de-whiten) mpeg packet and add leading MPEG-2 sync byte - void derandomize (atsc_mpeg_packet &out, const atsc_mpeg_packet_no_sync &in); - - unsigned int state() const { return d_state; } - private: - static void initialize_output_map (); - static unsigned char slow_output_map (int st); - - static unsigned char fast_output_map (int st){ - return s_output_map[(st & 0xb23c) >> 2]; // Magic const with 8 bits set improves cache - // utilization. The bits correspond to the taps - // used in output calculation. Others may be - // safely ignored. - } - - //! return current output value - unsigned char output (){ - return fast_output_map (d_state); - } - - //! clock LFSR; advance to next state. - void clk (){ if (d_state & 0x1) - d_state = ((d_state ^ MASK) >> 1) | 0x8000; + d_state = ((d_state ^ MASK) >> 1) | 0x8000; else - d_state = d_state >> 1; - } + d_state = d_state >> 1; + } - //! return current output value and advance to next state - unsigned char output_and_clk (){ - unsigned char r = output (); - clk (); + //! return current output value and advance to next state + unsigned char output_and_clk() + { + unsigned char r = output(); + clk(); return r; - } + } - unsigned int d_state; + unsigned int d_state; - static const unsigned int PRELOAD_VALUE = 0x018f; /* 0xf180 bit reversed */ - static const unsigned int MASK = 0xa638; - static unsigned char s_output_map[1 << 14]; - static bool s_output_map_initialized_p; - }; - } /* namespace dtv */ + static const unsigned int PRELOAD_VALUE = 0x018f; /* 0xf180 bit reversed */ + static const unsigned int MASK = 0xa638; + static unsigned char s_output_map[1 << 14]; + static bool s_output_map_initialized_p; +}; +} /* namespace dtv */ } /* namespace gr */ #endif /* INCLUDED_ATSC_RANDOMIZE_H */ |