3 * Copyright 2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
27 #include <gr_streams_encode_convolutional.h>
28 #include <gr_io_signature.h>
32 gr_streams_encode_convolutional_sptr
33 gr_make_streams_encode_convolutional
37 const std::vector<int> &code_generator,
39 int start_memory_state,
42 return gr_streams_encode_convolutional_sptr
43 (new gr_streams_encode_convolutional (frame_size_bits,
52 gr_streams_encode_convolutional_sptr
53 gr_make_streams_encode_convolutional_feedback
57 const std::vector<int> &code_generator,
58 const std::vector<int> &code_feedback,
60 int start_memory_state,
63 return gr_streams_encode_convolutional_sptr
64 (new gr_streams_encode_convolutional (frame_size_bits,
74 gr_streams_encode_convolutional::gr_streams_encode_convolutional
78 const std::vector<int> &code_generators,
80 int start_memory_state,
82 : gr_block ("streams_encode_convolutional",
83 gr_make_io_signature (0, 0, 0),
84 gr_make_io_signature (0, 0, 0))
86 // error checking is done by the encoder class itself;
87 // just pass items on here.
89 d_encoder = new encoder_convolutional_ic1_ic1 (frame_size_bits,
97 setup_io_signatures (n_code_inputs, n_code_outputs);
100 gr_streams_encode_convolutional::gr_streams_encode_convolutional
101 (int frame_size_bits,
104 const std::vector<int> &code_generators,
105 const std::vector<int> &code_feedback,
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))
113 // error checking is done by the encoder class itself;
114 // just pass items on here.
116 d_encoder = new encoder_convolutional_ic1_ic1 (frame_size_bits,
125 setup_io_signatures (n_code_inputs, n_code_outputs);
129 gr_streams_encode_convolutional::setup_io_signatures
133 fprintf (stderr, "gr_s_e_c: d_encoder == %X\n", (unsigned int)d_encoder);
135 // create the correct input signature; 1 bit per input char
137 set_input_signature (gr_make_io_signature (n_code_inputs,
141 // create the correct output signature; 1 bit per output char
143 set_output_signature (gr_make_io_signature (n_code_outputs,
147 // no need to set the output multiple (to 1 item), since 1 is the
148 // default, and the encoder class handles the rest internally
150 // no need to set the relative rate (# out / # in) because for each
151 // input bit per input stream there is 1 output bit per output
152 // stream ... with a little added for termination, but ignore those.
155 gr_streams_encode_convolutional::~gr_streams_encode_convolutional
163 * Compute the number of input items needed to produce 'n_output'
164 * bits. Handled internally by the encoder.
167 void gr_streams_encode_convolutional::forecast
169 gr_vector_int &ninput_items_required)
171 fprintf (stderr, "gr_s_e_c::forecast: #out = %d\n",
174 int ninput_items = d_encoder->compute_n_input_bits (noutput_items);
176 fprintf (stderr, "s_e_c::forecast: #out = %d, #in = %d\n",
177 noutput_items, ninput_items);
179 size_t ninputs = ninput_items_required.size();
180 for (size_t n = 0; n < ninputs; n++)
181 ninput_items_required[n] = ninput_items;
185 gr_streams_encode_convolutional::general_work
187 gr_vector_int &ninput_items,
188 gr_vector_const_void_star &input_items,
189 gr_vector_void_star &output_items)
191 fprintf (stderr, "gr_s_e_c::general_work: Starting #out = %d\n",
194 // FIXME: compute the actual number of output items (1 bit char's) created.
196 size_t t_n_input_items = d_encoder->compute_n_input_bits (noutput_items);
199 size_t t_n_output_items = d_encoder->compute_n_output_bits (t_n_input_items);
201 assert (t_n_output_items == ((size_t)noutput_items));
204 // "work" is handled by the encoder; which returns the actual number
205 // of input items (1-bit char's) used.
207 t_n_input_items = d_encoder->encode ((const char **)(&input_items[0]),
208 (char **)(&output_items[0]),
209 (size_t) noutput_items);
213 // consume the number of used input items on all input streams
215 consume_each (t_n_input_items);
217 // returns number of items written to each output stream
219 return (noutput_items);