Imported Upstream version 3.0
[debian/gnuradio] / gr-trellis / src / lib / trellis_metrics_c.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., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <trellis_metrics_c.h>
28 #include <gr_io_signature.h>
29 #include <assert.h>
30 #include <stdexcept>
31 #include <iostream>
32
33
34 trellis_metrics_c_sptr
35 trellis_make_metrics_c (int O, int D,  const std::vector<gr_complex> &TABLE, trellis_metric_type_t TYPE)
36 {
37   return trellis_metrics_c_sptr (new trellis_metrics_c (O,D,TABLE,TYPE));
38 }
39
40
41
42 trellis_metrics_c::trellis_metrics_c (int O, int D,  const std::vector<gr_complex> &TABLE, trellis_metric_type_t TYPE)
43   : gr_block ("metrics_c",
44               gr_make_io_signature (1, -1, sizeof (gr_complex)),
45               gr_make_io_signature (1, -1, sizeof (float))),
46     d_O (O),
47     d_D (D),
48     d_TYPE (TYPE),
49     d_TABLE (TABLE)
50 {
51   set_relative_rate (1.0 * d_O / ((double) d_D));
52   set_output_multiple ((int)d_O);
53 }
54
55
56
57
58 void
59 trellis_metrics_c::forecast (int noutput_items, gr_vector_int &ninput_items_required)
60 {
61   assert (noutput_items % d_O == 0);
62   int input_required =  d_D * noutput_items / d_O;
63   unsigned ninputs = ninput_items_required.size();
64   for (unsigned int i = 0; i < ninputs; i++)
65     ninput_items_required[i] = input_required;
66 }
67
68
69
70 int
71 trellis_metrics_c::general_work (int noutput_items,
72                                 gr_vector_int &ninput_items,
73                                 gr_vector_const_void_star &input_items,
74                                 gr_vector_void_star &output_items)
75 {
76
77   assert (noutput_items % d_O == 0);
78   assert (input_items.size() == output_items.size());
79   int nstreams = input_items.size();
80
81 for (int m=0;m<nstreams;m++) {
82   const gr_complex *in = (gr_complex *) input_items[m];
83   float *out = (float *) output_items[m];
84
85   for (int i = 0; i < noutput_items / d_O ; i++){
86 /*
87 #if 0
88     calc_metric_s(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
89 #elif 0
90     calc_metric_i(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
91 #elif 0
92     calc_metric_f(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
93 #elif 1
94     calc_metric_c(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
95 #endif
96 */
97     calc_metric(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
98   } 
99 }
100
101   consume_each (d_D * noutput_items / d_O);
102   return noutput_items;
103 }