Houston, we have a trunk.
[debian/gnuradio] / gr-error-correcting-codes / src / lib / gr_metrics_decode_viterbi_full_block.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifndef INCLUDED_GR_METRICS_DECODE_VITERBI_FULL_BLOCK_H
24 #define INCLUDED_GR_METRICS_DECODE_VITERBI_FULL_BLOCK_H
25
26 #include <gr_block.h>
27 #include <libecc/decoder_viterbi_full_block_i1_ic1.h>
28 #include <libecc/encoder_convolutional_ic1_ic1.h>
29
30 class gr_metrics_decode_viterbi_full_block;
31
32 typedef boost::shared_ptr<gr_metrics_decode_viterbi_full_block>
33 gr_metrics_decode_viterbi_full_block_sptr,
34 gr_metrics_decode_viterbi_full_block_feedback_sptr;
35
36 gr_metrics_decode_viterbi_full_block_sptr
37 gr_make_metrics_decode_viterbi_full_block
38 (int frame_size_bits,
39  int n_code_inputs,
40  int n_code_outputs,
41  std::vector<int> code_generator,
42  bool do_termination = true,
43  int start_memory_state = 0,
44  int end_memory_state = 0);
45
46 gr_metrics_decode_viterbi_full_block_feedback_sptr
47 gr_make_metrics_decode_viterbi_full_block_feedback
48 (int frame_size_bits,
49  int n_code_inputs,
50  int n_code_outputs,
51  std::vector<int> code_generator,
52  std::vector<int> code_feedback,
53  bool do_termination = true,
54  int start_memory_state = 0,
55  int end_memory_state = 0);
56
57 /*!
58  * \brief Decode the incoming streams using a Viterbi-style decoder,
59  *     full trellis block decoding.
60  *
61  * input: symbol metrics data.
62  *
63  * output: stream(s) of char, single bit stored in the LSB.
64  */
65
66 class gr_metrics_decode_viterbi_full_block : public gr_block
67 {
68   friend gr_metrics_decode_viterbi_full_block_sptr
69   gr_make_metrics_decode_viterbi_full_block
70   (int sample_precision,
71    int frame_size_bits,
72    int n_code_inputs,
73    int n_code_outputs,
74    const std::vector<int> &code_generator,
75    bool do_termination,
76    int start_memory_state,
77    int end_memory_state);
78
79   friend gr_metrics_decode_viterbi_full_block_feedback_sptr
80   gr_make_metrics_decode_viterbi_full_block_feedback
81   (int sample_precision,
82    int frame_size_bits,
83    int n_code_inputs,
84    int n_code_outputs,
85    const std::vector<int> &code_generator,
86    const std::vector<int> &code_feedback,
87    bool do_termination,
88    int start_memory_state,
89    int end_memory_state);
90 /*
91  * frame_size_bits: if == 0, then do streaming decoding (infinite
92  *     trellis); otherwise this is the block size to decode before
93  *     terminating the trellis.
94  *
95  * code_generator: vector of integers (32 bit) representing the code
96  *     to be implemented in octal form.  E.g. "04" in binary is "100",
97  *     which would be "D^2" for code generation.  "06" == 110b == "D^2 + D"
98  *  ==> The vector is listed in order for each input stream, so if there
99  *     are 2 input streams (I1, I2) [specified in "n_code_inputs"]
100  *     and 2 output streams (O1, O2) [specified in "n_code_outputs"],
101  *     then the vector would be the code generator for:
102  *       [I1->O1, I1->O2, I2->O1, I2->O2]
103  *     with each element being the octal representation of the code.
104  *
105  * do_termination is valid only if frame_size_bits != 0, and defines
106  *     whether or not to to trellis termination.
107  *
108  * do_mux_input: is true, then the one input stream will be
109  *     interpreted as the multiplexing all of the input bits.  For
110  *     example for a 3 input decoder, the input stream would be
111  *     [I1[k], I2[k], I3[k], I1[k+1], I2[k+1], ...], where "k" is the
112  *     input sample time, and "I1" through "I3" are the 3 input
113  *     streams.
114  *
115  * n_code_inputs: the number of decoder-input (encoder-output)
116  *     streams, no matter if separate or mux'ed
117  *
118  * n_code_outputs: the number of decoder-output (encoder-input) streams
119  */
120
121   gr_metrics_decode_viterbi_full_block
122   (int sample_precision,
123    int frame_size_bits,
124    int n_code_inputs,
125    int n_code_outputs,
126    const std::vector<int> &code_generator,
127    bool do_termination,
128    int start_memory_state,
129    int end_memory_state);
130
131   gr_metrics_decode_viterbi_full_block
132   (int sample_precision,
133    int frame_size_bits,
134    int n_code_inputs,
135    int n_code_outputs,
136    const std::vector<int> &code_generator,
137    const std::vector<int> &code_feedback,
138    bool do_termination,
139    int start_memory_state,
140    int end_memory_state);
141
142 public:
143   ~gr_metrics_decode_viterbi_full_block ();
144
145   virtual void forecast (int noutput_items,
146                          gr_vector_int &ninput_items_required);
147
148   virtual int general_work (int noutput_items,
149                             gr_vector_int &ninput_items,
150                             gr_vector_const_void_star &input_items,
151                             gr_vector_void_star &output_items);
152
153 protected:
154   void setup_io_signatures (int sample_precision,
155                             int n_code_inputs,
156                             int n_code_outputs);
157
158   int d_n_code_inputs, d_n_code_outputs;
159   decoder_viterbi_full_block_i1_ic1* d_decoder;
160   encoder_convolutional_ic1_ic1* d_encoder;
161 };
162
163 #endif /* INCLUDED_GR_METRICS_DECODE_VITERBI_FULL_BLOCK_H */