diff options
Diffstat (limited to 'gr-atsc/include')
76 files changed, 5129 insertions, 0 deletions
diff --git a/gr-atsc/include/atsc/CMakeLists.txt b/gr-atsc/include/atsc/CMakeLists.txt new file mode 100644 index 0000000000..cdf818aab2 --- /dev/null +++ b/gr-atsc/include/atsc/CMakeLists.txt @@ -0,0 +1,103 @@ +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +######################################################################## +# Install header files +######################################################################## +install(FILES + api.h + basic_trellis_encoder_impl.h + bit_timing_loop.h + CMakeLists.txt + consts.h + convolutional_interleaver.h + create_atsci_equalizer.h + create_atsci_fs_checker.h + create_atsci_fs_correlator.h + data_interleaver_impl.h + deinterleaver.h + depad.h + derandomizer.h + diag_output_impl.h + ds_to_softds.h + equalizer.h + equalizer_impl.h + equalizer_lms2_impl.h + equalizer_lms_impl.h + equalizer_nop_impl.h + exp2_lp_impl.h + fake_single_viterbi_impl.h + field_sync_demux.h + field_sync_mux.h + fpll.h + fs_checker.h + fs_checker_impl.h + fs_checker_naive_impl.h + fs_correlator_impl.h + fs_correlator_naive_impl.h + GrAtscBitTimingLoop2.h + GrAtscBitTimingLoop3.h + GrAtscBitTimingLoop.h + GrAtscConvert2xTo20.h + GrAtscDataSegToSoftDataSeg.h + GrAtscDeinterleaver.h + GrAtscDerandomizer.h + GrAtscEqualizer.h + GrAtscFieldSyncChecker.h + GrAtscFieldSyncCorrelator.h + GrAtscFieldSyncDemux.h + GrAtscFieldSyncMux.h + GrAtscFPLL.h + GrAtscInterleaver.h + GrAtscRandomizer.h + GrAtscRSDecoder.h + GrAtscRSEncoder.h + GrAtscSegSymSync.h + GrAtscSegSymSyncImpl_export.h + GrAtscSegSymSyncImpl.h + GrAtscSymbolMapper.h + GrAtscTrellisEncoder.h + GrAtscViterbiDecoder.h + interleaver_fifo.h + interleaver.h + pad.h + pnXXX_impl.h + randomizer.h + randomizer_impl.h + reed_solomon_impl.h + root_raised_cosine_bandpass_impl.h + root_raised_cosine_impl.h + rs_decoder.h + rs_encoder.h + single_viterbi_impl.h + slicer_agc_impl.h + sliding_correlator_impl.h + sssr_impl.h + syminfo_impl.h + sync_tag_impl.h + trellis_encoder.h + trellis_encoder_impl.h + types.h + viterbi_decoder.h + viterbi_decoder_impl.h + vsbtx_lp_impl.h + DESTINATION ${GR_INCLUDE_DIR}/gnuradio/atsc + COMPONENT "atsc_devel" +) + diff --git a/gr-atsc/include/atsc/GrAtscBitTimingLoop.h b/gr-atsc/include/atsc/GrAtscBitTimingLoop.h new file mode 100644 index 0000000000..1bedbb39ec --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscBitTimingLoop.h @@ -0,0 +1,90 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCBITTIMINGLOOP_H_ +#define _GRATSCBITTIMINGLOOP_H_ + +#include <blocks/nco.h> +#include <VrSigProc.h> +#include <VrHistoryProc.h> +#include <VrDecimatingSigProc.h> +#include <atsc/interleaver_fifo.h> +#include <filter/single_pole_iir.h> +#include <filter/mmse_fir_interpolator.h> +#include <atsc/slicer_agc_impl.h> +#include <stdio.h> +#include <atsc/diag_output_impl.h> + + +/*! + * \brief ATSC BitTimingLoop + * + * This class accepts a single real input and produces a single real output + */ + +class GrAtscBitTimingLoop : public VrDecimatingSigProc<float,float> { + + public: + + GrAtscBitTimingLoop (); + virtual ~GrAtscBitTimingLoop () { }; + + virtual const char *name () { return "GrAtscBitTimingLoop"; } + + virtual int forecast (VrSampleRange output, + VrSampleRange inputs[]); + + virtual int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + + // debug + void set_mu (double a_mu) { mu = a_mu; } + void set_no_update (bool a_no_update) { debug_no_update = a_no_update; } + void set_loop_filter_tap (double tap) { loop.set_taps (tap); } + void set_timing_rate (double rate) { d_timing_rate = rate; } + + protected: + + typedef float iType; + typedef float oType; + + iType produce_sample (const iType *in, unsigned int &index); + double filter_error (double e); + + VrSampleIndex next_input; + gr_mmse_fir_interpolator intr; + double w; // timing control word + double mu; // fractional delay + iType last_right; // last right hand sample + gr_single_pole_iir<double,double,double> loop; + bool debug_no_update;// debug + + double d_loop_filter_tap; + double d_timing_rate; + +#ifdef _BT_DIAG_OUTPUT_ + FILE *fp_loop; + FILE *fp_ps; +#endif +}; + +#endif // _GRATSCBITTIMINGLOOP_H_ diff --git a/gr-atsc/include/atsc/GrAtscBitTimingLoop2.h b/gr-atsc/include/atsc/GrAtscBitTimingLoop2.h new file mode 100644 index 0000000000..64d25da01e --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscBitTimingLoop2.h @@ -0,0 +1,80 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCBITTIMINGLOOP2_H_ +#define _GRATSCBITTIMINGLOOP2_H_ + +#include <blocks/nco.h> +#include <VrSigProc.h> +#include <VrHistoryProc.h> +#include <VrDecimatingSigProc.h> +#include <atsc/interleaver_fifo.h> +#include <filtersingle_pole_iir.h> +#include <filter/mmse_fir_interpolator.h> + +/*! + * \brief ATSC BitTimingLoop + * + * This class accepts a single real input and produces a single real output + */ + +class GrAtscBitTimingLoop2 : public VrDecimatingSigProc<float,float> { + + public: + + GrAtscBitTimingLoop2 (); + virtual ~GrAtscBitTimingLoop2 () { }; + + virtual const char *name () { return "GrAtscBitTimingLoop2"; } + + virtual int forecast (VrSampleRange output, + VrSampleRange inputs[]); + + virtual int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + + // debug + void set_mu (float a_mu) { + assert (0 <= a_mu && a_mu <= 1.9); + use_right_p = a_mu < 1.0; + mu = a_mu - floor (a_mu); + cerr << "BTL2: mu: " << mu << " use_right_p: " << use_right_p << endl; + } + + protected: + + typedef float iType; + typedef float oType; + + iType produce_sample (const iType *in, unsigned int &index); + float filter_error (float e); + + VrSampleIndex next_input; + gr_single_pole_iir<float,float,float> dc; // used to estimate DC component + gr_mmse_fir_interpolator intr; + float mu; // fractional delay + iType last_right; // last right hand sample + + bool use_right_p; // ...else middle +}; + +#endif // _GRATSCBITTIMINGLOOP2_H_ diff --git a/gr-atsc/include/atsc/GrAtscBitTimingLoop3.h b/gr-atsc/include/atsc/GrAtscBitTimingLoop3.h new file mode 100644 index 0000000000..c0fb333ace --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscBitTimingLoop3.h @@ -0,0 +1,72 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCBITTIMINGLOOP3_H_ +#define _GRATSCBITTIMINGLOOP3_H_ + +#include <cstdio> +#include <VrDecimatingSigProc.h> +#include <atsc/diag_output_impl.h> +#include <atsc/sssr_impl.h> +#include <atsc/syminfo_impl.h> + +/*! + * \brief ATSC BitTimingLoop3 + * + * This class accepts a single real input and produces two outputs, + * the raw symbol (float) and the tag (atsc_syminfo) + */ + +class GrAtscBitTimingLoop3 : public VrDecimatingSigProc<float,float> { + + public: + + GrAtscBitTimingLoop3 (double ratio_of_rx_clock_to_symbol_freq); + virtual ~GrAtscBitTimingLoop3 () { }; + + virtual const char *name () { return "GrAtscBitTimingLoop3"; } + + virtual int forecast (VrSampleRange output, + VrSampleRange inputs[]); + + virtual int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + + // debug (NOPs) + void set_mu (double a_mu) { } + void set_no_update (bool a_no_update) { } + void set_loop_filter_tap (double tap) { } + void set_timing_rate (double rate) { } + + protected: + + typedef float iType; + typedef float oDataType; + typedef atsc::syminfo oTagType; + + atsci_sssr d_sssr; + atsci_interpolator d_interp; + VrSampleIndex d_next_input; + double d_rx_clock_to_symbol_freq; +}; + +#endif // _GRATSCBITTIMINGLOOP3_H_ diff --git a/gr-atsc/include/atsc/GrAtscConvert2xTo20.h b/gr-atsc/include/atsc/GrAtscConvert2xTo20.h new file mode 100644 index 0000000000..47ea4fb593 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscConvert2xTo20.h @@ -0,0 +1,50 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef _GRATSCCONVERT2XTO20_H_ +#define _GRATSCCONVERT2XTO20_H_ + +#include <VrDecimatingSigProc.h> +#include <filter/mmse_fir_interpolator.h> + +class GrAtscConvert2xTo20 : public VrDecimatingSigProc<float,float> { + gr_mmse_fir_interpolator d_interp; + double d_frac_part; + VrSampleIndex d_next_input; + +public: + GrAtscConvert2xTo20 (); + ~GrAtscConvert2xTo20 (); + + virtual const char *name () { return "GrAtscConvert2xTo20"; } + + virtual int forecast (VrSampleRange output, + VrSampleRange inputs[]); + + virtual int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + + void pre_initialize (); + int checkOutputSamplingFrequency(float) { return 0; } // bogus, but required + +}; + +#endif /* _GRATSCCONVERT2XTO20_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscDataSegToSoftDataSeg.h b/gr-atsc/include/atsc/GrAtscDataSegToSoftDataSeg.h new file mode 100644 index 0000000000..5fcb894321 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscDataSegToSoftDataSeg.h @@ -0,0 +1,50 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCDATASEGTOSOFTDATASEG_H_ +#define _GRATSCDATASEGTOSOFTDATASEG_H_ + +#include <VrHistoryProc.h> +#include <atsc/types.h> + +/*! + * \brief Debug glue routine (atsc_data_segment --> atsc_soft_data_segment) + */ + +class GrAtscDataSegToSoftDataSeg : public VrHistoryProc<atsc_data_segment, + atsc_soft_data_segment> +{ + +public: + + GrAtscDataSegToSoftDataSeg (); + ~GrAtscDataSegToSoftDataSeg (); + + const char *name () { return "GrAtscDataSegToSoftDataSeg"; } + + int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + +protected: +}; + +#endif /* _GRATSCDATASEGTOSOFTDATASEG_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscDeinterleaver.h b/gr-atsc/include/atsc/GrAtscDeinterleaver.h new file mode 100644 index 0000000000..8b602fa2dc --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscDeinterleaver.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCDEINTERLEAVER_H_ +#define _GRATSCDEINTERLEAVER_H_ + +#include <VrHistoryProc.h> +#include <atsc/types.h> +#include <atsc/data_interleaver_impl.h> + +/*! + * \brief Deinterleave RS encoded ATSC data ( atsc_mpeg_packet_rs_encoded --> atsc_mpeg_packet_rs_encoded) + */ + +class GrAtscDeinterleaver : public VrHistoryProc<atsc_mpeg_packet_rs_encoded, atsc_mpeg_packet_rs_encoded> +{ + +public: + + GrAtscDeinterleaver (); + ~GrAtscDeinterleaver (); + + const char *name () { return "GrAtscDeinterleaver"; } + + int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + +protected: + atsci_data_deinterleaver deinterleaver; +}; + +#endif /* _GRATSCDEINTERLEAVER_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscDerandomizer.h b/gr-atsc/include/atsc/GrAtscDerandomizer.h new file mode 100644 index 0000000000..0075ae2998 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscDerandomizer.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCDERANDOMIZER_H_ +#define _GRATSCDERANDOMIZER_H_ + +#include <VrHistoryProc.h> +#include <atsc/types.h> +#include <atsc/randomizer_impl.h> + +/*! + * \brief Derandomize ATSC data (atsc_mpeg_packet_no_sync --> atsc_mpeg_packet) + */ + +class GrAtscDerandomizer : public VrHistoryProc<atsc_mpeg_packet_no_sync, atsc_mpeg_packet> +{ + +public: + + GrAtscDerandomizer (); + ~GrAtscDerandomizer (); + + const char *name () { return "GrAtscDerandomizer"; } + + virtual int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + +protected: + atsci_randomizer rand; +}; + +#endif /* _GRATSCDERANDOMIZER_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscEqualizer.h b/gr-atsc/include/atsc/GrAtscEqualizer.h new file mode 100644 index 0000000000..ff944deb7d --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscEqualizer.h @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCEQUALIZER_H_ +#define _GRATSCEQUALIZER_H_ + +#include <VrHistoryProc.h> + +class atsci_equalizer; + +/*! + * \brief ATSC equalizer (float,syminfo --> float,syminfo) + * + * first inputs are data samples, second inputs are tags. + * first outputs are equalized data samples, second outputs are tags. + * + * tag values are defined in atsci_syminfo.h + */ + +class GrAtscEqualizer : public VrHistoryProc<float,float> +{ + +public: + + GrAtscEqualizer (atsci_equalizer *equalizer); + ~GrAtscEqualizer (); + + const char *name () { return "GrAtscEqualizer"; } + + int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + + // we've got a non-standard forecast routine + int forecast (VrSampleRange output, VrSampleRange inputs[]); + +protected: + atsci_equalizer *d_equalizer; +}; + +#endif /* _GRATSCEQUALIZER_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscFPLL.h b/gr-atsc/include/atsc/GrAtscFPLL.h new file mode 100644 index 0000000000..c1e3302a17 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscFPLL.h @@ -0,0 +1,88 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + + +#ifndef _GRATSCFPLL_H_ +#define _GRATSCFPLL_H_ + +#include <blocks/nco.h> +#include <filter/iir.h> +#include <filter/single_pole_iir.h> +#include <analog/agc.h> +#include <VrSigProc.h> +#include <stdio.h> +#include <atsc/diag_output_impl.h> + +/*! + * \brief ATSC FPLL (2nd Version) + * + * Used as follows: + * float float + * A/D --> GrFIRfilterFFF ----> GrAtscFPLL ----> + * + * We use GrFIRfilterFFF to bandpass filter the signal of interest. + * + * This class accepts a single real input and produces a single real output + */ + +class GrAtscFPLL : public VrSigProc { + protected: + + typedef float iType; + typedef float oType; + + public: + + GrAtscFPLL (double a_initial_freq); + virtual ~GrAtscFPLL () {} + + virtual const char *name () { return "GrAtscFPLL"; } + + virtual void initialize (); + + virtual int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + + + // diagnostic routines + void set_initial_phase (double phase) { initial_phase = phase; } // radians + void set_no_update (bool a_no_update) { debug_no_update = a_no_update; } + + + protected: + + double initial_freq; + double initial_phase; + bool debug_no_update; + gr_nco<float,float> nco; + gr_agc agc; // automatic gain control + gr_single_pole_iir<float,float,float> afci; + gr_single_pole_iir<float,float,float> afcq; + +#ifdef _FPLL_DIAG_OUTPUT_ + FILE *fp; +#endif + +}; + + +#endif // _GRATSCFPLL_H_ diff --git a/gr-atsc/include/atsc/GrAtscFieldSyncChecker.h b/gr-atsc/include/atsc/GrAtscFieldSyncChecker.h new file mode 100644 index 0000000000..28458a19b5 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscFieldSyncChecker.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCFIELDSYNCCHECKER_H_ +#define _GRATSCFIELDSYNCCHECKER_H_ + +#include <VrHistoryProc.h> + +class atsci_fs_checker; + +/*! + * \brief ATSC field sync checker (float,syminfo --> float,syminfo) + * + * first output is delayed version of input. + * second output is set of tags, one-for-one with first output. + */ + +class GrAtscFieldSyncChecker : public VrHistoryProc<float,float> +{ + +public: + + GrAtscFieldSyncChecker (); + ~GrAtscFieldSyncChecker (); + + const char *name () { return "GrAtscFieldSyncChecker"; } + + int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + +protected: + atsci_fs_checker *d_fsc; +}; + +#endif /* _GRATSCFIELDSYNCCHECKER_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscFieldSyncCorrelator.h b/gr-atsc/include/atsc/GrAtscFieldSyncCorrelator.h new file mode 100644 index 0000000000..1a16048b22 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscFieldSyncCorrelator.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCFIELDSYNCCORRELATOR_H_ +#define _GRATSCFIELDSYNCCORRELATOR_H_ + +#include <VrHistoryProc.h> + +class atsci_fs_correlator; + +/*! + * \brief ATSC field sync correlator (float --> float,float) + * + * first output is delayed version of input. + * second output is set of tags, one-for-one with first output. + * + * tag values are defined in atsci_sync_tag.h + */ + +class GrAtscFieldSyncCorrelator : public VrHistoryProc<float,float> +{ + +public: + + GrAtscFieldSyncCorrelator (); + ~GrAtscFieldSyncCorrelator (); + + const char *name () { return "GrAtscFieldSyncCorrelator"; } + + int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + +protected: + atsci_fs_correlator *d_fsc; +}; + +#endif /* _GRATSCFIELDSYNCCORRELATOR_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscFieldSyncDemux.h b/gr-atsc/include/atsc/GrAtscFieldSyncDemux.h new file mode 100644 index 0000000000..248c257914 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscFieldSyncDemux.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCFIELDSYNCDEMUX_H_ +#define _GRATSCFIELDSYNCDEMUX_H_ + +#include <VrDecimatingSigProc.h> +#include <atsc/types.h> + +/*! + * \brief ATSC Field Sync Demux + * + * This class accepts 1 stream of floats (data), and 1 stream of tags (syminfo). + * It outputs one stream of atsc_soft_data_segment packets + */ + +class GrAtscFieldSyncDemux : public VrDecimatingSigProc<float,atsc_soft_data_segment> { + + public: + + GrAtscFieldSyncDemux (); + virtual ~GrAtscFieldSyncDemux (); + + virtual const char *name () { return "GrAtscFieldSyncDemux"; } + + virtual int forecast (VrSampleRange output, + VrSampleRange inputs[]); + + virtual int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + + protected: + + bool d_locked; + bool d_in_field2; + int d_segment_number; + VrSampleIndex d_next_input; + VrSampleIndex d_lost_index; // diagnostic fluff +}; + +#endif // _GRATSCFIELDSYNCDEMUX_H_ diff --git a/gr-atsc/include/atsc/GrAtscFieldSyncMux.h b/gr-atsc/include/atsc/GrAtscFieldSyncMux.h new file mode 100644 index 0000000000..3045f32846 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscFieldSyncMux.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCFIELDSYNCMUX_H_ +#define _GRATSCFIELDSYNCMUX_H_ + +#include <VrHistoryProc.h> +#include <atsc/types.h> + +/*! + * \brief Insert ATSC Field Syncs as required (atsc_data_segment --> atsc_data_segment) + */ + +class GrAtscFieldSyncMux : public VrHistoryProc<atsc_data_segment, atsc_data_segment> +{ + +public: + + GrAtscFieldSyncMux (); + ~GrAtscFieldSyncMux (); + + const char *name () { return "GrAtscFieldSyncMux"; } + + int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + + int forecast (VrSampleRange output, VrSampleRange inputs[]); + + void pre_initialize (); + + static const int N_SAVED_SYMBOLS = 12; + +protected: + VrSampleIndex d_current_index; + bool d_already_output_field_sync; + unsigned char d_saved_symbols[N_SAVED_SYMBOLS]; +}; + +#endif /* _GRATSCFIELDSYNCMUX_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscInterleaver.h b/gr-atsc/include/atsc/GrAtscInterleaver.h new file mode 100644 index 0000000000..5b6ad4849c --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscInterleaver.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCINTERLEAVER_H_ +#define _GRATSCINTERLEAVER_H_ + +#include <VrHistoryProc.h> +#include <atsc/types.h> +#include <atsc/data_interleaver_impl.h> + +/*! + * \brief Interleave RS encoded ATSC data ( atsc_mpeg_packet_rs_encoded --> atsc_mpeg_packet_rs_encoded) + */ + +class GrAtscInterleaver : public VrHistoryProc<atsc_mpeg_packet_rs_encoded, atsc_mpeg_packet_rs_encoded> +{ + +public: + + GrAtscInterleaver (); + ~GrAtscInterleaver (); + + const char *name () { return "GrAtscInterleaver"; } + + int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + +protected: + atsci_data_interleaver interleaver; +}; + +#endif /* _GRATSCINTERLEAVER_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscRSDecoder.h b/gr-atsc/include/atsc/GrAtscRSDecoder.h new file mode 100644 index 0000000000..9321b66a5b --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscRSDecoder.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCRSDECODER_H_ +#define _GRATSCRSDECODER_H_ + +#include <VrHistoryProc.h> +#include <atsc/types.h> +#include <atsc/reed_solomon_impl.h> + +/*! + * \brief Pass ATSC data Reed-Solomon decoder( atsc_mpeg_packet_rs_encoded --> atsc_mpeg_rs_no_sync) + */ + +class GrAtscRSDecoder : public VrHistoryProc<atsc_mpeg_packet_rs_encoded, atsc_mpeg_packet_no_sync> +{ + +public: + + GrAtscRSDecoder (); + ~GrAtscRSDecoder (); + + const char *name () { return "GrAtscRSDecoder"; } + + virtual int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + +protected: + atsci_reed_solomon rs_decoder; +}; + +#endif /* _GRATSCRSDECODER_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscRSEncoder.h b/gr-atsc/include/atsc/GrAtscRSEncoder.h new file mode 100644 index 0000000000..e18b6bd63f --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscRSEncoder.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCRSENCODER_H_ +#define _GRATSCRSENCODER_H_ + +#include <VrHistoryProc.h> +#include <atsc/types.h> +#include <atsc/reed_solomon_impl.h> + +/*! + * \brief Encode using Reed Solomon ATSC data (atsc_mpeg_packet_no_sync --> atsc_mpeg_packet_rs_encoded) + */ + +class GrAtscRSEncoder : public VrHistoryProc<atsc_mpeg_packet_no_sync, atsc_mpeg_packet_rs_encoded> +{ + +public: + + GrAtscRSEncoder (); + ~GrAtscRSEncoder (); + + const char *name () { return "GrAtscRSEncoder"; } + + int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + +protected: + atsci_reed_solomon rs_encoder; +}; + +#endif /* _GRATSCRSENCODER_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscRandomizer.h b/gr-atsc/include/atsc/GrAtscRandomizer.h new file mode 100644 index 0000000000..565ea7b8eb --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscRandomizer.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCRANDOMIZER_H_ +#define _GRATSCRANDOMIZER_H_ + +#include <VrHistoryProc.h> +#include <atsc/types.h> +#include <atsc/randomizer_impl.h> + +/*! + * \brief Randomize ATSC data (atsc_mpeg_packet --> atsc_mpeg_packet_no_sync) + */ + +class GrAtscRandomizer : public VrHistoryProc<atsc_mpeg_packet, atsc_mpeg_packet_no_sync> +{ + +public: + + GrAtscRandomizer (); + ~GrAtscRandomizer (); + + const char *name () { return "GrAtscRandomizer"; } + + int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + +protected: + atsci_randomizer rand; + + // used to initialize plinfo in output + bool field2; + int segno; +}; + +#endif /* _GRATSCRANDOMIZER_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscSegSymSync.h b/gr-atsc/include/atsc/GrAtscSegSymSync.h new file mode 100644 index 0000000000..750483f544 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscSegSymSync.h @@ -0,0 +1,64 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCSEGSYMSYNC_H_ +#define _GRATSCSEGSYMSYNC_H_ + +#include <VrDecimatingSigProc.h> + +/*! + * \brief ATSC SegSymSync + * + * Abstract class that establishes symbol timing and synchronizes + * with data segment boundaries. + * + * Takes a single stream of floats as the input and + * produces two streams as output. The first stream is the data samples + * and is of type float. The second stream is the tags, and is of type syminfo. + * + * The current GNU Radio interface doesn't currently support different + * types on the input ports (or output ports for that matter), but + * since they are the same size, it works. + */ + +#include <atsci_syminfo.h> + +class GrAtscSegSymSync : public VrDecimatingSigProc<float,float> { + +public: + + GrAtscSegSymSync (); + ~GrAtscSegSymSync (); + + /*! + * \brief reset bit timing loop on channel change + */ + virtual void reset () = 0; + + /*! + * \brief create an instance of GrAtscSegSymSync + */ + static GrAtscSegSymSync *create (double nominal_ratio_of_rx_clock_to_symbol_freq); + +}; + +#endif // _GRATSCSEGSYMSYNC_H_ diff --git a/gr-atsc/include/atsc/GrAtscSegSymSyncImpl.h b/gr-atsc/include/atsc/GrAtscSegSymSyncImpl.h new file mode 100644 index 0000000000..779f311f4f --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscSegSymSyncImpl.h @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef _GRATSCSEGSYMSYNCIMPL_H_ +#define _GRATSCSEGSYMSYNCIMPL_H_ + +#include <GrAtscSegSymSync.h> +#include <atsc/sssr_impl.h> + + +/*! + * \brief concrete implementation of GrAtscSegSymSync + * + * This class implements data segment sync tracking and symbol timing + * using a variation of the method described in + * "ATSC/VSB Tutorial - Receiver Technology" by Wayne E. Bretl of + * Zenith, pgs 41-45. + */ + +class GrAtscSegSymSyncImpl : public GrAtscSegSymSync { + + atsci_sssr d_sssr; + atsci_interpolator d_interp; + VrSampleIndex d_next_input; + double d_rx_clock_to_symbol_freq; // nominal ratio + +public: + + // the standard methods... + + GrAtscSegSymSyncImpl (double nominal_ratio_of_rx_clock_to_symbol_freq); + virtual ~GrAtscSegSymSyncImpl (); + + virtual const char *name () { return "GrAtscSegSymSyncImpl"; } + + virtual int forecast (VrSampleRange output, + VrSampleRange inputs[]); + + virtual int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + + void pre_initialize (); + + + // reset on channel change + + virtual void reset (); + +}; + +#endif /* _GRATSCSEGSYMSYNCIMPL_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscSegSymSyncImpl_export.h b/gr-atsc/include/atsc/GrAtscSegSymSyncImpl_export.h new file mode 100644 index 0000000000..187f1a0395 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscSegSymSyncImpl_export.h @@ -0,0 +1,26 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +class GrAtscSegSymSync; + +GrAtscSegSymSync *create_GrAtscSegSymSyncImpl ( + double nominal_ratio_of_rx_clock_to_symbol_freq); diff --git a/gr-atsc/include/atsc/GrAtscSymbolMapper.h b/gr-atsc/include/atsc/GrAtscSymbolMapper.h new file mode 100644 index 0000000000..c4e4083aa3 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscSymbolMapper.h @@ -0,0 +1,97 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCSYMBOLMAPPER_H_ +#define _GRATSCSYMBOLMAPPER_H_ + + +#include <VrInterpolatingSigProcNoWork.h> +#include <atsc/types.h> +#include <blocks/nco.h> + +/*! + * \brief take atsc_data_segments and map them to symbols. + * + * Input is a stream of atsc_data_segments. + * Output is a stream of symbols at 1x the symbol rate + * + * This module performs the signal mapping & pilot addition. + */ + +template<class oType> +class GrAtscSymbolMapper + : public VrInterpolatingSigProcNoWork<atsc_data_segment, oType> { + +public: + GrAtscSymbolMapper () + : VrInterpolatingSigProcNoWork<atsc_data_segment, oType>(1, INTERP_FACTOR) {}; + + ~GrAtscSymbolMapper () {}; + + const char *name () { return "GrAtscSymbolMapper"; } + + int work (VrSampleRange output, void *ao[], + VrSampleRange inputs[], void *ai[]); + +protected: + static const int INTERP_FACTOR = ATSC_DATA_SEGMENT_LENGTH; +}; + + +template<class oType> +int +GrAtscSymbolMapper<oType>::work (VrSampleRange output, void *ao[], + VrSampleRange inputs[], void *ai[]) +{ + atsc_data_segment *in = ((atsc_data_segment **) ai)[0]; + oType *out = ((oType **) ao)[0]; + + assert ((output.size % INTERP_FACTOR) == 0); + + static const float pilot_add = 1.25; + static const float map[8] = { + -7 + pilot_add, + -5 + pilot_add, + -3 + pilot_add, + -1 + pilot_add, + 1 + pilot_add, + 3 + pilot_add, + 5 + pilot_add, + 7 + pilot_add + }; + + unsigned int oo = 0; + unsigned int nsegs = output.size / INTERP_FACTOR; + + for (unsigned int n = 0; n < nsegs; n++){ + unsigned char *symbol = in[n].data; + + for (int i = 0; i < ATSC_DATA_SEGMENT_LENGTH; i++){ + out[oo++] = (oType) map[symbol[i] & 0x7]; + } + } + + assert (oo == output.size); + return output.size; +} + +#endif /* _GRATSCSYMBOLMAPPER_H_ */ diff --git a/gr-atsc/include/atsc/GrAtscTrellisEncoder.h b/gr-atsc/include/atsc/GrAtscTrellisEncoder.h new file mode 100644 index 0000000000..b1a047ce24 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscTrellisEncoder.h @@ -0,0 +1,50 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCTRELLISENCODER_H_ + +#include <VrHistoryProc.h> +#include <atsc/trellis_encoder_impl.h> + +/*! + * \brief ATSC 12-way interleaved trellis encoder (atsc_mpeg_packet_rs_encoded --> atsc_data_segment) + */ + +class GrAtscTrellisEncoder : public VrHistoryProc<atsc_mpeg_packet_rs_encoded,atsc_data_segment> +{ + +public: + + GrAtscTrellisEncoder (); + ~GrAtscTrellisEncoder (); + + const char *name () { return "GrAtscTrellisEncoder"; } + + int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + +protected: + atsci_trellis_encoder encoder; + int last_start; +}; + +#endif diff --git a/gr-atsc/include/atsc/GrAtscViterbiDecoder.h b/gr-atsc/include/atsc/GrAtscViterbiDecoder.h new file mode 100644 index 0000000000..35b1ea0dc7 --- /dev/null +++ b/gr-atsc/include/atsc/GrAtscViterbiDecoder.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GRATSCVITERBIDECODER_H_ + +#include <VrHistoryProc.h> +#include <atsc/viterbi_decoder_impl.h> + +/*! + * \brief ATSC 12-way interleaved viterbi decoder (atsc_soft_data_segment --> atsc_mpeg_packet_rs_encoded) + */ + +class GrAtscViterbiDecoder : public VrHistoryProc<atsc_soft_data_segment, + atsc_mpeg_packet_rs_encoded> +{ + +public: + + GrAtscViterbiDecoder (); + ~GrAtscViterbiDecoder (); + + const char *name () { return "GrAtscViterbiDecoder"; } + + int work (VrSampleRange output, void *o[], + VrSampleRange inputs[], void *i[]); + +protected: + atsci_viterbi_decoder decoder; + int last_start; +}; + +#endif diff --git a/gr-atsc/include/atsc/api.h b/gr-atsc/include/atsc/api.h new file mode 100644 index 0000000000..9516892e02 --- /dev/null +++ b/gr-atsc/include/atsc/api.h @@ -0,0 +1,33 @@ +/* + * Copyright 2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_API_H +#define INCLUDED_ATSC_API_H + +#include <attributes.h> + +#ifdef gnuradio_atsc_EXPORTS +# define ATSC_API __GR_ATTR_EXPORT +#else +# define ATSC_API __GR_ATTR_IMPORT +#endif + +#endif /* INCLUDED_ATSC_API_H */ diff --git a/gr-atsc/include/atsc/basic_trellis_encoder_impl.h b/gr-atsc/include/atsc/basic_trellis_encoder_impl.h new file mode 100644 index 0000000000..396ca94957 --- /dev/null +++ b/gr-atsc/include/atsc/basic_trellis_encoder_impl.h @@ -0,0 +1,62 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_BASIC_TRELLIS_ENCODER_H_ +#define _ATSC_BASIC_TRELLIS_ENCODER_H_ + +#include <atsc/api.h> +#include <assert.h> + +/*! + * \brief ATSC trellis encoder building block. + * + * Note this is NOT the 12x interleaved interface. + * + * This implements a single instance of the ATSC trellis encoder. + * This is a rate 2/3 encoder (really a constraint length 3, rate 1/2 + * encoder with the top bit passed through unencoded. This does not + * implement the "precoding" of the top bit, because the NTSC rejection + * filter is not supported. + */ + +class ATSC_API atsci_basic_trellis_encoder { + +private: + int state; // two bit state; + +public: + atsci_basic_trellis_encoder () : state (0) {} + + /*! + * Encode two bit INPUT into 3 bit return value. Domain is [0,3], + * Range is [0,7]. The mapping to bipolar levels is not done. + */ + int encode (unsigned int input); + + //! reset encoder state + void reset () { state = 0; } + + static const unsigned char next_state[32]; + static const unsigned char out_symbol[32]; +}; + +#endif /* _ATSC_BASIC_TRELLIS_ENCODER_H_ */ diff --git a/gr-atsc/include/atsc/bit_timing_loop.h b/gr-atsc/include/atsc/bit_timing_loop.h new file mode 100644 index 0000000000..eee2b2f73b --- /dev/null +++ b/gr-atsc/include/atsc/bit_timing_loop.h @@ -0,0 +1,89 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_BIT_TIMING_LOOP_H +#define INCLUDED_ATSC_BIT_TIMING_LOOP_H + +#include <atsc/api.h> +#include <cstdio> +#include <gr_block.h> +#include <atsc/diag_output_impl.h> +#include <atsc/sssr_impl.h> +#include <atsc/syminfo_impl.h> + +class atsc_bit_timing_loop; +typedef boost::shared_ptr<atsc_bit_timing_loop> atsc_bit_timing_loop_sptr; + +ATSC_API atsc_bit_timing_loop_sptr atsc_make_bit_timing_loop(); + +/*! + * \brief ATSC BitTimingLoop3 + * \ingroup atsc + * + * This class accepts a single real input and produces two outputs, + * the raw symbol (float) and the tag (atsc_syminfo) + */ +class ATSC_API atsc_bit_timing_loop : public gr_block +{ + friend ATSC_API atsc_bit_timing_loop_sptr atsc_make_bit_timing_loop(); + + atsc_bit_timing_loop(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } + + ~atsc_bit_timing_loop () { }; + + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + + int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + + // debug (NOPs) + void set_mu (double a_mu) { } + void set_no_update (bool a_no_update) { } + void set_loop_filter_tap (double tap) { } + void set_timing_rate (double rate) { } + + + protected: + + atsci_sssr d_sssr; + atsci_interpolator d_interp; + unsigned long long d_next_input; + double d_rx_clock_to_symbol_freq; + int d_si; + + +}; + +#endif /* INCLUDED_ATSC_BIT_TIMING_LOOP_H */ + + + diff --git a/gr-atsc/include/atsc/consts.h b/gr-atsc/include/atsc/consts.h new file mode 100644 index 0000000000..bbe2ec69aa --- /dev/null +++ b/gr-atsc/include/atsc/consts.h @@ -0,0 +1,42 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_CONSTS_H_ +#define _ATSC_CONSTS_H_ + +static const double ATSC_SYMBOL_RATE = 4.5e6 / 286 * 684; // ~10.76 MHz +static const double ATSC_DATA_SEGMENT_RATE = ATSC_SYMBOL_RATE / 832; // ~12.935 kHz + + +static const int ATSC_MPEG_DATA_LENGTH = 187; +static const int ATSC_MPEG_PKT_LENGTH = 188; // sync + data +static const int ATSC_MPEG_RS_ENCODED_LENGTH = 207; +static const int ATSC_DATA_SEGMENT_LENGTH = 832; // includes 4 sync symbols at beginning +static const int ATSC_DSEGS_PER_FIELD = 312; // regular data segs / field + + +static const int MPEG_SYNC_BYTE = 0x47; + +static const int MPEG_TRANSPORT_ERROR_BIT = 0x80; // top bit of byte after SYNC + + +#endif // _ATSC_CONSTS_H_ diff --git a/gr-atsc/include/atsc/convolutional_interleaver.h b/gr-atsc/include/atsc/convolutional_interleaver.h new file mode 100644 index 0000000000..00c843b015 --- /dev/null +++ b/gr-atsc/include/atsc/convolutional_interleaver.h @@ -0,0 +1,126 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _CONVOLUTIONAL_INTERLEAVER_H_ +#define _CONVOLUTIONAL_INTERLEAVER_H_ + +#include <vector> +#include <atsc/interleaver_fifo.h> +#include <assert.h> + +/*! + * \brief template class for generic convolutional interleaver + */ + +template<class symbol_type> +class convolutional_interleaver { + public: + + convolutional_interleaver (bool interleave_p, int nbanks, int fifo_size_incr); + virtual ~convolutional_interleaver (); + + //! reset interleaver (flushes contents and resets commutator) + void reset (); + + //! sync interleaver (resets commutator, but doesn't flush fifos) + void sync () { m_commutator = 0; } + + //! return end to end delay in symbols (delay through concatenated interleaver / deinterleaver) + int end_to_end_delay (); + + //! transform a single symbol + symbol_type transform (symbol_type input){ + symbol_type retval = m_fifo[m_commutator]->stuff (input); + m_commutator++; + if (m_commutator >= m_nbanks) + m_commutator = 0; + return retval; + } + + //! transform a bunch of symbols + void transform (symbol_type *out, const symbol_type *in, int nsymbols); + +protected: + int m_commutator; + int m_nbanks; + int m_fifo_size_incr; + std::vector<interleaver_fifo<symbol_type> *> m_fifo; +}; + +template<class symbol_type> +convolutional_interleaver<symbol_type>::convolutional_interleaver ( + bool interleave_p, + int nbanks, + int fifo_size_incr) +{ + assert (nbanks >= 1); + assert (fifo_size_incr >= 1); + + m_nbanks = nbanks; + m_fifo_size_incr = fifo_size_incr; + + m_fifo.resize (nbanks); + + if (interleave_p){ // configure as interleaver + for (int i = 0; i < nbanks; i++) + m_fifo[i] = new interleaver_fifo<symbol_type>(i * fifo_size_incr); + } + else { // configure as de-interleaver + for (int i = 0; i < nbanks; i++) + m_fifo[nbanks - 1 - i] = new interleaver_fifo<symbol_type>(i * fifo_size_incr); + } + sync (); +} + +template<class symbol_type> +convolutional_interleaver<symbol_type>::~convolutional_interleaver () +{ + for (int i = 0; i < m_nbanks; i++) + delete m_fifo[i]; +} + +template<class symbol_type> void +convolutional_interleaver<symbol_type>::reset () +{ + sync (); + for (int i = 0; i < m_nbanks; i++) + m_fifo[i]->reset (); +} + +template<class symbol_type> int +convolutional_interleaver<symbol_type>::end_to_end_delay () +{ + int m = m_nbanks * m_fifo_size_incr; + return m * (m_nbanks - 1); +} + +template<class symbol_type> void +convolutional_interleaver<symbol_type>::transform (symbol_type *out, + const symbol_type *in, + int nsymbols) +{ + // we may want to unroll this a couple of times... + for (int i = 0; i < nsymbols; i++) + out[i] = transform (in[i]); +} + +#endif /* _CONVOLUTIONAL_INTERLEAVER_H_ */ diff --git a/gr-atsc/include/atsc/create_atsci_equalizer.h b/gr-atsc/include/atsc/create_atsci_equalizer.h new file mode 100644 index 0000000000..adc4991703 --- /dev/null +++ b/gr-atsc/include/atsc/create_atsci_equalizer.h @@ -0,0 +1,34 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _CREATE_ATSC_EQUALIZER_H_ +#define _CREATE_ATSC_EQUALIZER_H_ + +#include <atsc/api.h> + +class atsci_equalizer; + +ATSC_API atsci_equalizer *create_atsci_equalizer_nop (); +ATSC_API atsci_equalizer *create_atsci_equalizer_lms (); +ATSC_API atsci_equalizer *create_atsci_equalizer_lms2 (); + +#endif /* _CREATE_ATSC_EQUALIZER_H_ */ diff --git a/gr-atsc/include/atsc/create_atsci_fs_checker.h b/gr-atsc/include/atsc/create_atsci_fs_checker.h new file mode 100644 index 0000000000..5d8e9ea407 --- /dev/null +++ b/gr-atsc/include/atsc/create_atsci_fs_checker.h @@ -0,0 +1,36 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _CREATE_ATSC_FS_CHECKER_H_ +#define _CREATE_ATSC_FS_CHECKER_H_ + +#include <atsc/api.h> + +class atsci_fs_checker; + +/*! + * Factory that creates appropriate atsci_fs_checker + */ +ATSC_API atsci_fs_checker *create_atsci_fs_checker (); + + +#endif /* _CREATE_ATSC_FS_CHECKER_H_ */ diff --git a/gr-atsc/include/atsc/create_atsci_fs_correlator.h b/gr-atsc/include/atsc/create_atsci_fs_correlator.h new file mode 100644 index 0000000000..0488645ace --- /dev/null +++ b/gr-atsc/include/atsc/create_atsci_fs_correlator.h @@ -0,0 +1,36 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _CREATE_ATSC_FS_CORRELATOR_H_ +#define _CREATE_ATSC_FS_CORRELATOR_H_ + +#include <atsc/api.h> + +class atsci_fs_correlator; + +/*! + * Factory that creates appropriate atsci_fs_correlator + */ +ATSC_API atsci_fs_correlator *create_atsci_fs_correlator (); + + +#endif /* _CREATE_ATSC_FS_CORRELATOR_H_ */ diff --git a/gr-atsc/include/atsc/data_interleaver_impl.h b/gr-atsc/include/atsc/data_interleaver_impl.h new file mode 100644 index 0000000000..a7765bd43f --- /dev/null +++ b/gr-atsc/include/atsc/data_interleaver_impl.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_DATA_INTERLEAVER_H_ +#define _ATSC_DATA_INTERLEAVER_H_ + +#include <atsc/api.h> +#include <atsc/types.h> +#include <atsc/convolutional_interleaver.h> + +/*! + * \brief atsc convolutional data interleaver + */ +class ATSC_API atsci_data_interleaver : public convolutional_interleaver<unsigned char> { + public: + atsci_data_interleaver () : convolutional_interleaver<unsigned char>(true, 52, 4) {} + + void interleave (atsc_mpeg_packet_rs_encoded &out, + const atsc_mpeg_packet_rs_encoded &in); +}; + +/*! + * \brief atsc convolutional data deinterleaver + */ +class ATSC_API atsci_data_deinterleaver : public convolutional_interleaver<unsigned char> { + public: + atsci_data_deinterleaver () : + convolutional_interleaver<unsigned char>(false, 52, 4), alignment_fifo (156) {} + + void deinterleave (atsc_mpeg_packet_rs_encoded &out, + const atsc_mpeg_packet_rs_encoded &in); + +private: + /*! + * Note: The use of the alignment_fifo keeps the encoder and decoder + * aligned if both are synced to a field boundary. There may be other + * ways to implement this function. This is a best guess as to how + * this should behave, as we have no test vectors for either the + * interleaver or deinterleaver. + */ + interleaver_fifo<unsigned char> alignment_fifo; + + static void remap_pli (plinfo &out, const plinfo &in); +}; + +#endif /* _ATSC_DATA_INTERLEAVER_H_ */ diff --git a/gr-atsc/include/atsc/deinterleaver.h b/gr-atsc/include/atsc/deinterleaver.h new file mode 100644 index 0000000000..7864526cfd --- /dev/null +++ b/gr-atsc/include/atsc/deinterleaver.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_DEINTERLEAVER_H +#define INCLUDED_ATSC_DEINTERLEAVER_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <atsc/data_interleaver_impl.h> + +class atsc_deinterleaver; +typedef boost::shared_ptr<atsc_deinterleaver> atsc_deinterleaver_sptr; + +ATSC_API atsc_deinterleaver_sptr atsc_make_deinterleaver(); + +/*! + * \brief Deinterleave RS encoded ATSC data ( atsc_mpeg_packet_rs_encoded --> atsc_mpeg_packet_rs_encoded) + * \ingroup atsc + * + * input: atsc_mpeg_packet_rs_encoded; output: atsc_mpeg_packet_rs_encoded + */ +class ATSC_API atsc_deinterleaver : public gr_sync_block +{ + friend ATSC_API atsc_deinterleaver_sptr atsc_make_deinterleaver(); + + atsci_data_deinterleaver d_deinterleaver; + + atsc_deinterleaver(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } +}; + + +#endif /* INCLUDED_ATSC_DEINTERLEAVER_H */ diff --git a/gr-atsc/include/atsc/depad.h b/gr-atsc/include/atsc/depad.h new file mode 100644 index 0000000000..ffced87a39 --- /dev/null +++ b/gr-atsc/include/atsc/depad.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef INCLUDED_ATSC_DEPAD_H +#define INCLUDED_ATSC_DEPAD_H + +#include <atsc/api.h> +#include <gr_sync_interpolator.h> + +class atsc_depad; +typedef boost::shared_ptr<atsc_depad> atsc_depad_sptr; + +ATSC_API atsc_depad_sptr atsc_make_depad(); + +/*! + * \brief depad mpeg ts packets from 256 byte atsc_mpeg_packet to 188 byte char + * \ingroup atsc + * + * input: atsc_mpeg_packet; output: unsigned char + */ +class ATSC_API atsc_depad : public gr_sync_interpolator +{ + friend ATSC_API atsc_depad_sptr atsc_make_depad(); + + atsc_depad(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } +}; + + +#endif /* INCLUDED_ATSC_DEPAD_H */ diff --git a/gr-atsc/include/atsc/derandomizer.h b/gr-atsc/include/atsc/derandomizer.h new file mode 100644 index 0000000000..4def872aa6 --- /dev/null +++ b/gr-atsc/include/atsc/derandomizer.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef INCLUDED_ATSC_DERANDOMIZER_H +#define INCLUDED_ATSC_DERANDOMIZER_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <atsc/randomizer_impl.h> + +class atsc_derandomizer; +typedef boost::shared_ptr<atsc_derandomizer> atsc_derandomizer_sptr; + +ATSC_API atsc_derandomizer_sptr atsc_make_derandomizer(); + +/*! + * \brief "dewhiten" incoming mpeg transport stream packets + * \ingroup atsc + * + * input: atsc_mpeg_packet_no_sync; output: atsc_mpeg_packet; + */ +class ATSC_API atsc_derandomizer : public gr_sync_block +{ + friend ATSC_API atsc_derandomizer_sptr atsc_make_derandomizer(); + + atsci_randomizer d_rand; + + atsc_derandomizer(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset(); +}; + + +#endif /* INCLUDED_ATSC_DERANDOMIZER_H */ diff --git a/gr-atsc/include/atsc/diag_output_impl.h b/gr-atsc/include/atsc/diag_output_impl.h new file mode 100644 index 0000000000..09fd763d6a --- /dev/null +++ b/gr-atsc/include/atsc/diag_output_impl.h @@ -0,0 +1,29 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +/* + * single place to control all compile time diagnostic output options + */ + +#define _BT_DIAG_OUTPUT_ 0 +#define _FPLL_DIAG_OUTPUT_ 0 +#define _SSSR_DIAG_OUTPUT_ 0 diff --git a/gr-atsc/include/atsc/ds_to_softds.h b/gr-atsc/include/atsc/ds_to_softds.h new file mode 100644 index 0000000000..6356506663 --- /dev/null +++ b/gr-atsc/include/atsc/ds_to_softds.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_DS_TO_SOFTDS_H +#define INCLUDED_ATSC_DS_TO_SOFTDS_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <atsc/types.h> + +class atsc_ds_to_softds; +typedef boost::shared_ptr<atsc_ds_to_softds> atsc_ds_to_softds_sptr; + +ATSC_API atsc_ds_to_softds_sptr atsc_make_ds_to_softds(); + +/*! + * \brief Debug glue routine (atsc_data_segment --> atsc_soft_data_segment) + * \ingroup atsc + * + * input: atsc_data_segment; output: atsc_soft_data_segment + */ +class ATSC_API atsc_ds_to_softds : public gr_sync_block +{ + friend ATSC_API atsc_ds_to_softds_sptr atsc_make_ds_to_softds(); + + atsc_ds_to_softds(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void map_to_soft_symbols (atsc_soft_data_segment &out, + const atsc_data_segment &in); + + + void reset() { /* nop */ } +}; + + +#endif /* INCLUDED_ATSC_DS_TO_SOFTDS_H */ diff --git a/gr-atsc/include/atsc/equalizer.h b/gr-atsc/include/atsc/equalizer.h new file mode 100644 index 0000000000..a910ab7562 --- /dev/null +++ b/gr-atsc/include/atsc/equalizer.h @@ -0,0 +1,71 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_EQUALIZER_H +#define INCLUDED_ATSC_EQUALIZER_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <atsc/equalizer_impl.h> +#include <vector> + +class atsc_equalizer; +typedef boost::shared_ptr<atsc_equalizer> atsc_equalizer_sptr; + +atsc_equalizer_sptr ATSC_API atsc_make_equalizer(); + +/*! + * \brief ATSC equalizer (float,syminfo --> float,syminfo) + * \ingroup atsc + * + * first inputs are data samples, second inputs are tags. + * first outputs are equalized data samples, second outputs are tags. + */ +class ATSC_API atsc_equalizer : public gr_sync_block +{ + friend ATSC_API atsc_equalizer_sptr atsc_make_equalizer(); + + atsc_equalizer(); + +public: + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + + std::vector<double> taps() { + return d_equalizer->taps(); + } + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } + + ~atsc_equalizer (); + + +protected: + atsci_equalizer *d_equalizer; + +}; + + +#endif /* INCLUDED_ATSC_EQUALIZER_H */ diff --git a/gr-atsc/include/atsc/equalizer_impl.h b/gr-atsc/include/atsc/equalizer_impl.h new file mode 100644 index 0000000000..e2baf537df --- /dev/null +++ b/gr-atsc/include/atsc/equalizer_impl.h @@ -0,0 +1,169 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_EQUALIZER_H_ +#define _ATSC_EQUALIZER_H_ + +#include <atsc/api.h> +#include <atsc/syminfo_impl.h> +#include <vector> + +/*! + * \brief abstract base class for ATSC equalizer + */ +class ATSC_API atsci_equalizer { + +private: + + /* + * have we seen a field sync since the last reset or problem? + */ + bool d_locked_p; + + /* + * sample offset from the beginning of the last field sync we saw + * to the beginning of our current input stream. When we're locked + * this will be in [0, 313*832] i.e., [0, 260416] + */ + int d_offset_from_last_field_sync; + + int d_current_field; // [0,1] + + +public: + + // CREATORS + atsci_equalizer (); + virtual ~atsci_equalizer (); + + virtual std::vector<double> taps () { + return std::vector<double>(); + } + + // MANIPULATORS + + /*! + * \brief reset state (e.g., on channel change) + * + * Note, subclasses must invoke the superclass's method too! + */ + virtual void reset (); + + /*! + * \brief produce \p nsamples of output from given inputs and tags + * + * This is the main entry point. It examines the input_tags + * and local state and invokes the appropriate virtual function + * to handle each sub-segment of the input data. + * + * \p input_samples must have (nsamples + ntaps() - 1) valid entries. + * input_samples[0] .. input_samples[nsamples - 1 + ntaps() - 1] are + * referenced to compute the output values. + * + * \p input_tags must have nsamples valid entries. + * input_tags[0] .. input_tags[nsamples - 1] are referenced to + * compute the output values. + */ + virtual void filter (const float *input_samples, + const atsc::syminfo *input_tags, + float *output_samples, + int nsamples); + + // ACCESSORS + + /*! + * \brief how much history the input data stream requires. + * + * This must return a value >= 1. Think of this as the number + * of samples you need to look at to compute a single output sample. + */ + virtual int ntaps () const = 0; + + /*! + * \brief how many taps are "in the future". + * + * This allows us to handle what the ATSC folks call "pre-ghosts". + * What it really does is allow the caller to jack with the offset + * between the tags and the data so that everything magically works out. + * + * npretaps () must return a value between 0 and ntaps() - 1. + * + * If npretaps () returns 0, this means that the equalizer will only handle + * multipath "in the past." I suspect that a good value would be something + * like 15% - 20% of ntaps (). + */ + virtual int npretaps () const = 0; + + +protected: + + /*! + * Input range is known NOT TO CONTAIN data segment syncs + * or field syncs. This should be the fast path. In the + * non decicion directed case, this just runs the input + * through the filter without adapting it. + * + * \p input_samples has (nsamples + ntaps() - 1) valid entries. + * input_samples[0] .. input_samples[nsamples - 1 + ntaps() - 1] may be + * referenced to compute the output values. + */ + virtual void filter_normal (const float *input_samples, + float *output_samples, + int nsamples) = 0; + + /*! + * Input range is known to consist of only a data segment sync or a + * portion of a data segment sync. \p nsamples will be in [1,4]. + * \p offset will be in [0,3]. \p offset is the offset of the input + * from the beginning of the data segment sync pattern. + * + * \p input_samples has (nsamples + ntaps() - 1) valid entries. + * input_samples[0] .. input_samples[nsamples - 1 + ntaps() - 1] may be + * referenced to compute the output values. + */ + virtual void filter_data_seg_sync (const float *input_samples, + float *output_samples, + int nsamples, + int offset) = 0; + + /*! + * Input range is known to consist of only a field sync segment or a + * portion of a field sync segment. \p nsamples will be in [1,832]. + * \p offset will be in [0,831]. \p offset is the offset of the input + * from the beginning of the data segment sync pattern. We consider the + * 4 symbols of the immediately preceding data segment sync to be the + * first symbols of the field sync segment. \p which_field is in [0,1] + * and specifies which field (duh). + * + * \p input_samples has (nsamples + ntaps() - 1) valid entries. + * input_samples[0] .. input_samples[nsamples - 1 + ntaps() - 1] may be + * referenced to compute the output values. + */ + virtual void filter_field_sync (const float *input_samples, + float *output_samples, + int nsamples, + int offset, + int which_field) = 0; +}; + + +#endif /* _ATSC_EQUALIZER_H_ */ diff --git a/gr-atsc/include/atsc/equalizer_lms2_impl.h b/gr-atsc/include/atsc/equalizer_lms2_impl.h new file mode 100644 index 0000000000..ebd6c13d0f --- /dev/null +++ b/gr-atsc/include/atsc/equalizer_lms2_impl.h @@ -0,0 +1,80 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_EQUALIZER_LMS2_H_ +#define _ATSC_EQUALIZER_LMS2_H_ + +#include <atsc/api.h> +#include <atsc/equalizer_impl.h> +#include <vector> +#include <stdio.h> + +class ATSC_API atsci_equalizer_lms2 : public atsci_equalizer +{ +public: + atsci_equalizer_lms2 (); + virtual ~atsci_equalizer_lms2 (); + + virtual void reset (); + virtual int ntaps () const; + virtual int npretaps () const; + +protected: + FILE *trainingfile; + virtual void filter_normal (const float *input_samples, + float *output_samples, + int nsamples); + + virtual void filter_data_seg_sync (const float *input_samples, + float *output_samples, + int nsamples, + int offset); + + virtual void filter_field_sync (const float *input_samples, + float *output_samples, + int nsamples, + int offset, + int which_field); + +private: + std::vector<double> d_taps_ff; + std::vector<double> d_taps_fb; + std::vector<float> d_old_output; + + int d_output_ptr; + + void filterN (const float *input_samples, + float *output_samples, + int nsamples); + + void adaptN (const float *input_samples, + const float *training_pattern, + float *output_samples, + int nsamples); + + float filter1 (const float input[]); + float adapt1 (const float input[], float ideal_output); + +}; + + +#endif /* _ATSC_EQUALIZER_LMS2_H_ */ diff --git a/gr-atsc/include/atsc/equalizer_lms_impl.h b/gr-atsc/include/atsc/equalizer_lms_impl.h new file mode 100644 index 0000000000..c91349de69 --- /dev/null +++ b/gr-atsc/include/atsc/equalizer_lms_impl.h @@ -0,0 +1,79 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_EQUALIZER_LMS_H_ +#define _ATSC_EQUALIZER_LMS_H_ + +#include <atsc/api.h> +#include <atsc/equalizer_impl.h> +#include <vector> +#include <stdio.h> + +class ATSC_API atsci_equalizer_lms : public atsci_equalizer +{ +public: + atsci_equalizer_lms (); + virtual ~atsci_equalizer_lms (); + + virtual void reset (); + virtual int ntaps () const; + virtual int npretaps () const; + std::vector<double> taps () { + return d_taps; + } + +protected: + FILE *trainingfile; + virtual void filter_normal (const float *input_samples, + float *output_samples, + int nsamples); + + virtual void filter_data_seg_sync (const float *input_samples, + float *output_samples, + int nsamples, + int offset); + + virtual void filter_field_sync (const float *input_samples, + float *output_samples, + int nsamples, + int offset, + int which_field); + +private: + std::vector<double> d_taps; + + void filterN (const float *input_samples, + float *output_samples, + int nsamples); + + void adaptN (const float *input_samples, + const float *training_pattern, + float *output_samples, + int nsamples); + + float filter1 (const float input[]); + float adapt1 (const float input[], float ideal_output); + +}; + + +#endif /* _ATSC_EQUALIZER_LMS_H_ */ diff --git a/gr-atsc/include/atsc/equalizer_nop_impl.h b/gr-atsc/include/atsc/equalizer_nop_impl.h new file mode 100644 index 0000000000..85549e326b --- /dev/null +++ b/gr-atsc/include/atsc/equalizer_nop_impl.h @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_EQUALIZER_NOP_H_ +#define _ATSC_EQUALIZER_NOP_H_ + +#include <atsc/api.h> +#include <atsc/equalizer_impl.h> + +class ATSC_API atsci_equalizer_nop : public atsci_equalizer +{ +private: + float scale (float input) { return input; } + + float scale_and_train (float input); + + +public: + atsci_equalizer_nop (); + virtual ~atsci_equalizer_nop (); + + virtual void reset (); + virtual int ntaps () const; + virtual int npretaps () const; + +protected: + virtual void filter_normal (const float *input_samples, + float *output_samples, + int nsamples); + + virtual void filter_data_seg_sync (const float *input_samples, + float *output_samples, + int nsamples, + int offset); + + virtual void filter_field_sync (const float *input_samples, + float *output_samples, + int nsamples, + int offset, + int which_field); +}; + + +#endif /* _ATSC_EQUALIZER_NOP_H_ */ diff --git a/gr-atsc/include/atsc/exp2_lp_impl.h b/gr-atsc/include/atsc/exp2_lp_impl.h new file mode 100644 index 0000000000..b0fbc46432 --- /dev/null +++ b/gr-atsc/include/atsc/exp2_lp_impl.h @@ -0,0 +1,35 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_EXP2_LP_H_ +#define _ATSC_EXP2_LP_H_ + +#include <atsc/api.h> +#include <gr_fir_builder.h> + +class ATSC_API atsci_exp2_lp : public gr_fir_builder +{ +public: + virtual std::vector<float> taps (double sampling_freq); +}; + +#endif /* _ATSC_EXP2_LP_H_ */ diff --git a/gr-atsc/include/atsc/fake_single_viterbi_impl.h b/gr-atsc/include/atsc/fake_single_viterbi_impl.h new file mode 100644 index 0000000000..5895e0ac61 --- /dev/null +++ b/gr-atsc/include/atsc/fake_single_viterbi_impl.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSCFAKESINGLEVITERBI_H_ +#define _ATSCFAKESINGLEVITERBI_H_ + +#include <atsc/api.h> + +/*! + * \brief single channel viterbi decoder + */ +class ATSC_API atsci_fake_single_viterbi +{ + +public: + atsci_fake_single_viterbi (); + + /*! + * \p INPUT ideally takes on the values +/- 1,3,5,7 + * return is decoded dibit in the range [0, 3] + */ + char decode (float input); + + void reset (); + + //! internal delay of decoder + int delay () { return 0; } + +protected: + int post_coder_state; +}; + +#endif diff --git a/gr-atsc/include/atsc/field_sync_demux.h b/gr-atsc/include/atsc/field_sync_demux.h new file mode 100644 index 0000000000..bec3590096 --- /dev/null +++ b/gr-atsc/include/atsc/field_sync_demux.h @@ -0,0 +1,76 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef INCLUDED_ATSC_FIELD_SYNC_DEMUX_H +#define INCLUDED_ATSC_FIELD_SYNC_DEMUX_H + +#include <atsc/api.h> +#include <gr_block.h> +#include <atsc/types.h> + +class atsc_field_sync_demux; +typedef boost::shared_ptr<atsc_field_sync_demux> atsc_field_sync_demux_sptr; + +ATSC_API atsc_field_sync_demux_sptr atsc_make_field_sync_demux(); + +/*! + * \brief ATSC Field Sync Demux + * + * This class accepts 1 stream of floats (data), and 1 stream of tags (syminfo). * It outputs one stream of atsc_soft_data_segment packets + * \ingroup atsc + * + */ +class ATSC_API atsc_field_sync_demux : public gr_block +{ + friend ATSC_API atsc_field_sync_demux_sptr atsc_make_field_sync_demux(); + + atsc_field_sync_demux(); + +public: + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + + int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } + +protected: + bool d_locked; + bool d_in_field2; + int d_segment_number; + gr_uint64 d_next_input; + gr_uint64 d_lost_index; // diagnostic fluff + + unsigned long long d_inputs0_index; // for inputs[0].index + unsigned long d_inputs0_size; // for inputs[0].size + int d_consume; + +}; + + +#endif /* INCLUDED_ATSC_FIELD_SYNC_DEMUX_H */ diff --git a/gr-atsc/include/atsc/field_sync_mux.h b/gr-atsc/include/atsc/field_sync_mux.h new file mode 100644 index 0000000000..21a2f0fdab --- /dev/null +++ b/gr-atsc/include/atsc/field_sync_mux.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_FIELD_SYNC_MUX_H +#define INCLUDED_ATSC_FIELD_SYNC_MUX_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <atsc/types.h> + +class atsc_field_sync_mux; +typedef boost::shared_ptr<atsc_field_sync_mux> atsc_field_sync_mux_sptr; + +ATSC_API atsc_field_sync_mux_sptr atsc_make_field_sync_mux(); + +/*! + * \brief Insert ATSC Field Syncs as required (atsc_data_segment --> atsc_data_segment) + * \ingroup atsc + * + * input: atsc_data_segment; output: atsc_data_segment + */ +class ATSC_API atsc_field_sync_mux : public gr_sync_block +{ + friend ATSC_API atsc_field_sync_mux_sptr atsc_make_field_sync_mux(); + + atsc_field_sync_mux(); + +public: + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + + static const int N_SAVED_SYMBOLS = 12; + + void reset() { /* nop */ } + +protected: + gr_uint64 d_current_index; + bool d_already_output_field_sync; + unsigned char d_saved_symbols[N_SAVED_SYMBOLS]; +}; + + +#endif /* INCLUDED_ATSC_FIELD_SYNC_MUX_H */ diff --git a/gr-atsc/include/atsc/fpll.h b/gr-atsc/include/atsc/fpll.h new file mode 100644 index 0000000000..2bffc327eb --- /dev/null +++ b/gr-atsc/include/atsc/fpll.h @@ -0,0 +1,82 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_FPLL_H +#define INCLUDED_ATSC_FPLL_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <gr_nco.h> +#include <filter/single_pole_iir.h> +#include <analog/agc.h> +#include <stdio.h> +#include <atsc/diag_output_impl.h> + +using namespace gr; + +class atsc_fpll; +typedef boost::shared_ptr<atsc_fpll> atsc_fpll_sptr; + +ATSC_API atsc_fpll_sptr atsc_make_fpll(); + +/*! + * \brief ATSC FPLL (2nd Version) + * \ingroup atsc + * + * A/D --> GrFIRfilterFFF ----> GrAtscFPLL ----> + * + * We use GrFIRfilterFFF to bandpass filter the signal of interest. + * + * This class accepts a single real input and produces a single real output + */ + +class ATSC_API atsc_fpll : public gr_sync_block +{ + friend ATSC_API atsc_fpll_sptr atsc_make_fpll(); + + atsc_fpll(); + +public: + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } + + void initialize () ; + + protected: + + double initial_freq; + double initial_phase; + bool debug_no_update; + gr_nco<float,float> nco; + analog::kernel::agc_ff agc; // automatic gain control + filter::single_pole_iir<float,float,float> afci; + filter::single_pole_iir<float,float,float> afcq; + + +}; + + +#endif /* INCLUDED_ATSC_FPLL_H */ diff --git a/gr-atsc/include/atsc/fs_checker.h b/gr-atsc/include/atsc/fs_checker.h new file mode 100644 index 0000000000..1bd304090f --- /dev/null +++ b/gr-atsc/include/atsc/fs_checker.h @@ -0,0 +1,64 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_FS_CHECKER_H +#define INCLUDED_ATSC_FS_CHECKER_H + +#include <atsc/api.h> +#include <atsc/fs_checker_impl.h> +#include <gr_sync_block.h> + +class atsc_fs_checker; +typedef boost::shared_ptr<atsc_fs_checker> atsc_fs_checker_sptr; + +ATSC_API atsc_fs_checker_sptr atsc_make_fs_checker(); + +/*! + * \brief ATSC field sync checker (float,syminfo --> float,syminfo) + * \ingroup atsc + * + * first output is delayed version of input. + * second output is set of tags, one-for-one with first output. + */ + +class ATSC_API atsc_fs_checker : public gr_sync_block +{ + friend ATSC_API atsc_fs_checker_sptr atsc_make_fs_checker(); + + atsc_fs_checker(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } + + ~atsc_fs_checker (); + +protected: + atsci_fs_checker *d_fsc; + +}; + + +#endif /* INCLUDED_ATSC_FS_CHECKER_H */ diff --git a/gr-atsc/include/atsc/fs_checker_impl.h b/gr-atsc/include/atsc/fs_checker_impl.h new file mode 100644 index 0000000000..a4975d243e --- /dev/null +++ b/gr-atsc/include/atsc/fs_checker_impl.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef _ATSC_FS_CHECKER_H_ +#define _ATSC_FS_CHECKER_H_ + +#include <atsc/api.h> +#include <atsc/syminfo_impl.h> + +/*! + * \brief abstract base class for ATSC field sync checker + * + * Processes input samples one at a time looking for + * an occurence of either the field sync 1 or field sync 2 pattern. + * + * Note that unlike atsci_fs_correlator, this class uses the symbol_num in + * input_tag to avoid having to test each symbol position. + * + * For each sample processed, an output sample and an output tag are produced. + * The output samples are identical to the input samples but are delayed by + * a number of samples given by \p delay(). The output tag associated with + * the the given output sample indicates whether this sample is the beginning + * of one of the field syncs or is an ordinary sample. The tags are defined in + * atsci_sync_tag.h. + * + * For ease of use, the field sync patterns are defined to begin with the + * first symbol of the 4 symbol data segment sync pattern that immediately + * proceeds the actual PN 511 code. This makes it easier for downstream code + * to determine the location of data segment syncs merely by counting. They'll + * occur every 832 samples assuming everything is working. + */ + +class ATSC_API atsci_fs_checker { + +public: + + // CREATORS + atsci_fs_checker (); + virtual ~atsci_fs_checker () = 0; + + // MANIPULATORS + virtual void reset () = 0; + virtual void filter (float input_sample, atsc::syminfo input_tag, + float *output_sample, atsc::syminfo *output_tag) = 0; + + // ACCESSORS + + //! return delay in samples from input to output + virtual int delay () const = 0; +}; + +#endif /* _ATSC_FS_CHECKER_H_ */ diff --git a/gr-atsc/include/atsc/fs_checker_naive_impl.h b/gr-atsc/include/atsc/fs_checker_naive_impl.h new file mode 100644 index 0000000000..0056bf69c8 --- /dev/null +++ b/gr-atsc/include/atsc/fs_checker_naive_impl.h @@ -0,0 +1,74 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_FS_CHECKER_NAIVE_H_ +#define _ATSC_FS_CHECKER_NAIVE_H_ + +#include <atsc/api.h> +#include <atsc/fs_checker_impl.h> + +/*! + * \brief Naive concrete implementation of field sync checker + */ +class ATSC_API atsci_fs_checker_naive : public atsci_fs_checker { + + private: + static const int SRSIZE = 1024; // must be power of two + int d_index; // points at oldest sample + float d_sample_sr[SRSIZE]; // sample shift register + atsc::syminfo d_tag_sr[SRSIZE]; // tag shift register + unsigned char d_bit_sr[SRSIZE]; // binary decision shift register + int d_field_num; + int d_segment_num; + + static const int OFFSET_511 = 0; // offset to PN 511 pattern + static const int LENGTH_511 = 511 + 4; // length of PN 511 pattern (+ 4 seg sync) + static const int OFFSET_2ND_63 = 578; // offset to second PN 63 pattern + static const int LENGTH_2ND_63 = 63; // length of PN 63 pattern + + static unsigned char s_511[LENGTH_511]; // PN 511 pattern + static unsigned char s_63[LENGTH_2ND_63]; // PN 63 pattern + + inline static int wrap (int index){ return index & (SRSIZE - 1); } + inline static int incr (int index){ return wrap (index + 1); } + inline static int decr (int index){ return wrap (index - 1); } + + public: + + // CREATORS + atsci_fs_checker_naive (); + ~atsci_fs_checker_naive (); + + // MANIPULATORS + virtual void reset (); + void filter (float input_sample, atsc::syminfo input_tag, + float *output_sample, atsc::syminfo *output_tag); + + // ACCESSORS + + //! return delay in samples from input to output + int delay () const; + +}; + + +#endif /* _ATSC_FS_CHECKER_NAIVE_H_ */ diff --git a/gr-atsc/include/atsc/fs_correlator_impl.h b/gr-atsc/include/atsc/fs_correlator_impl.h new file mode 100644 index 0000000000..b55b1b9854 --- /dev/null +++ b/gr-atsc/include/atsc/fs_correlator_impl.h @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_FS_CORRELATOR_H_ +#define _ATSC_FS_CORRELATOR_H_ + +#include <atsc/api.h> + +/*! + * \brief abstract base class for ATSC field sync correlator + * + * Processes input samples one at a time looking for + * an occurence of either the field sync 1 or field sync 2 pattern. + * + * For each sample processed, an output sample and an output tag are produced. + * The output samples are identical to the input samples but are delayed by + * a number of samples given by \p delay(). The output tag associated with + * the the given output sample indicates whether this sample is the beginning + * of one of the field syncs or is an ordinary sample. The tags are defined in + * atsci_sync_tag.h. + * + * For ease of use, the field sync patterns are defined to begin with the + * first symbol of the 4 symbol data segment sync pattern that immediately + * proceeds the actual PN 511 code. This makes it easier for downstream code + * to determine the location of data segment syncs merely by counting. They'll + * occur every 832 samples assuming everything is working. + */ + +class ATSC_API atsci_fs_correlator { + +public: + + // CREATORS + atsci_fs_correlator (); + virtual ~atsci_fs_correlator () = 0; + + // MANIPULATORS + virtual void reset () = 0; + virtual void filter (float input_sample, float *output_sample, float *output_tag) = 0; + + // ACCESSORS + + //! return delay in samples from input to output + virtual int delay () const = 0; +}; + +#endif /* _ATSC_FS_CORRELATOR_H_ */ diff --git a/gr-atsc/include/atsc/fs_correlator_naive_impl.h b/gr-atsc/include/atsc/fs_correlator_naive_impl.h new file mode 100644 index 0000000000..e2fd19557b --- /dev/null +++ b/gr-atsc/include/atsc/fs_correlator_naive_impl.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_FS_CORRELATOR_NAIVE_H_ +#define _ATSC_FS_CORRELATOR_NAIVE_H_ + +#include <atsc/api.h> +#include <atsc/fs_correlator_impl.h> + +/*! + * \brief Naive concrete implementation of field sync correlator + */ +class ATSC_API atsci_fs_correlator_naive : public atsci_fs_correlator { + + private: + static const int SRSIZE = 1024; // must be power of two + int d_index; // points at oldest sample + float d_sample_sr[SRSIZE]; // sample shift register + unsigned char d_bit_sr[SRSIZE]; // binary decision shift register + + static const int OFFSET_511 = 0; // offset to PN 511 pattern + static const int LENGTH_511 = 511 + 4; // length of PN 511 pattern (+ 4 seg sync) + static const int OFFSET_2ND_63 = 578; // offset to second PN 63 pattern + static const int LENGTH_2ND_63 = 63; // length of PN 63 pattern + + static unsigned char s_511[LENGTH_511]; // PN 511 pattern + static unsigned char s_63[LENGTH_2ND_63]; // PN 63 pattern + + inline static int wrap (int index){ return index & (SRSIZE - 1); } + inline static int incr (int index){ return wrap (index + 1); } + inline static int decr (int index){ return wrap (index - 1); } + + public: + + // CREATORS + atsci_fs_correlator_naive (); + ~atsci_fs_correlator_naive (); + + // MANIPULATORS + virtual void reset (); + void filter (float input_sample, float *output_sample, float *output_tag); + + // ACCESSORS + + //! return delay in samples from input to output + int delay () const; + +}; + + +#endif /* _ATSC_FS_CORRELATOR_NAIVE_H_ */ diff --git a/gr-atsc/include/atsc/interleaver.h b/gr-atsc/include/atsc/interleaver.h new file mode 100644 index 0000000000..f426381add --- /dev/null +++ b/gr-atsc/include/atsc/interleaver.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_INTERLEAVER_H +#define INCLUDED_ATSC_INTERLEAVER_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <atsc/data_interleaver_impl.h> + +class atsc_interleaver; +typedef boost::shared_ptr<atsc_interleaver> atsc_interleaver_sptr; + +ATSC_API atsc_interleaver_sptr atsc_make_interleaver(); + +/*! \brief Interleave RS encoded ATSC data ( atsc_mpeg_packet_rs_encoded --> atsc_mpeg_packet_rs_encoded)* + * \ingroup atsc + * + * input: atsc_mpeg_packet_rs_encoded; output: atsc_mpeg_packet_rs_encoded + */ +class ATSC_API atsc_interleaver : public gr_sync_block +{ + friend ATSC_API atsc_interleaver_sptr atsc_make_interleaver(); + + atsci_data_interleaver d_interleaver; + + atsc_interleaver(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } +}; + + +#endif /* INCLUDED_ATSC_INTERLEAVER_H */ diff --git a/gr-atsc/include/atsc/interleaver_fifo.h b/gr-atsc/include/atsc/interleaver_fifo.h new file mode 100644 index 0000000000..5c29a82563 --- /dev/null +++ b/gr-atsc/include/atsc/interleaver_fifo.h @@ -0,0 +1,86 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _INTERLEAVER_FIFO_H_ +#define _INTERLEAVER_FIFO_H_ + + +#include <atsc/interleaver_fifo.h> +#include <string.h> + +/*! + * \brief template class for interleaver fifo + */ + +template<class symbol_type> +class interleaver_fifo { + public: + + interleaver_fifo (unsigned int size); + ~interleaver_fifo (); + + //! reset interleaver (flushes contents and resets commutator) + void reset (); + + //! stuff a symbol into the fifo and return the oldest + symbol_type stuff (symbol_type input){ + if (m_size == 0) + return input; + + symbol_type retval = m_fifo[m_position]; + m_fifo[m_position] = input; + m_position++; + if (m_position >= m_size) + m_position = 0; + + return retval; + } + +protected: + unsigned int m_size; + unsigned int m_position; + symbol_type *m_fifo; +}; + +template<class symbol_type> +interleaver_fifo<symbol_type>::interleaver_fifo (unsigned int size) +{ + m_size = size; + m_position = 0; + m_fifo = new symbol_type[size]; + memset (m_fifo, 0, m_size * sizeof (symbol_type)); +} + +template<class symbol_type> +interleaver_fifo<symbol_type>::~interleaver_fifo () +{ + delete [] m_fifo; +} + +template<class symbol_type> void +interleaver_fifo<symbol_type>::reset () +{ + m_position = 0; + memset (m_fifo, 0, m_size * sizeof (symbol_type)); +} + +#endif /* _INTERLEAVER_FIFO_H_ */ diff --git a/gr-atsc/include/atsc/pad.h b/gr-atsc/include/atsc/pad.h new file mode 100644 index 0000000000..b48d17f7b7 --- /dev/null +++ b/gr-atsc/include/atsc/pad.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_PAD_H +#define INCLUDED_ATSC_PAD_H + +#include <atsc/api.h> +#include <gr_sync_decimator.h> + +class atsc_pad; +typedef boost::shared_ptr<atsc_pad> atsc_pad_sptr; + +ATSC_API atsc_pad_sptr atsc_make_pad(); + +/*! + * \brief pad mpeg ts packets from 188 byte char to + * to 256 byte atsc_mpeg_packet + * \ingroup atsc + * + * input: unsigned char; output: atsc_mpeg_packet + */ +class ATSC_API atsc_pad : public gr_sync_decimator +{ + friend ATSC_API atsc_pad_sptr atsc_make_pad(); + + atsc_pad(); + +public: + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } +}; + + +#endif /* INCLUDED_ATSC_PAD_H */ diff --git a/gr-atsc/include/atsc/pnXXX_impl.h b/gr-atsc/include/atsc/pnXXX_impl.h new file mode 100644 index 0000000000..3de6eb1f51 --- /dev/null +++ b/gr-atsc/include/atsc/pnXXX_impl.h @@ -0,0 +1,26 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include <atsc/api.h> + +ATSC_API extern const unsigned char atsc_pn511[]; +ATSC_API extern const unsigned char atsc_pn63[]; diff --git a/gr-atsc/include/atsc/randomizer.h b/gr-atsc/include/atsc/randomizer.h new file mode 100644 index 0000000000..8825062bbc --- /dev/null +++ b/gr-atsc/include/atsc/randomizer.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_RANDOMIZER_H +#define INCLUDED_ATSC_RANDOMIZER_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <atsc/randomizer_impl.h> + +class atsc_randomizer; +typedef boost::shared_ptr<atsc_randomizer> atsc_randomizer_sptr; + +ATSC_API atsc_randomizer_sptr atsc_make_randomizer(); + +/*! + * \brief "Whiten" incoming mpeg transport stream packets + * \ingroup atsc + * + * input: atsc_mpeg_packet; output: atsc_mpeg_packet_no_sync + */ +class ATSC_API atsc_randomizer : public gr_sync_block +{ + friend ATSC_API atsc_randomizer_sptr atsc_make_randomizer(); + + atsci_randomizer d_rand; + bool d_field2; // user to init plinfo in output + int d_segno; // likewise + + atsc_randomizer(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset(); +}; + + +#endif /* INCLUDED_ATSC_RANDOMIZER_H */ diff --git a/gr-atsc/include/atsc/randomizer_impl.h b/gr-atsc/include/atsc/randomizer_impl.h new file mode 100644 index 0000000000..4fdbebc06d --- /dev/null +++ b/gr-atsc/include/atsc/randomizer_impl.h @@ -0,0 +1,97 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_RANDOMIZER_H_ +#define _ATSC_RANDOMIZER_H_ + +#include <atsc/api.h> +#include <atsc/types.h> + +/*! + * \brief ATSC data "whitener" + * + * The data randomizer described in ATSC standard A/53B. + * See figure D4 on page 54. + */ + +class ATSC_API atsci_randomizer { + friend class qa_atsci_randomizer; + + public: + atsci_randomizer(); + + /*! \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; + else + 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 r; + } + + 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; +}; + +#endif /* _ATSC_RANDOMIZER_H_ */ diff --git a/gr-atsc/include/atsc/reed_solomon_impl.h b/gr-atsc/include/atsc/reed_solomon_impl.h new file mode 100644 index 0000000000..484b6d0ce2 --- /dev/null +++ b/gr-atsc/include/atsc/reed_solomon_impl.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_REED_SOLOMON_H_ +#define _ATSC_REED_SOLOMON_H_ + +#include <atsc/api.h> +#include <atsc/types.h> + +/*! + * \brief ATSC Reed-Solomon encoder / decoder + * + * The t=10 (207,187) code described in ATSC standard A/53B. + * See figure D5 on page 55. + */ + +class ATSC_API atsci_reed_solomon { + + public: + atsci_reed_solomon(); + ~atsci_reed_solomon(); + + /*! + * \brief Add RS error correction encoding + */ + void encode (atsc_mpeg_packet_rs_encoded &out, const atsc_mpeg_packet_no_sync &in); + + /*! + * Decode RS encoded packet. + * \returns a count of corrected symbols, or -1 if the block was uncorrectible. + */ + int decode (atsc_mpeg_packet_no_sync &out, const atsc_mpeg_packet_rs_encoded &in); + + private: + void *d_rs; +}; + +#endif /* _ATSC_REED_SOLOMON_H_ */ diff --git a/gr-atsc/include/atsc/root_raised_cosine_bandpass_impl.h b/gr-atsc/include/atsc/root_raised_cosine_bandpass_impl.h new file mode 100644 index 0000000000..50548bec89 --- /dev/null +++ b/gr-atsc/include/atsc/root_raised_cosine_bandpass_impl.h @@ -0,0 +1,40 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_RRC_BANDPASS_H_ +#define _ATSC_RRC_BANDPASS_H_ + +#include <atsc/api.h> +#include <atsc/root_raised_cosine_impl.h> + +class ATSC_API atsc_root_raised_cosine_bandpass : public atsc_root_raised_cosine +{ +public: + atsc_root_raised_cosine_bandpass (double center_freq) : _center_freq (center_freq) {} + virtual std::vector<float> taps (double sampling_freq); + +protected: + double _center_freq; +}; + + +#endif /* _ATSC_RRC_BANDPASS_H_ */ diff --git a/gr-atsc/include/atsc/root_raised_cosine_impl.h b/gr-atsc/include/atsc/root_raised_cosine_impl.h new file mode 100644 index 0000000000..ae884bfb19 --- /dev/null +++ b/gr-atsc/include/atsc/root_raised_cosine_impl.h @@ -0,0 +1,36 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_RRC_H_ +#define _ATSC_RRC_H_ + +#include <atsc/api.h> +#include <gr_fir_builder.h> + +class ATSC_API atsc_root_raised_cosine : public gr_fir_builder +{ +public: + virtual std::vector<float> taps (double sampling_freq); +}; + + +#endif /* _ATSC_RRC_H_ */ diff --git a/gr-atsc/include/atsc/rs_decoder.h b/gr-atsc/include/atsc/rs_decoder.h new file mode 100644 index 0000000000..308fb46432 --- /dev/null +++ b/gr-atsc/include/atsc/rs_decoder.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_RS_DECODER_H +#define INCLUDED_ATSC_RS_DECODER_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <atsc/reed_solomon_impl.h> + +class atsc_rs_decoder; +typedef boost::shared_ptr<atsc_rs_decoder> atsc_rs_decoder_sptr; + +ATSC_API atsc_rs_decoder_sptr atsc_make_rs_decoder(); + +/*! + * \brief Reed-Solomon decoder for ATSC + * \ingroup atsc + * + * input: atsc_mpeg_packet_rs_encoded; output: atsc_mpeg_packet_no_sync + */ +class ATSC_API atsc_rs_decoder : public gr_sync_block +{ + friend ATSC_API atsc_rs_decoder_sptr atsc_make_rs_decoder(); + + atsci_reed_solomon d_rs_decoder; + + atsc_rs_decoder(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } +}; + + +#endif /* INCLUDED_ATSC_RS_DECODER_H */ diff --git a/gr-atsc/include/atsc/rs_encoder.h b/gr-atsc/include/atsc/rs_encoder.h new file mode 100644 index 0000000000..ace2806da3 --- /dev/null +++ b/gr-atsc/include/atsc/rs_encoder.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_RS_ENCODER_H +#define INCLUDED_ATSC_RS_ENCODER_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <atsc/reed_solomon_impl.h> + +class atsc_rs_encoder; +typedef boost::shared_ptr<atsc_rs_encoder> atsc_rs_encoder_sptr; + +ATSC_API atsc_rs_encoder_sptr atsc_make_rs_encoder(); + +/*! + * \brief Reed-Solomon encoder for ATSC + * \ingroup atsc + * + * input: atsc_mpeg_packet_no_sync; output: atsc_mpeg_packet_rs_encoded + */ +class ATSC_API atsc_rs_encoder : public gr_sync_block +{ + friend ATSC_API atsc_rs_encoder_sptr atsc_make_rs_encoder(); + + atsci_reed_solomon d_rs_encoder; + + atsc_rs_encoder(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } +}; + + +#endif /* INCLUDED_ATSC_RS_ENCODER_H */ diff --git a/gr-atsc/include/atsc/single_viterbi_impl.h b/gr-atsc/include/atsc/single_viterbi_impl.h new file mode 100644 index 0000000000..d92ded80e5 --- /dev/null +++ b/gr-atsc/include/atsc/single_viterbi_impl.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSCSINGLEVITERBI_H_ +#define _ATSCSINGLEVITERBI_H_ + +#include <atsc/api.h> + +/*! + * \brief single channel viterbi decoder + */ +class ATSC_API atsci_single_viterbi +{ + +public: + atsci_single_viterbi (); + + static const unsigned int TB_LEN = 32; + + /*! + * \p INPUT ideally takes on the values +/- 1,3,5,7 + * return is decoded dibit in the range [0, 3] + */ + char decode (float input); + + void reset (); + + //! internal delay of decoder + int delay () { return TB_LEN - 1; } + +protected: + static const int transition_table[32]; + static const float was_sent[32]; + float path_metrics [2][8]; + unsigned long long traceback [2][8]; + unsigned char phase; +}; + +#endif diff --git a/gr-atsc/include/atsc/slicer_agc_impl.h b/gr-atsc/include/atsc/slicer_agc_impl.h new file mode 100644 index 0000000000..91694c09db --- /dev/null +++ b/gr-atsc/include/atsc/slicer_agc_impl.h @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_SLICER_AGC_H_ +#define _ATSC_SLICER_AGC_H_ + +#include <atsc/api.h> +#include <math.h> +#include <filter/single_pole_iir.h> + +/*! + * \brief Automatic Gain Control class for atsc slicer + * + * Given perfect data, output values will be +/- {7, 5, 3, 1} + */ + +class ATSC_API atsci_slicer_agc { + + public: + atsci_slicer_agc () : _gain(1), dc(0.0025) {}; + + + float gain () { return _gain; } + +#if 1 + float scale (float input){ + float t = input * _gain; + float output = t - REFERENCE; + float error = REFERENCE - dc.filter (t); + _gain += error * RATE; + return output; + } +#else + float scale(float input){ + float avg = dc.filter(input); + if(fabs(avg)<.1)avg=.1; + _gain += _gain*.99 + .01* REFERENCE/avg; + return input*_gain - REFERENCE; + } +#endif + + protected: + + static const float REFERENCE = 1.25; // pilot reference value + static const float RATE = 1.0e-5; // adjustment rate + float _gain; // current gain + gr_single_pole_iir<float,float,float> dc; +}; + +#endif /* _ATSC_SLICER_AGC_H_ */ diff --git a/gr-atsc/include/atsc/sliding_correlator_impl.h b/gr-atsc/include/atsc/sliding_correlator_impl.h new file mode 100644 index 0000000000..45c0caa241 --- /dev/null +++ b/gr-atsc/include/atsc/sliding_correlator_impl.h @@ -0,0 +1,86 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_SLIDING_CORRELATOR_H_ +#define _ATSC_SLIDING_CORRELATOR_H_ + +#include <atsc/api.h> +#include <string.h> + +#include <atsc/pnXXX_impl.h> +//extern const unsigned char atsc_pn511[511]; +//extern const unsigned char atsc_pn63[63]; + +/*! + * \brief look for the PN 511 field sync pattern + */ +class ATSC_API atsci_sliding_correlator { + public: + + atsci_sliding_correlator (); + ~atsci_sliding_correlator (){}; + + //! input hard decision bit, return correlation (0,511) + // Result is the number of wrong bits. + // E.g., 0 -> perfect match; 511 -> all bits are wrong + + int input_bit (int bit); + + //! input sample, return correlation (0,511) + // Result is the number of wrong bits. + // E.g., 0 -> perfect match; 511 -> all bits are wrong + + int input_int (int sample){ + return input_bit (sample < 0 ? 0 : 1); + } + + //! input sample, return correlation (0,511) + // Result is the number of wrong bits. + // E.g., 0 -> perfect match; 511 -> all bits are wrong + + int input_float (float sample){ + return input_bit (sample < 0 ? 0 : 1); + } + + void reset () { input.reset (); } + + private: + + typedef unsigned long srblock; + static const int bits_per_char = 8; + static const int srblock_bitsize = sizeof (srblock) * bits_per_char; + static const int NSRBLOCKS = (511 + srblock_bitsize - 1) / srblock_bitsize; + + class shift_reg { + public: + shift_reg () { reset (); } + void reset () { memset (d, 0, sizeof (d)); } + void shift_in (int bit); + srblock d[NSRBLOCKS]; + }; + + shift_reg mask; // pattern we're looking for + shift_reg input; // current input window + shift_reg and_mask; // bits to consider +}; + +#endif /* _ATSC_SLIDING_CORRELATOR_H_ */ diff --git a/gr-atsc/include/atsc/sssr_impl.h b/gr-atsc/include/atsc/sssr_impl.h new file mode 100644 index 0000000000..60d116577b --- /dev/null +++ b/gr-atsc/include/atsc/sssr_impl.h @@ -0,0 +1,241 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +/* + * --- ATSC Segment and Symbol Sync Recovery --- + */ + +#ifndef _ATSC_SSSR_H_ +#define _ATSC_SSSR_H_ + +#include <atsc/api.h> +#include <atsc/consts.h> +#include <filter/mmse_fir_interpolator_ff.h> +#include <filter/single_pole_iir.h> +#include <cstdio> + +/* + * --- support classes for atsci_sssr --- + */ + +namespace sssr { + + typedef float sample_t; + + // ---------------------------------------------------------------- + //! digital correlator for 1001 and 0110 patterns + + class ATSC_API digital_correlator { + int d_sr; // 4 bit shift register + + public: + + // Constructor + digital_correlator () { reset (); } + + // Manipulators + + //! called on channel change + void reset () { d_sr = 0; } + + //! clock bit in and return true if we've seen 1001 + + bool update (int bit) { + d_sr = ((bit & 1) << 3) | (d_sr >> 1); + + return (d_sr == 0x9); // 1001 + } + + }; + + + // ---------------------------------------------------------------- + //! segment sync integrator + + class ATSC_API seg_sync_integrator { + signed char d_integrator[ATSC_DATA_SEGMENT_LENGTH]; + + public: + + // Constructor + seg_sync_integrator () { reset (); } + + // Manipulators + + //! called on channel change + void reset (); + + //! update current tap with weight and return integrated correlation value + int update (int weight, int index); + + //! return index of maximum correlation value + int find_max (int *value); + + }; + + // ---------------------------------------------------------------- + //! quad filter (used to compute timing error) + + class ATSC_API quad_filter { + sample_t d_delay[4]; + + public: + // Constructor + quad_filter () { reset (); } + + // Manipulators + + //! called on channel change + void reset () { d_delay[0] = d_delay[1] = d_delay[2] = d_delay[3] = 0; } + + double update (sample_t sample){ + d_delay[3] = d_delay[2]; + d_delay[2] = d_delay[1]; + d_delay[1] = d_delay[0]; + d_delay[0] = sample; + + // the coefficients are -1,-1,+1,+1 + return d_delay[3] + d_delay[2] - d_delay[1] - d_delay[0]; + } + }; +} + +// ---------------------------------------------------------------- + +/*! + * \brief ATSC Segment and Symbol Sync Recovery + * + * This class implements data segment sync tracking and symbol timing + * using the method described in "ATSC/VSB Tutorial - Receiver Technology" + * by Wayne E. Bretl of Zenith, pgs 41-45. + */ + +class ATSC_API atsci_sssr { + sssr::digital_correlator d_correlator; + sssr::seg_sync_integrator d_integrator; + sssr::quad_filter d_quad_filter; + double d_quad_output[ATSC_DATA_SEGMENT_LENGTH]; + double d_timing_adjust; + int d_counter; // free running mod 832 counter + int d_symbol_index; + bool d_seg_locked; + FILE *d_debug_fp; + + + bool incr_counter () { + d_counter++; + if (d_counter >= ATSC_DATA_SEGMENT_LENGTH){ + d_counter = 0; + return true; + } + return false; + } + + void incr_symbol_index () { + d_symbol_index++; + if (d_symbol_index >= ATSC_DATA_SEGMENT_LENGTH) + d_symbol_index = 0; + } + +public: + + // Constructor + atsci_sssr (); + ~atsci_sssr (); + + // Manipulators + + //! call on channel change + void reset (); + + + /*! + * \brief process a single sample at the ATSC symbol rate (~10.76 MSPS) + * + * This block computes an indication of our timing error and keeps + * track of where the segment sync's occur. \p timing_adjust is + * returned to indicate how the interpolator timing needs to be + * adjusted to track the transmitter's symbol timing. If \p seg_locked + * is true, then \p symbol_index is the index of this sample in + * the current segment. The symbols are numbered from 0 to 831, where + * symbols 0, 1, 2 and 3 correspond to the data segment sync pattern, + * nominally +5, -5, -5, +5. + */ + + void update (sssr::sample_t sample_in, // input + bool *seg_locked, // are we seeing segment syncs? + int *symbol_index, // 0..831 + double *timing_adjust); // how much to adjust timing + +}; + +// ---------------------------------------------------------------- + +/*! + * \brief interpolator control for segment and symbol sync recovery + */ + +class ATSC_API atsci_interpolator { + gr::filter::mmse_fir_interpolator_ff d_interp; + gr::filter::single_pole_iir<float,float,float> d_loop; // ``VCO'' loop filter + double d_nominal_ratio_of_rx_clock_to_symbol_freq; // FREQ + double d_w; // ratio of PERIOD of Tx to Rx clocks + double d_mu; // fractional delay [0,1] + int d_incr; // diagnostic only + FILE *d_debug_fp; // diagnostic only + +public: + //! \p nominal_ratio_of_rx_clock_to_symbol_freq must be >= 1.8 + atsci_interpolator (double nominal_ratio_of_rx_clock_to_symbol_freq); + ~atsci_interpolator (); + + // Manipulators + + //! call on channel change + void reset (); + + /*! + * \brief produce next sample referenced to Tx clock + * + * If there aren't enough input_samples left to produce + * an output, return false, else true. + */ + + bool update (const sssr::sample_t input_samples[], // I: vector of samples + int nsamples, // I: total number of samples + int *index, // I/O: current input index + double timing_adjustment, // I: how much to bump timing + sssr::sample_t *output_sample); // O: the output sample + + // Accessors + + // how much history we require on our input + unsigned ntaps () const { return d_interp.ntaps (); } + + // diagnostic accessors + double mu () const { return d_mu; } + double w () const { return d_w; } + int incr () const { return d_incr; } + +}; + +#endif /* _ATSC_SSSR_H_ */ diff --git a/gr-atsc/include/atsc/syminfo_impl.h b/gr-atsc/include/atsc/syminfo_impl.h new file mode 100644 index 0000000000..9f25e4902a --- /dev/null +++ b/gr-atsc/include/atsc/syminfo_impl.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef _ATSC_SYMINFO_H_ +#define _ATSC_SYMINFO_H_ + +namespace atsc { + + static const unsigned int SI_SEGMENT_NUM_MASK = 0x1ff; + static const unsigned int SI_FIELD_SYNC_SEGMENT_NUM = SI_SEGMENT_NUM_MASK; // conceptually -1 + + struct syminfo { + unsigned int symbol_num : 10; // 0..831 + unsigned int segment_num : 9; // 0..311 and SI_FIELD_SYNC_SEGMENT_NUM + unsigned int field_num : 1; // 0..1 + unsigned int valid : 1; // contents are valid + }; + + + static inline bool + tag_is_start_field_sync (syminfo tag) + { + return tag.symbol_num == 0 && tag.segment_num == SI_FIELD_SYNC_SEGMENT_NUM && tag.valid; + } + + static inline bool + tag_is_start_field_sync_1 (syminfo tag) + { + return tag_is_start_field_sync (tag) && tag.field_num == 0; + } + + static inline bool + tag_is_start_field_sync_2 (syminfo tag) + { + return tag_is_start_field_sync (tag) && tag.field_num == 1; + } + +} + +#endif /* _ATSC_SYMINFO_H_ */ diff --git a/gr-atsc/include/atsc/sync_tag_impl.h b/gr-atsc/include/atsc/sync_tag_impl.h new file mode 100644 index 0000000000..bdb64c5d3d --- /dev/null +++ b/gr-atsc/include/atsc/sync_tag_impl.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef _ATSC_SYNC_TAG_H_ +#define _ATSC_SYNC_TAG_H_ + +/* + * Constants used to communicate in the second stream passed between + * GrAtscFSCorrelator, GrAtscEqualizer and GrAtscFieldSyncMux. The + * second stream is sample-for-sample parallel with the streaming + * floating point in the first stream. The second stream provides + * information about alignment boundaries. + * + * These are in floating point because the current implementation + * requires that for a given module, all input streams share the same + * type and all output streams share the same type. We'd use unsigned + * char otherwise. + */ + +namespace atsc_sync_tag { + + // Nothing special + static const float NORMAL = 0.0; + + // The corresponding symbol is the first symbol of the + // data segment sync sequence { +5, -5, -5, +5 } + static const float START_SEG_SYNC = 1.0; + + // The corresponding symbol is the first symbol of the + // field sync 1 PN511 pattern. + static const float START_FIELD_SYNC_1 = 2.0; + + // The corresponding symbol is the first symbol of the + // field sync 2 PN511 pattern. + static const float START_FIELD_SYNC_2 = 3.0; +}; + +#endif /* _ATSC_SYNC_TAG_H_ */ diff --git a/gr-atsc/include/atsc/trellis_encoder.h b/gr-atsc/include/atsc/trellis_encoder.h new file mode 100644 index 0000000000..243dd7c2ce --- /dev/null +++ b/gr-atsc/include/atsc/trellis_encoder.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef INCLUDED_ATSC_TRELLIS_ENCODER_H +#define INCLUDED_ATSC_TRELLIS_ENCODER_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <atsc/trellis_encoder_impl.h> + +class atsc_trellis_encoder; +typedef boost::shared_ptr<atsc_trellis_encoder> atsc_trellis_encoder_sptr; + +ATSC_API atsc_trellis_encoder_sptr atsc_make_trellis_encoder(); + +/*! + * \brief ATSC 12-way interleaved trellis encoder (atsc_mpeg_packet_rs_encoded --> atsc_data_segment) + * \ingroup atsc + * + * input: atsc_mpeg_packet_rs_encoded; output: atsc_data_segment + */ +class ATSC_API atsc_trellis_encoder : public gr_sync_block +{ + friend ATSC_API atsc_trellis_encoder_sptr atsc_make_trellis_encoder(); + + atsci_trellis_encoder d_trellis_encoder; + + atsc_trellis_encoder(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } +}; + + +#endif /* INCLUDED_ATSC_TRELLIS_ENCODER_H */ diff --git a/gr-atsc/include/atsc/trellis_encoder_impl.h b/gr-atsc/include/atsc/trellis_encoder_impl.h new file mode 100644 index 0000000000..d20885ef36 --- /dev/null +++ b/gr-atsc/include/atsc/trellis_encoder_impl.h @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_TRELLIS_ENCODER_H_ +#define _ATSC_TRELLIS_ENCODER_H_ + +#include <atsc/api.h> +#include <atsc/basic_trellis_encoder_impl.h> +#include <atsc/types.h> + +/*! + * \brief fancy, schmancy 12-way interleaved trellis encoder for ATSC + */ + +class ATSC_API atsci_trellis_encoder { + public: + static const int NCODERS = 12; + + atsci_trellis_encoder (); + ~atsci_trellis_encoder (); + + //! reset all encoder states + void reset (); + + /*! + * Take 12 RS encoded, convolutionally interleaved segments and + * produce 12 trellis coded data segments. We work in groups of 12 + * because that's the smallest number of segments that composes a + * single full cycle of the encoder mux. + */ + void encode (atsc_data_segment out[NCODERS], + const atsc_mpeg_packet_rs_encoded in[NCODERS]); + + + protected: + static const int SEGMENT_SIZE = ATSC_MPEG_RS_ENCODED_LENGTH; // 207 + static const int INPUT_SIZE = (SEGMENT_SIZE * 12); + static const int OUTPUT_SIZE = (ATSC_DATA_SEGMENT_LENGTH * 12); + + void encode_helper (unsigned char out[OUTPUT_SIZE], + const unsigned char in[INPUT_SIZE]); + + atsci_basic_trellis_encoder enc[NCODERS]; + bool debug; +}; + + +#endif /* _ATSC_TRELLIS_ENCODER_H_ */ diff --git a/gr-atsc/include/atsc/types.h b/gr-atsc/include/atsc/types.h new file mode 100644 index 0000000000..759ef68ba7 --- /dev/null +++ b/gr-atsc/include/atsc/types.h @@ -0,0 +1,238 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_TYPES_H_ +#define _ATSC_TYPES_H_ + +#include <atsc/consts.h> +#include <cstring> +#include <cassert> + + +/*! + * \brief pipeline info that flows with data + * + * Not all modules need all the info + */ +class plinfo { +public: + plinfo () : _flags (0), _segno (0) { } + + // accessors + + bool field_sync1_p () const { return (_flags & fl_field_sync1) != 0; } + bool field_sync2_p () const { return (_flags & fl_field_sync2) != 0; } + bool field_sync_p () const { return field_sync1_p () || field_sync2_p (); } + + bool regular_seg_p () const { return (_flags & fl_regular_seg) != 0; } + + bool in_field1_p () const { return (_flags & fl_field2) == 0; } + bool in_field2_p () const { return (_flags & fl_field2) != 0; } + + bool first_regular_seg_p () const { return (_flags & fl_first_regular_seg) != 0; } + + bool transport_error_p () const { return (_flags & fl_transport_error) != 0; } + + unsigned int segno () const { return _segno; } + unsigned int flags () const { return _flags; } + + // setters + + void set_field_sync1 () + { + _segno = 0; + _flags = fl_field_sync1; + } + + void set_field_sync2 () + { + _segno = 0; + _flags = fl_field_sync2 | fl_field2; + } + + void set_regular_seg (bool field2, int segno) + { + assert (0 <= segno && segno < ATSC_DSEGS_PER_FIELD); + _segno = segno; + _flags = fl_regular_seg; + if (segno == 0) + _flags |= fl_first_regular_seg; + if (segno >= ATSC_DSEGS_PER_FIELD) + _flags |= fl_transport_error; + if (field2) + _flags |= fl_field2; + } + + void set_transport_error (bool error){ + if (error) + _flags |= fl_transport_error; + else + _flags &= ~fl_transport_error; + } + + // overload equality operator + bool operator== (const plinfo &other) const { + return (_flags == other._flags && _segno == other._segno); + } + + bool operator!= (const plinfo &other) const { + return !(_flags == other._flags && _segno == other._segno); + } + + /*! + * Set \p OUT such that it reflects a \p NSEGS_OF_DELAY + * pipeline delay from \p IN. + */ + static void delay (plinfo &out, const plinfo &in, int nsegs_of_delay); + + /*! + * confirm that \p X is plausible + */ + static void sanity_check (const plinfo &in); + + +protected: + unsigned short _flags; // bitmask + unsigned short _segno; // segment number [0,311] + + // these three are mutually exclusive + // This is a regular data segment. + static const int fl_regular_seg = 0x0001; + // This is a field sync segment, for 1st half of a field. + static const int fl_field_sync1 = 0x0002; + // This is a field sync segment, for 2nd half of a field. + static const int fl_field_sync2 = 0x0004; + + // This bit is on ONLY when fl_regular_seg is set AND when this is + // the first regular data segment AFTER a field sync segment. This + // segment causes various processing modules to reset. + static const int fl_first_regular_seg = 0x0008; + + // which field are we in? + static const int fl_field2 = 0x0010; // else field 1 + + // This bit is set when Reed-Solomon decoding detects an error that it + // can't correct. Note that other error detection (e.g. Viterbi) do not + // set it, since Reed-Solomon will correct many of those. This bit is + // then copied into the final Transport Stream packet so that MPEG + // software can see that the 188-byte data segment has been corrupted. + static const int fl_transport_error = 0x0020; +}; + + + + +class atsc_mpeg_packet { + public: + static const int NPAD = 68; + unsigned char data[ATSC_MPEG_DATA_LENGTH + 1]; // first byte is sync + unsigned char _pad_[NPAD]; // pad to power of 2 (256) + + // overload equality operator + bool operator== (const atsc_mpeg_packet &other) const { + return std::memcmp (data, other.data, sizeof (data)) == 0; + }; + + bool operator!= (const atsc_mpeg_packet &other) const { + return !(std::memcmp (data, other.data, sizeof (data)) == 0); + }; +}; + +class atsc_mpeg_packet_no_sync { + public: + static const int NPAD = 65; + plinfo pli; + unsigned char data[ATSC_MPEG_DATA_LENGTH]; + unsigned char _pad_[NPAD]; // pad to power of 2 (256) + + // overload equality operator + bool operator== (const atsc_mpeg_packet_no_sync &other) const { + return std::memcmp (data, other.data, sizeof (data)) == 0; + } + + bool operator!= (const atsc_mpeg_packet_no_sync &other) const { + return !(std::memcmp (data, other.data, sizeof (data)) == 0); + } +}; + +class atsc_mpeg_packet_rs_encoded { + public: + static const int NPAD = 45; + plinfo pli; + unsigned char data[ATSC_MPEG_RS_ENCODED_LENGTH]; + unsigned char _pad_[NPAD]; // pad to power of 2 (256) + + // overload equality operator + bool operator== (const atsc_mpeg_packet_rs_encoded &other) const { + return std::memcmp (data, other.data, sizeof (data)) == 0; + } + + bool operator!= (const atsc_mpeg_packet_rs_encoded &other) const { + return !(std::memcmp (data, other.data, sizeof (data)) == 0); + } +}; + + +//! contains 832 3 bit symbols. The low 3 bits in the byte hold the symbol. + +class atsc_data_segment { + public: + static const int NPAD = 188; + plinfo pli; + unsigned char data[ATSC_DATA_SEGMENT_LENGTH]; + unsigned char _pad_[NPAD]; // pad to power of 2 (1024) + + // overload equality operator + bool operator== (const atsc_data_segment &other) const { + return std::memcmp (data, other.data, sizeof (data)) == 0; + } + + bool operator!= (const atsc_data_segment &other) const { + return !(std::memcmp (data, other.data, sizeof (data)) == 0); + } +}; + +/*! + * Contains 832 bipolar floating point symbols. + * Nominal values are +/- {1, 3, 5, 7}. + * This data type represents the input to the viterbi decoder. + */ + +class atsc_soft_data_segment { + public: + static const int NPAD = 764; + plinfo pli; + float data[ATSC_DATA_SEGMENT_LENGTH]; + unsigned char _pad_[NPAD]; // pad to power of 2 (4096) + + // overload equality operator + bool operator== (const atsc_data_segment &other) const { + return std::memcmp (data, other.data, sizeof (data)) == 0; + } + + bool operator!= (const atsc_data_segment &other) const { + return !(std::memcmp (data, other.data, sizeof (data)) == 0); + } +}; + + +#endif /* _ATSC_TYPES_H_ */ diff --git a/gr-atsc/include/atsc/viterbi_decoder.h b/gr-atsc/include/atsc/viterbi_decoder.h new file mode 100644 index 0000000000..e119337553 --- /dev/null +++ b/gr-atsc/include/atsc/viterbi_decoder.h @@ -0,0 +1,62 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ATSC_VITERBI_DECODER_H +#define INCLUDED_ATSC_VITERBI_DECODER_H + +#include <atsc/api.h> +#include <gr_sync_block.h> +#include <atsc/viterbi_decoder_impl.h> + +class atsc_viterbi_decoder; +typedef boost::shared_ptr<atsc_viterbi_decoder> atsc_viterbi_decoder_sptr; + +ATSC_API atsc_viterbi_decoder_sptr atsc_make_viterbi_decoder(); + +/*! + * \brief ATSC 12-way interleaved viterbi decoder (atsc_soft_data_segment --> atsc_mpeg_packet_rs_encoded) + * \ingroup atsc + * + * input: atsc_soft_data_segment; output: atsc_mpeg_packet_rs_encoded + */ +class ATSC_API atsc_viterbi_decoder : public gr_sync_block +{ + friend ATSC_API atsc_viterbi_decoder_sptr atsc_make_viterbi_decoder(); + + atsci_viterbi_decoder d_viterbi_decoder; + + atsc_viterbi_decoder(); + +public: + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void reset() { /* nop */ } + +protected: + int last_start; + +}; + + +#endif /* INCLUDED_ATSC_VITERBI_DECODER_H */ diff --git a/gr-atsc/include/atsc/viterbi_decoder_impl.h b/gr-atsc/include/atsc/viterbi_decoder_impl.h new file mode 100644 index 0000000000..307b157a9b --- /dev/null +++ b/gr-atsc/include/atsc/viterbi_decoder_impl.h @@ -0,0 +1,84 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_VITERBI_DECODER_H_ +#define _ATSC_VITERBI_DECODER_H_ + +#define USE_SIMPLE_SLICER 0 + +#include <atsc/api.h> +#include <atsc/types.h> +#include <atsc/interleaver_fifo.h> + +#if (USE_SIMPLE_SLICER) +#include <atsc/fake_single_viterbi_impl.h> +typedef atsci_fake_single_viterbi single_viterbi_t; +#else +#include <atsc/single_viterbi_impl.h> +typedef atsci_single_viterbi single_viterbi_t; +#endif + +/*! + * \brief fancy, schmancy 12-way interleaved viterbi decoder for ATSC + */ + +class ATSC_API atsci_viterbi_decoder { +public: + static const int NCODERS = 12; + + atsci_viterbi_decoder (); + ~atsci_viterbi_decoder (); + + //! reset all decoder states + void reset (); + + /*! + * Take 12 data segments of soft decisions (floats) and + * produce 12 RS encoded data segments. We work in groups of 12 + * because that's the smallest number of segments that composes a + * single full cycle of the decoder mux. + */ + void decode (atsc_mpeg_packet_rs_encoded out[NCODERS], + const atsc_soft_data_segment in[NCODERS]); + + + + protected: + typedef interleaver_fifo<unsigned char> fifo_t; + + static const int SEGMENT_SIZE = ATSC_MPEG_RS_ENCODED_LENGTH; // 207 + static const int OUTPUT_SIZE = (SEGMENT_SIZE * 12); + static const int INPUT_SIZE = (ATSC_DATA_SEGMENT_LENGTH * 12); + + void decode_helper (unsigned char out[OUTPUT_SIZE], + const float in[INPUT_SIZE]); + + + single_viterbi_t viterbi[NCODERS]; + fifo_t *fifo[NCODERS]; + bool debug; + +}; + + + +#endif /* _ATSC_VITERBI_DECODER_H_ */ diff --git a/gr-atsc/include/atsc/vsbtx_lp_impl.h b/gr-atsc/include/atsc/vsbtx_lp_impl.h new file mode 100644 index 0000000000..d9640ca483 --- /dev/null +++ b/gr-atsc/include/atsc/vsbtx_lp_impl.h @@ -0,0 +1,37 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _ATSC_VSBTX_LP_H_ +#define _ATSC_VSBTX_LP_H_ + +#include <atsc/api.h> +#include <gr_fir_builder.h> + +class ATSC_API atsc_vsbtx_lp : public gr_fir_builder +{ +public: + virtual std::vector<float> taps (double sampling_freq); +}; + + + +#endif /* _ATSC_VSBTX_LP_H_ */ |