1 /* -*- c++ -*- */
2 /*
3 * Copyright 2004,2010,2012,2018 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 3, 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
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include "sccc_decoder_blk_impl.h"
29 #include <gnuradio/io_signature.h>
30 #include <gnuradio/trellis/core_algorithms.h>
31 #include <iostream>
32
33 namespace gr {
34 namespace trellis {
35
36 template <class T>
37 typename sccc_decoder_blk<T>::sptr
make(const fsm & FSMo,int STo0,int SToK,const fsm & FSMi,int STi0,int STiK,const interleaver & INTERLEAVER,int blocklength,int repetitions,siso_type_t SISO_TYPE)38 sccc_decoder_blk<T>::make(const fsm& FSMo,
39 int STo0,
40 int SToK,
41 const fsm& FSMi,
42 int STi0,
43 int STiK,
44 const interleaver& INTERLEAVER,
45 int blocklength,
46 int repetitions,
47 siso_type_t SISO_TYPE)
48 {
49 return gnuradio::get_initial_sptr(new sccc_decoder_blk_impl<T>(FSMo,
50 STo0,
51 SToK,
52 FSMi,
53 STi0,
54 STiK,
55 INTERLEAVER,
56 blocklength,
57 repetitions,
58 SISO_TYPE));
59 }
60
61 template <class T>
sccc_decoder_blk_impl(const fsm & FSMo,int STo0,int SToK,const fsm & FSMi,int STi0,int STiK,const interleaver & INTERLEAVER,int blocklength,int repetitions,siso_type_t SISO_TYPE)62 sccc_decoder_blk_impl<T>::sccc_decoder_blk_impl(const fsm& FSMo,
63 int STo0,
64 int SToK,
65 const fsm& FSMi,
66 int STi0,
67 int STiK,
68 const interleaver& INTERLEAVER,
69 int blocklength,
70 int repetitions,
71 siso_type_t SISO_TYPE)
72 : block("sccc_decoder_blk",
73 io_signature::make(1, 1, sizeof(float)),
74 io_signature::make(1, 1, sizeof(T))),
75 d_FSMo(FSMo),
76 d_STo0(STo0),
77 d_SToK(SToK),
78 d_FSMi(FSMi),
79 d_STi0(STi0),
80 d_STiK(STiK),
81 d_INTERLEAVER(INTERLEAVER),
82 d_blocklength(blocklength),
83 d_repetitions(repetitions),
84 d_SISO_TYPE(SISO_TYPE)
85 {
86 this->set_relative_rate(1, (uint64_t)d_FSMi.O());
87 this->set_output_multiple(d_blocklength);
88 }
89
90 template <class T>
~sccc_decoder_blk_impl()91 sccc_decoder_blk_impl<T>::~sccc_decoder_blk_impl()
92 {
93 }
94
95 template <class T>
forecast(int noutput_items,gr_vector_int & ninput_items_required)96 void sccc_decoder_blk_impl<T>::forecast(int noutput_items,
97 gr_vector_int& ninput_items_required)
98 {
99 int input_required = d_FSMi.O() * noutput_items;
100 ninput_items_required[0] = input_required;
101 }
102
103 //===========================================================
104
105 template <class T>
general_work(int noutput_items,gr_vector_int & ninput_items,gr_vector_const_void_star & input_items,gr_vector_void_star & output_items)106 int sccc_decoder_blk_impl<T>::general_work(int noutput_items,
107 gr_vector_int& ninput_items,
108 gr_vector_const_void_star& input_items,
109 gr_vector_void_star& output_items)
110 {
111 int nblocks = noutput_items / d_blocklength;
112 float (*p2min)(float, float) = NULL;
113
114 if (d_SISO_TYPE == TRELLIS_MIN_SUM)
115 p2min = &min;
116 else if (d_SISO_TYPE == TRELLIS_SUM_PRODUCT)
117 p2min = &min_star;
118
119 const float* in = (const float*)input_items[0];
120 T* out = (T*)output_items[0];
121
122 for (int n = 0; n < nblocks; n++) {
123 sccc_decoder(d_FSMo,
124 d_STo0,
125 d_SToK,
126 d_FSMi,
127 d_STi0,
128 d_STiK,
129 d_INTERLEAVER,
130 d_blocklength,
131 d_repetitions,
132 p2min,
133 &(in[n * d_blocklength * d_FSMi.O()]),
134 &(out[n * d_blocklength]));
135 }
136
137 this->consume_each(d_FSMi.O() * noutput_items);
138 return noutput_items;
139 }
140
141 template class sccc_decoder_blk<std::uint8_t>;
142 template class sccc_decoder_blk<std::int16_t>;
143 template class sccc_decoder_blk<std::int32_t>;
144 } /* namespace trellis */
145 } /* namespace gr */
146