Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / gr-error-correcting-codes / src / lib / ecc_streams_encode_convolutional.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., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef INCLUDED_ECC_STREAMS_ENCODE_CONVOLUTIONAL_H
24 #define INCLUDED_ECC_STREAMS_ENCODE_CONVOLUTIONAL_H
25
26 #include <gr_block.h>
27 #include <libecc/encoder_convolutional.h>
28
29 /*!
30  * \brief Encode the incoming streams using a convolutional encoder
31  *
32  * input: streams of char, one stream per input as defined by the
33  *     instantiated code, using only the right-most justified bit as
34  *     the single input bit per input item.
35  *
36  * output: streams of char, one stream per output as defined by the
37  *     instantiated code, using only the right-most justified bit as
38  *     the single output bit per output item.
39  *
40  * frame_size_bits: if == 0, then do streaming encoding ("infinite"
41  *     trellis); otherwise this is the frame size in bits to encode
42  *     before terminating the trellis.  This value -does not- include
43  *     any termination bits.
44  *
45  * n_code_inputs:
46  * n_code_outputs:
47  * code_generator: vector of integers (32 bit) representing the code
48  *     to be implemented.  E.g. "4" in binary is "100", which would be
49  *     "D^2" for code generation.  "6" == 110b == "D^2 + D"
50  *  ==> The vector is listed in order for each output stream, so if there
51  *     are 2 input streams (I1, I2) [specified in "n_code_inputs"]
52  *     and 2 output streams (O1, O2) [specified in "n_code_outputs"],
53  *     then the vector would be the code generator for:
54  *       [I1->O1, I2->O1, I1->O2, I2->O2]
55  *     with each element being an integer representation of the code.
56  *
57  * do_termination: valid only if frame_size_bits != 0, and defines
58  *     whether or not to use trellis termination.  Default is to use
59  *     termination when doing block coding.
60  *
61  * start_memory_state: when starting a new block, the starting memory
62  *     state to begin encoding; there will be a helper function to
63  *     assist in creating this value for a given set of inputs;
64  *     default is the "all zero" state.
65  * 
66  * end_memory_state: when terminating a block, the ending memory
67  *     state to stop encoding; there will be a helper function to
68  *     assist in creating this value for a given set of inputs;
69  *     default is the "all zero" state.
70  */
71
72 class ecc_streams_encode_convolutional;
73 typedef boost::shared_ptr<ecc_streams_encode_convolutional>
74   ecc_streams_encode_convolutional_sptr;
75
76 ecc_streams_encode_convolutional_sptr
77 ecc_make_streams_encode_convolutional
78 (int frame_size_bits,
79  int n_code_inputs,
80  int n_code_outputs,
81  const std::vector<int> &code_generator,
82  bool do_termination = true,
83  int start_memory_state = 0,
84  int end_memory_state = 0);
85
86 ecc_streams_encode_convolutional_sptr
87 ecc_make_streams_encode_convolutional_feedback
88 (int frame_size_bits,
89  int n_code_inputs,
90  int n_code_outputs,
91  const std::vector<int> &code_generator,
92  const std::vector<int> &code_feedback,
93  bool do_termination = true,
94  int start_memory_state = 0,
95  int end_memory_state = 0);
96
97 class ecc_streams_encode_convolutional : public gr_block
98 {
99 protected:
100   friend ecc_streams_encode_convolutional_sptr
101   ecc_make_streams_encode_convolutional
102   (int frame_size_bits,
103    int n_code_inputs,
104    int n_code_outputs,
105    const std::vector<int> &code_generator,
106    bool do_termination,
107    int start_memory_state,
108    int end_memory_state);
109
110   friend ecc_streams_encode_convolutional_sptr
111   ecc_make_streams_encode_convolutional_feedback
112   (int frame_size_bits,
113    int n_code_inputs,
114    int n_code_outputs,
115    const std::vector<int> &code_generator,
116    const std::vector<int> &code_feedback,
117    bool do_termination,
118    int start_memory_state,
119    int end_memory_state);
120
121   ecc_streams_encode_convolutional (int frame_size_bits,
122                                    int n_code_inputs,
123                                    int n_code_outputs,
124                                    const std::vector<int> &code_generator,
125                                    bool do_termination,
126                                    int start_memory_state,
127                                    int end_memory_state);
128
129   ecc_streams_encode_convolutional (int frame_size_bits,
130                                    int n_code_inputs,
131                                    int n_code_outputs,
132                                    const std::vector<int> &code_generator,
133                                    const std::vector<int> &code_feedback,
134                                    bool do_termination,
135                                    int start_memory_state,
136                                    int end_memory_state);
137
138   void setup_io_signatures (int n_code_inputs, int n_code_outputs);
139
140   encoder_convolutional* d_encoder;
141   code_input_ptr d_in_buf;
142   code_output_ptr d_out_buf;
143
144 public:
145   ~ecc_streams_encode_convolutional ();
146
147   inline encoder_convolutional* encoder () {return (d_encoder);};
148
149   virtual void forecast (int noutput_items,
150                          gr_vector_int &ninput_items_required);
151
152   virtual int general_work (int noutput_items,
153                             gr_vector_int &ninput_items,
154                             gr_vector_const_void_star &input_items,
155                             gr_vector_void_star &output_items);
156 };
157
158 #endif /* INCLUDED_ECC_STREAMS_ENCODE_CONVOLUTIONAL_H */