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_metrics_decode_viterbi_full_block.h>
28 #include <gr_io_signature.h>
32 gr_metrics_decode_viterbi_full_block_sptr
33 gr_make_metrics_decode_viterbi_full_block
34 (int sample_precision,
38 const std::vector<int> &code_generator,
40 int start_memory_state,
43 return gr_metrics_decode_viterbi_full_block_sptr
44 (new gr_metrics_decode_viterbi_full_block
55 gr_metrics_decode_viterbi_full_block_feedback_sptr
56 gr_make_metrics_decode_viterbi_full_block_feedback
57 (int sample_precision,
61 const std::vector<int> &code_generator,
62 const std::vector<int> &code_feedback,
64 int start_memory_state,
67 return gr_metrics_decode_viterbi_full_block_feedback_sptr
68 (new gr_metrics_decode_viterbi_full_block
80 gr_metrics_decode_viterbi_full_block::gr_metrics_decode_viterbi_full_block
81 (int sample_precision,
85 const std::vector<int> &code_generator,
87 int start_memory_state,
89 : gr_block ("metrics_decode_viterbi_full_block",
90 gr_make_io_signature (0, 0, 0),
91 gr_make_io_signature (0, 0, 0))
93 d_encoder = new encoder_convolutional_ic1_ic1 (frame_size_bits,
101 setup_io_signatures (sample_precision, n_code_inputs, n_code_outputs);
104 gr_metrics_decode_viterbi_full_block::gr_metrics_decode_viterbi_full_block
105 (int sample_precision,
109 const std::vector<int> &code_generator,
110 const std::vector<int> &code_feedback,
112 int start_memory_state,
113 int end_memory_state)
114 : gr_block ("metrics_decode_viterbi_full_block_feedback",
115 gr_make_io_signature (0, 0, 0),
116 gr_make_io_signature (0, 0, 0))
118 d_encoder = new encoder_convolutional_ic1_ic1 (frame_size_bits,
127 setup_io_signatures (sample_precision, n_code_inputs, n_code_outputs);
130 gr_metrics_decode_viterbi_full_block::~gr_metrics_decode_viterbi_full_block
138 gr_metrics_decode_viterbi_full_block::setup_io_signatures
139 (int sample_precision,
143 // create the decoder using:
145 // the "i1" input model: individual input streams; two per metric
146 // type (0-bit, 1-bit), single metric per input item (char, short, long)
148 // the "ic1" output model:
149 // individual output streams per decoded code input stream;
150 // each item is a 'char' type with 1 bit aligned on the LSB.
152 d_decoder = new decoder_viterbi_full_block_i1_ic1 (sample_precision,
155 // error checking is done in the encoder and decoder classes
156 // so just use the parameters as given; will be correct!
158 d_n_code_inputs = n_code_inputs;
159 d_n_code_outputs = n_code_outputs;
161 // output signature is always the same:
162 // sizeof (char) with 1 bit per char as the LSB
164 set_output_signature (gr_make_io_signature (d_n_code_inputs,
168 // determine the input signature element size
169 size_t l_input_item_size_bytes;
171 if (sample_precision == 0) {
173 l_input_item_size_bytes = sizeof (float);
174 } else if (sample_precision <= 8) {
176 l_input_item_size_bytes = sizeof (char);
177 } else if (sample_precision <= 16) {
179 l_input_item_size_bytes = sizeof (short);
182 l_input_item_size_bytes = sizeof (long);
185 set_input_signature (gr_make_io_signature (2*d_n_code_outputs,
187 l_input_item_size_bytes));
190 void gr_metrics_decode_viterbi_full_block::forecast
192 gr_vector_int &ninput_items_required)
194 int ninput_items = d_decoder->compute_n_input_metrics (noutput_items);
195 size_t ninputs = ninput_items_required.size();
196 for (size_t n = 0; n < ninputs; n++)
197 ninput_items_required[n] = ninput_items;
201 gr_metrics_decode_viterbi_full_block::general_work
203 gr_vector_int &ninput_items,
204 gr_vector_const_void_star &input_items,
205 gr_vector_void_star &output_items)
207 // FIXME: compute the actual number of output items (1 bit char's) created.
209 size_t t_n_input_items = d_decoder->compute_n_input_metrics (noutput_items);
210 size_t t_n_output_items = d_decoder->compute_n_output_bits (t_n_input_items);
212 assert (t_n_output_items == ((size_t)noutput_items));
214 // "work" is handled by the decoder; which returns the actual number
215 // of input items (metrics) used.
217 t_n_input_items = d_decoder->decode ((const char**)(&input_items[0]),
218 (char**)(&output_items[0]),
221 // consume the number of used input items on all input streams
223 consume_each (t_n_input_items);
225 // returns number of items written to each output stream
227 return (noutput_items);