Houston, we have a trunk.
[debian/gnuradio] / gr-error-correcting-codes / src / lib / libecc / decoder_viterbi_full_block_i1_ic1.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., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "decoder_viterbi_full_block_i1_ic1.h"
28 #include <assert.h>
29 #include <iostream>
30 #include <math.h>
31
32 const int g_max_block_size_bits = 10000000;
33 const int g_max_num_streams = 10;
34 const int g_num_bits_per_byte = 8;
35
36 #define DO_TIME_THOUGHPUT 0
37
38 #define DO_PRINT_DEBUG_INST 0
39 #define DO_PRINT_DEBUG_FSM 0
40 #define DO_PRINT_DEBUG_INIT 0
41 #define DO_PRINT_DEBUG_UP 0
42 #define DO_PRINT_DEBUG_UP_0 0
43 #define DO_PRINT_DEBUG_UP_1 0
44 #define DO_PRINT_DEBUG_MIDDLE 0
45 #define DO_PRINT_DEBUG_MIDDLE_0 0
46 #define DO_PRINT_DEBUG_MIDDLE_1 0
47 #define DO_PRINT_DEBUG_TERM 0
48 #define DO_PRINT_DEBUG_TERM_1 0
49 #define DO_PRINT_DEBUG_OUTPUT 0
50 #define DO_PRINT_DEBUG_OUTPUT_0 0
51 #define DO_PRINT_DEBUG_EXIT 0
52 #define DO_PRINT_DEBUG 1
53
54 #if DO_TIME_THOUGHPUT
55 #include <mld/mld_timer.h>
56 #endif
57 #if DO_PRINT_DEBUG
58 #include <mld/n2bs.h>
59 #endif
60
61 // FIXME
62
63 size_t
64 decoder_viterbi_full_block_i1_ic1::compute_n_output_bits
65 (size_t n_input_items)
66 {
67   assert (0);
68   return (0);
69 }
70
71 /*
72  * Compute the number of input items (metrics) needed to produce
73  * 'noutput' bits.  For convolutional decoders, there is 1
74  * bit output per metric input per stream, with the addition of a some
75  * metrics for trellis termination if selected.  Without termination,
76  * there is exactly 1:1 input to output (1 metric in to 1 bit out),
77  * no matter the encoding type.
78  *
79  * if (not terminating), then get the number of output bits.
80  *
81  * otherwise, find the number of blocks (not necessarily an integer),
82  * and then compute the number of input metrics (including termination)
83  * required to produce those blocks.  Subtract the number of bits
84  * leftover from the previous computation, then find the number of input
85  * metrics, ceil'd to make sure there are enough.
86  */
87
88 size_t
89 decoder_viterbi_full_block_i1_ic1::compute_n_input_metrics
90 (size_t n_output_bits)
91 {
92   int t_ninput_items = 0;
93   int t_noutput_bits = ((int) n_output_bits) - ((int) d_n_saved_bits);
94
95   // if there are enough saved bits, just use those, no inputs required
96
97   if (t_noutput_bits <= 0)
98     return (0);
99
100   // remove any bits already in the decoding trellis
101
102   if (d_time_count != 0) {
103     int t_time_bits = ((d_time_count > d_block_size_bits) ? 0 :
104                        d_block_size_bits - d_time_count);
105     t_noutput_bits -= t_time_bits;
106     t_ninput_items += t_time_bits;
107   }
108   // if completing this trellis doesn't create enough outputs ...
109
110   if (t_noutput_bits > 0) {
111
112     // there is a 1:1 ratio between input symbols and output bits (per
113     // stream), except for termination bits which are already taken
114     // into account in the total # of input bits per stream class
115     // variable; need to round the # output bits to the
116
117     // find the number of blocks, ceil'd to the next higher integer
118
119     int t_nblocks = (int) ceilf (((float) t_noutput_bits) /
120                                  ((float) d_block_size_bits));
121
122     // find the number of required input bits
123
124     t_ninput_items += t_nblocks * d_n_total_inputs_per_stream;
125   }
126
127   return (t_ninput_items);
128 }
129
130 // FIXME, from here down dummies to get correct compiling; for testing
131 // purposes only.
132
133 void
134 decoder_viterbi_full_block_i1_ic1::increment_input_indices
135 (bool while_decoding)
136 {
137   if (while_decoding)
138     std::cout << "foo!";
139
140 #if 0
141 // increment the in_buf index, depending on mux'ing or not
142   t_in_buf_ndx += (d_do_mux_inputs == false) ? 1 : d_n_code_outputs;
143 #endif
144 }
145
146 void
147 decoder_viterbi_full_block_i1_ic1::increment_output_indices
148 (bool while_decoding)
149 {
150   if (while_decoding)
151     std::cout << "bar!";
152 }
153
154 void
155 decoder_viterbi_full_block_i1_ic1::output_bit
156 (char t_out_bit,
157  char** out_buf,
158  size_t t_output_stream)
159 {
160   if (t_out_bit)
161     std::cout << "mop!";
162 }