Merged anastas/wip changes r3156:3218 into trunk.
[debian/gnuradio] / gr-trellis / src / lib / trellis_encoder_bs.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004 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 <trellis_encoder_bs.h>
28 #include <gr_io_signature.h>
29 #include <iostream>
30
31 trellis_encoder_bs_sptr 
32 trellis_make_encoder_bs (const fsm &FSM, const int ST)
33 {
34   return trellis_encoder_bs_sptr (new trellis_encoder_bs (FSM,ST));
35 }
36
37 trellis_encoder_bs::trellis_encoder_bs (const fsm &FSM, const int ST)
38   : gr_sync_block ("encoder_bs",
39                    gr_make_io_signature (1, -1, sizeof (unsigned char)),
40                    gr_make_io_signature (1, -1, sizeof (short))),
41     d_FSM (FSM),
42     d_ST (ST)
43 {
44 }
45
46
47
48 int 
49 trellis_encoder_bs::work (int noutput_items,
50                         gr_vector_const_void_star &input_items,
51                         gr_vector_void_star &output_items)
52 {
53   int d_ST_tmp;
54
55   assert (input_items.size() == output_items.size());
56   int nstreams = input_items.size();
57
58 for (int m=0;m<nstreams;m++) {
59   const unsigned char *in = (const unsigned char *) input_items[m];
60   short *out = (short *) output_items[m];
61   d_ST_tmp = d_ST;
62
63 // per stream processing
64
65   for (int i = 0; i < noutput_items; i++){
66     out[i] = (short) d_FSM.OS()[d_ST_tmp*d_FSM.I()+in[i]]; // direction of time?
67     d_ST_tmp = (int) d_FSM.NS()[d_ST_tmp*d_FSM.I()+in[i]];
68   }
69
70 // end per stream processing
71 }
72   d_ST = d_ST_tmp;
73
74   return noutput_items;
75 }
76