Houston, we have a trunk.
[debian/gnuradio] / gr-error-correcting-codes / src / lib / gr_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., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifndef INCLUDED_GR_STREAMS_ENCODE_CONVOLUTIONAL_H
24 #define INCLUDED_GR_STREAMS_ENCODE_CONVOLUTIONAL_H
25
26 #include <gr_block.h>
27 #include <libecc/encoder_convolutional_ic1_ic1.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 gr_streams_encode_convolutional;
73 typedef boost::shared_ptr<gr_streams_encode_convolutional>
74   gr_streams_encode_convolutional_sptr;
75
76 gr_streams_encode_convolutional_sptr
77 gr_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 gr_streams_encode_convolutional_sptr
87 gr_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 gr_streams_encode_convolutional : public gr_block
98 {
99   friend gr_streams_encode_convolutional_sptr
100   gr_make_streams_encode_convolutional
101   (int frame_size_bits,
102    int n_code_inputs,
103    int n_code_outputs,
104    const std::vector<int> &code_generator,
105    bool do_termination,
106    int start_memory_state,
107    int end_memory_state);
108
109   friend gr_streams_encode_convolutional_sptr
110   gr_make_streams_encode_convolutional_feedback
111   (int frame_size_bits,
112    int n_code_inputs,
113    int n_code_outputs,
114    const std::vector<int> &code_generator,
115    const std::vector<int> &code_feedback,
116    bool do_termination,
117    int start_memory_state,
118    int end_memory_state);
119
120   gr_streams_encode_convolutional (int frame_size_bits,
121                                    int n_code_inputs,
122                                    int n_code_outputs,
123                                    const std::vector<int> &code_generator,
124                                    bool do_termination,
125                                    int start_memory_state,
126                                    int end_memory_state);
127
128   gr_streams_encode_convolutional (int frame_size_bits,
129                                    int n_code_inputs,
130                                    int n_code_outputs,
131                                    const std::vector<int> &code_generator,
132                                    const std::vector<int> &code_feedback,
133                                    bool do_termination,
134                                    int start_memory_state,
135                                    int end_memory_state);
136
137   void setup_io_signatures (int n_code_inputs, int n_code_outputs);
138
139   encoder_convolutional_ic1_ic1* d_encoder;
140
141 public:
142   ~gr_streams_encode_convolutional ();
143
144   inline encoder_convolutional_ic1_ic1* encoder () {return (d_encoder);};
145
146   virtual void forecast (int noutput_items,
147                          gr_vector_int &ninput_items_required);
148
149   virtual int general_work (int noutput_items,
150                             gr_vector_int &ninput_items,
151                             gr_vector_const_void_star &input_items,
152                             gr_vector_void_star &output_items);
153 };
154
155 #endif /* INCLUDED_GR_STREAMS_ENCODE_CONVOLUTIONAL_H */