1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/* -*- c++ -*- */
/*
* Copyright 2015 Free Software Foundation, Inc.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "dvbt_convolutional_deinterleaver_impl.h"
#include <gnuradio/io_signature.h>
namespace gr {
namespace dtv {
const int dvbt_convolutional_deinterleaver_impl::d_SYNC = 0x47;
const int dvbt_convolutional_deinterleaver_impl::d_NSYNC = 0xB8;
const int dvbt_convolutional_deinterleaver_impl::d_MUX_PKT = 8;
dvbt_convolutional_deinterleaver::sptr
dvbt_convolutional_deinterleaver::make(int nsize, int I, int M)
{
return gnuradio::make_block_sptr<dvbt_convolutional_deinterleaver_impl>(nsize, I, M);
}
/*
* The private constructor
*/
dvbt_convolutional_deinterleaver_impl::dvbt_convolutional_deinterleaver_impl(int blocks,
int I,
int M)
: block("dvbt_convolutional_deinterleaver",
io_signature::make(1, 1, sizeof(unsigned char)),
io_signature::make(1, 1, sizeof(unsigned char) * I * blocks)),
d_blocks(blocks),
d_I(I),
d_M(M)
{
set_relative_rate(1, (uint64_t)(d_I * d_blocks));
set_output_multiple(2);
// The positions are shift registers (FIFOs)
// of length i*M
d_shift.reserve(d_I);
for (int i = (d_I - 1); i >= 0; i--) {
d_shift.emplace_back(d_M * i, 0);
}
// There are 8 mux packets
assert(d_blocks / d_M == d_MUX_PKT);
}
/*
* Our virtual destructor.
*/
dvbt_convolutional_deinterleaver_impl::~dvbt_convolutional_deinterleaver_impl() {}
void dvbt_convolutional_deinterleaver_impl::forecast(int noutput_items,
gr_vector_int& ninput_items_required)
{
int ninputs = ninput_items_required.size();
for (int i = 0; i < ninputs; i++) {
ninput_items_required[i] = noutput_items * d_I * d_blocks;
}
}
int dvbt_convolutional_deinterleaver_impl::general_work(
int noutput_items,
gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items)
{
const unsigned char* in = (const unsigned char*)input_items[0];
unsigned char* out = (unsigned char*)output_items[0];
int to_out = noutput_items;
/*
* Look for a tag that signals superframe_start and consume all input items
* that are in input buffer so far.
* This will actually reset the convolutional deinterleaver
*/
std::vector<tag_t> tags;
const uint64_t nread = this->nitems_read(0); // number of items read on port 0
this->get_tags_in_range(tags,
0,
nread,
nread + (noutput_items * d_I * d_blocks),
pmt::string_to_symbol("superframe_start"));
if (!tags.empty()) {
if (tags[0].offset - nread) {
consume_each(tags[0].offset - nread);
return (0);
}
}
/*
* At this moment the first item in input buffer should be NSYNC or SYNC
*/
for (int count = 0, i = 0; i < to_out; i++) {
for (int mux_pkt = 0; mux_pkt < d_MUX_PKT; mux_pkt++) {
// This is actually the deinterleaver
for (int k = 0; k < (d_M * d_I); k++) {
d_shift[k % d_I].push_back(in[count]);
out[count++] = d_shift[k % d_I].front();
d_shift[k % d_I].pop_front();
}
}
}
// Tell runtime system how many input items we consumed on
// each input stream.
consume_each(d_I * d_blocks * to_out);
// Tell runtime system how many output items we produced.
return (to_out);
}
} /* namespace dtv */
} /* namespace gr */
|