Houston, we have a trunk.
[debian/gnuradio] / gr-error-correcting-codes / src / lib / libecc / code_metrics.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_CODE_METRIC_H
24 #define INCLUDED_CODE_METRIC_H
25
26 #include <sys/types.h>
27 #include <vector>
28
29 class code_metrics
30 {
31 public:
32   typedef float pdf_fcn_io_t;
33
34   code_metrics () {};
35   virtual ~code_metrics () {};
36
37 // lookup() returns either a float, or a sign-extended
38 // 'sample_precision'-bit integer value.
39
40   virtual void lookup (pdf_fcn_io_t sym,
41                        void* bit_0,
42                        void* bit_1) = 0;
43
44   virtual void convert (size_t n_syms,
45                         pdf_fcn_io_t* syms,
46                         void* bit_0,
47                         void* bit_1) = 0;
48 };
49
50 class code_metric_ff : public code_metrics
51 {
52   typedef pdf_fcn_io_t (*pdf_fcn_t) (pdf_fcn_io_t);
53   typedef float metric_t, *metric_ptr_t;
54
55 private:
56   size_t d_n_samples;
57   pdf_fcn_io_t d_max_sample, d_min_sample, d_delta;
58   pdf_fcn_t d_pdf_fcn_0_bit, d_pdf_fcn_1_bit;
59   std::vector<metric_t> d_metric_table_0_bit;
60   std::vector<metric_t> d_metric_table_1_bit;
61
62 public:
63   code_metric_ff (pdf_fcn_t pdf_fcn_0_bit,
64                   pdf_fcn_t pdf_fcn_1_bit,
65                   size_t n_samples,
66                   pdf_fcn_io_t min_sample,
67                   pdf_fcn_io_t max_sample);
68   ~code_metric_ff () {};
69
70   void lookup (pdf_fcn_io_t sym, void* bit_0, void* bit_1);
71   void convert (size_t n_syms, pdf_fcn_io_t* sym, void* bit_0, void* bit_1);
72 };
73
74 class code_metric_fl : public code_metrics
75 {
76   typedef float pdf_fcn_io_t;
77   typedef pdf_fcn_io_t (*pdf_fcn_t) (pdf_fcn_io_t);
78   typedef long metric_t, *metric_ptr_t;
79
80 private:
81   char d_sample_precision;
82   size_t d_n_samples, d_sample_mask;
83   pdf_fcn_io_t d_max_sample, d_min_sample, d_delta;
84   pdf_fcn_t d_pdf_fcn_0_bit, d_pdf_fcn_1_bit;
85   std::vector<metric_t> d_metric_table_0_bit;
86   std::vector<metric_t> d_metric_table_1_bit;
87
88 public:
89   code_metric_fl (pdf_fcn_t pdf_fcn_0_bit,
90                   pdf_fcn_t pdf_fcn_1_bit,
91                   size_t n_samples,
92                   pdf_fcn_io_t min_sample,
93                   pdf_fcn_io_t max_sample,
94                   int sample_precision = 32);
95   ~code_metric_fl () {};
96
97   void lookup (pdf_fcn_io_t sym, void* bit_0, void* bit_1);
98   void convert (size_t n_syms, pdf_fcn_io_t* sym, void* bit_0, void* bit_1);
99 };
100
101 class code_metric_fs : public code_metrics
102 {
103   typedef float pdf_fcn_io_t;
104   typedef pdf_fcn_io_t (*pdf_fcn_t) (pdf_fcn_io_t);
105   typedef short metric_t, *metric_ptr_t;
106
107 private:
108   char d_sample_precision;
109   size_t d_n_samples, d_sample_mask;
110   pdf_fcn_io_t d_max_sample, d_min_sample, d_delta;
111   pdf_fcn_t d_pdf_fcn_0_bit, d_pdf_fcn_1_bit;
112   std::vector<metric_t> d_metric_table_0_bit;
113   std::vector<metric_t> d_metric_table_1_bit;
114
115 public:
116   code_metric_fs (pdf_fcn_t pdf_fcn_0_bit,
117                   pdf_fcn_t pdf_fcn_1_bit,
118                   size_t n_samples,
119                   pdf_fcn_io_t min_sample,
120                   pdf_fcn_io_t max_sample,
121                   int sample_precision = 16);
122   ~code_metric_fs () {};
123
124   void lookup (pdf_fcn_io_t sym, void* bit_0, void* bit_1);
125   void convert (size_t n_syms, pdf_fcn_io_t* sym, void* bit_0, void* bit_1);
126 };
127
128 class code_metric_fb : public code_metrics
129 {
130   typedef float pdf_fcn_io_t;
131   typedef pdf_fcn_io_t (*pdf_fcn_t) (pdf_fcn_io_t);
132   typedef char metric_t, *metric_ptr_t;
133
134 private:
135   char d_sample_precision;
136   size_t d_n_samples, d_sample_mask;
137   pdf_fcn_io_t d_max_sample, d_min_sample, d_delta;
138   pdf_fcn_t d_pdf_fcn_0_bit, d_pdf_fcn_1_bit;
139   std::vector<metric_t> d_metric_table_0_bit;
140   std::vector<metric_t> d_metric_table_1_bit;
141
142 public:
143   code_metric_fb (pdf_fcn_t pdf_fcn_0_bit,
144                   pdf_fcn_t pdf_fcn_1_bit,
145                   size_t n_samples,
146                   pdf_fcn_io_t min_sample,
147                   pdf_fcn_io_t max_sample,
148                   int sample_precision = 8);
149   ~code_metric_fb () {};
150
151   void lookup (pdf_fcn_io_t sym, void* bit_0, void* bit_1);
152   void convert (size_t n_syms, pdf_fcn_io_t* sym, void* bit_0, void* bit_1);
153 };
154
155 #endif /* INCLUDED_CODE_METRIC_H */