Houston, we have a trunk.
[debian/gnuradio] / gr-error-correcting-codes / src / lib / libecc / encoder_turbo.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_ENCODER_TURBO_H
24 #define INCLUDED_ENCODER_TURBO_H
25
26 #include "encoder_convolutional.h"
27 #include <vector>
28
29 class encoder_turbo : public encoder
30 {
31 public:
32 /*!
33  * class encoder_turbo : public encoder
34  *
35  * Encode the incoming streams using a turbo encoder; This is a
36  *     virtual class which defines the basics of a turbo encoder, but
37  *     not how input and output bits are handled.  These features are
38  *     all defined by overriding methods appropriately.
39  *
40  * n_code_inputs:
41  * n_code_outputs: the total number of code inputs and outputs for the
42  *     overall turbo encoder (not just the constituent codes).
43  *
44  * encoders: the constituent encoders to be used; all -should- be
45  *     configured with the same "block_size" and "termination", though
46  *     from this encoder's perspective it doesn't really matter.
47  *
48  * interleavers: the interleavers to use before each encoder,
49  *     respectively, except the first encoder which will not use an
50  *     interleaver.
51  */
52
53   encoder_turbo
54   (int n_code_inputs,
55    int n_code_outputs,
56    const std::vector<encoder_convolutional*> &encoders,
57    const std::vector<size_t> &interleavers);
58
59   virtual ~encoder_turbo () {};
60
61 /* for remote access to internal info */
62
63   inline bool do_termination () {return (d_do_termination);};
64
65 #if 1
66   virtual size_t compute_n_input_bits (size_t n_output_bits);
67   virtual size_t compute_n_output_bits (size_t n_input_bits);
68 #endif
69
70 protected:
71 /*
72  * fsm_enc_turbo_t: finite state machine for the turbo encoder;
73  *     output happens all the time, so that's built-in to each state.
74  *
75  * fsm_enc_turbo_init: initialize for a new frame / block; this is already
76  *     done at instantiation, so do it only at the end of a block.
77  *
78  * fsm_enc_turbo_doing_input: doing encoding inside the trellis
79  *
80  * fsm_enc_turbo_doing_term: termination trellis, if requested
81  */
82
83   enum fsm_enc_turbo_t {
84     fsm_enc_turbo_init, fsm_enc_turbo_doing_input, fsm_enc_turbo_doing_term
85   };
86
87 /*
88  * maio(i,o): matrix access into a vector, knowing the # of code
89  *     outputs (from inside the class). References into a vector with
90  *     code inputs ordered by code output.
91  *
92  * 'i' is the first dimension - immediate memory order first - the code input
93  * 'o' is the second dimension - slower memory order second - the code output
94  *
95  * returns ((o*n_code_outputs) + i)
96  */
97
98   inline size_t maio(size_t i, size_t o) {return ((o*d_n_code_outputs) + i);};
99
100 /*
101  * maoi(i,o): matrix access into a vector, knowing the # of code
102  *     inputs (from inside the class). References into a vector with
103  *     code outputs ordered by code input.
104  *
105  * 'o' is the first dimension - immediate memory order first - the code output
106  * 'i' is the second dimension - slower memory order second - the code input
107  *
108  * returns ((i*n_code_inputs) + o)
109  */
110
111   inline size_t maoi(size_t i, size_t o) {return ((i*d_n_code_inputs) + o);};
112
113   // methods defined in this class
114 #if 1
115   // temporary just to get full compilation
116
117   virtual void encode_private (const char** in_buf, char** out_buf);
118   virtual char get_next_bit (const char** in_buf, size_t code_input_n);
119   virtual void output_bit (char t_out_bit, char** out_buf,
120                            size_t t_output_stream);
121 #else
122   virtual void encode_private (const char** in_buf, char** out_buf) = 0;
123   virtual void encode_loop (const char** in_buf, char** out_buf,
124                             size_t* which_counter, size_t how_many) = 0;
125   virtual char get_next_bit (const char** in_buf, size_t code_input_n) = 0;
126   virtual char get_next_bit__term (size_t code_input_n) = 0;
127
128   // methods which are required by classes which inherit from this
129   // one; primarily just the parts which deal with getting input bits
130   // and writing output bits, changing the indices for those buffers.
131
132   virtual char get_next_bit__input (const char** in_buf,
133                                     size_t code_input_n) = 0;
134   virtual void increment_io_indices (bool while_encoding) = 0;
135 #endif
136
137   // variables
138
139   fsm_enc_turbo_t d_fsm_state;
140   bool d_do_termination;
141   size_t d_max_memory, d_n_memories;
142
143   std::vector<encoder_convolutional*> d_encoders;
144   std::vector<size_t> d_interleavers;
145 };
146
147 #endif /* INCLUDED_ENCODER_TURBO_H */