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., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <ecc_syms_to_metrics.h>
28 #include <gr_io_signature.h>
31 ecc_syms_to_metrics_sptr
32 ecc_make_syms_to_metrics (gr_feval_ff* pdf_fcn_0_bit,
33 gr_feval_ff* pdf_fcn_1_bit,
39 return ecc_syms_to_metrics_sptr
40 (new ecc_syms_to_metrics (pdf_fcn_0_bit,
49 * dummy functions and variables to get the float(*)(float) function
50 * to work properly with the gr_feval_XX stuff.
53 static gr_feval_ff* l_pdf_fcn_0_bit;
54 static gr_feval_ff* l_pdf_fcn_1_bit;
56 static float pdf_fcn_0 (float x)
58 return (l_pdf_fcn_0_bit->eval (x));
61 static float pdf_fcn_1 (float x)
63 return (l_pdf_fcn_1_bit->eval (x));
66 ecc_syms_to_metrics::ecc_syms_to_metrics
67 (gr_feval_ff* pdf_fcn_0_bit,
68 gr_feval_ff* pdf_fcn_1_bit,
73 : gr_block ("syms_to_metrics",
74 gr_make_io_signature (1, -1, sizeof (float)),
75 gr_make_io_signature (0, 0, 0))
77 // setup the dummy functions to do the conversion from the
78 // python-provided feval classes to that which is needed by the
79 // libecc's code_metrics classes.
81 l_pdf_fcn_0_bit = pdf_fcn_0_bit;
82 l_pdf_fcn_1_bit = pdf_fcn_1_bit;
84 // use the static "create" member function to create the actual
85 // code_metrics to use.
87 d_code_metrics_table = libecc_code_metrics_create_table<float>
95 // get the output item size in bytes from the new code_metrics.
97 d_out_item_size_bytes = d_code_metrics_table->out_item_size_bytes ();
99 // set the output signature to match that which the code_metrics
102 set_output_signature (gr_make_io_signature (1, -1, d_out_item_size_bytes));
105 bool ecc_syms_to_metrics::check_topology (int ninputs, int noutputs)
107 // there are 2 output streams per input stream; the first is ~to
108 // log(p(0|x)) = log-probability of a 0-bit given the input symbol
109 // 'x'; the second is ~to log(p(1|x)).
111 return ((noutputs == (2*ninputs)) ? true : false);
115 ecc_syms_to_metrics::forecast
117 gr_vector_int &ninput_items_required)
119 // always 1:1, for all streams
120 for (size_t n = 0; n < ninput_items_required.size(); n++) {
121 ninput_items_required[n] = noutput_items;
126 ecc_syms_to_metrics::general_work
128 gr_vector_int &ninput_items,
129 gr_vector_const_void_star &input_items,
130 gr_vector_void_star &output_items)
132 size_t l_n_output_items = noutput_items;
134 for (size_t n = 0; n < input_items.size(); n++) {
135 float* t_in_buf = (float*)(&input_items[n]);
136 void* t_out_buf_0_bit = (void*)(&(output_items[2*n]));
137 void* t_out_buf_1_bit = (void*)(&(output_items[(2*n)+1]));
138 d_code_metrics_table->convert (l_n_output_items, t_in_buf,
139 t_out_buf_0_bit, t_out_buf_1_bit);
142 // consume the number of used input items on all input streams
144 consume_each (noutput_items);
146 // returns number of items written to each output stream
148 return (noutput_items);