Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / gr-error-correcting-codes / src / lib / ecc_streams_encode_convolutional.cc
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 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <ecc_streams_encode_convolutional.h>
28 #include <gr_io_signature.h>
29 #include <assert.h>
30 #include <iostream>
31
32 ecc_streams_encode_convolutional_sptr 
33 ecc_make_streams_encode_convolutional
34 (int frame_size_bits,
35  int n_code_inputs,
36  int n_code_outputs,
37  const std::vector<int> &code_generator,
38  bool do_termination,
39  int start_memory_state,
40  int end_memory_state)
41 {
42   return ecc_streams_encode_convolutional_sptr
43     (new ecc_streams_encode_convolutional (frame_size_bits,
44                                           n_code_inputs,
45                                           n_code_outputs,
46                                           code_generator,
47                                           do_termination,
48                                           start_memory_state,
49                                           end_memory_state));
50 }
51
52 ecc_streams_encode_convolutional_sptr 
53 ecc_make_streams_encode_convolutional_feedback
54 (int frame_size_bits,
55  int n_code_inputs,
56  int n_code_outputs,
57  const std::vector<int> &code_generator,
58  const std::vector<int> &code_feedback,
59  bool do_termination,
60  int start_memory_state,
61  int end_memory_state)
62 {
63   return ecc_streams_encode_convolutional_sptr
64     (new ecc_streams_encode_convolutional (frame_size_bits,
65                                           n_code_inputs,
66                                           n_code_outputs,
67                                           code_generator,
68                                           code_feedback,
69                                           do_termination,
70                                           start_memory_state,
71                                           end_memory_state));
72 }
73
74 ecc_streams_encode_convolutional::ecc_streams_encode_convolutional
75 (int frame_size_bits,
76  int n_code_inputs,
77  int n_code_outputs,
78  const std::vector<int> &code_generators,
79  bool do_termination,
80  int start_memory_state,
81  int end_memory_state)
82   : gr_block ("streams_encode_convolutional",
83               gr_make_io_signature (0, 0, 0),
84               gr_make_io_signature (0, 0, 0))
85 {
86   // error checking is done by the encoder class itself;
87   // just pass items on here.
88
89   d_encoder = new encoder_convolutional (frame_size_bits,
90                                          n_code_inputs,
91                                          n_code_outputs,
92                                          code_generators,
93                                          do_termination,
94                                          start_memory_state,
95                                          end_memory_state);
96
97   setup_io_signatures (n_code_inputs, n_code_outputs);
98 }
99
100 ecc_streams_encode_convolutional::ecc_streams_encode_convolutional
101 (int frame_size_bits,
102  int n_code_inputs,
103  int n_code_outputs,
104  const std::vector<int> &code_generators,
105  const std::vector<int> &code_feedback,
106  bool do_termination,
107  int start_memory_state,
108  int end_memory_state)
109   : gr_block ("streams_encode_convolutional_feedback",
110               gr_make_io_signature (0, 0, 0),
111               gr_make_io_signature (0, 0, 0))
112 {
113   // error checking is done by the encoder class itself;
114   // just pass items on here.
115
116   d_encoder = new encoder_convolutional (frame_size_bits,
117                                          n_code_inputs,
118                                          n_code_outputs,
119                                          code_generators,
120                                          code_feedback,
121                                          do_termination,
122                                          start_memory_state,
123                                          end_memory_state);
124
125   setup_io_signatures (n_code_inputs, n_code_outputs);
126 }
127
128 void
129 ecc_streams_encode_convolutional::setup_io_signatures
130 (int n_code_inputs,
131  int n_code_outputs)
132 {
133   // create the correct input signature; 1 bit per input char
134
135   d_in_buf = new code_input_ic1l (n_code_inputs);
136   set_input_signature (gr_make_io_signature (n_code_inputs,
137                                              n_code_inputs,
138                                              sizeof (char)));
139
140   // create the correct output signature; 1 bit per output char
141
142   d_out_buf = new code_output_ic1l (n_code_outputs);
143   set_output_signature (gr_make_io_signature (n_code_outputs,
144                                               n_code_outputs,
145                                               sizeof (char)));
146 }
147
148 ecc_streams_encode_convolutional::~ecc_streams_encode_convolutional
149 ()
150 {
151   delete d_encoder;
152   d_encoder = 0;
153   delete d_in_buf;
154   d_in_buf = 0;
155   delete d_out_buf;
156   d_out_buf = 0;
157 }
158
159 /*
160  * Compute the number of input items needed to produce 'n_output'
161  * bits.  Handled internally by the encoder.
162  */
163
164 void ecc_streams_encode_convolutional::forecast
165 (int noutput_items,
166  gr_vector_int &ninput_items_required)
167 {
168   int ninput_items = d_encoder->compute_n_input_bits (noutput_items);
169   size_t ninputs = ninput_items_required.size();
170   for (size_t n = 0; n < ninputs; n++)
171     ninput_items_required[n] = ninput_items;
172 }
173
174 int
175 ecc_streams_encode_convolutional::general_work
176 (int noutput_items,
177  gr_vector_int &ninput_items,
178  gr_vector_const_void_star &input_items,
179  gr_vector_void_star &output_items)
180 {
181   // compute the actual number of output items (1 bit char's) created.
182
183   size_t t_n_input_items = d_encoder->compute_n_input_bits (noutput_items);
184 #if 1
185   size_t t_n_output_items = d_encoder->compute_n_output_bits (t_n_input_items);
186   assert (t_n_output_items == ((size_t)noutput_items));
187 #endif
188   // setup the i/o buffers
189
190   d_in_buf->set_buffer ((void**)(&input_items[0]), t_n_input_items);
191   d_out_buf->set_buffer ((void**)(&output_items[0]), noutput_items);
192
193   // "work" is handled by the encoder; which returns the actual number
194   // of input items (1-bit char's) used.
195
196   t_n_input_items = d_encoder->encode (d_in_buf, d_out_buf,
197                                        (size_t) noutput_items);
198
199   assert (0);
200
201   // consume the number of used input items on all input streams
202
203   consume_each (t_n_input_items);
204
205   // returns number of items written to each output stream
206
207   return (noutput_items);
208 }