1 /* -*- c++ -*- */
2 /*
3 * Copyright 2012 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 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "interleave_impl.h"
28 #include <gnuradio/io_signature.h>
29
30 namespace gr {
31 namespace blocks {
32
make(size_t itemsize,unsigned int blocksize)33 interleave::sptr interleave::make(size_t itemsize, unsigned int blocksize)
34 {
35 return gnuradio::get_initial_sptr(new interleave_impl(itemsize, blocksize));
36 }
37
interleave_impl(size_t itemsize,unsigned int blocksize)38 interleave_impl::interleave_impl(size_t itemsize, unsigned int blocksize)
39 : block("interleave",
40 io_signature::make(1, io_signature::IO_INFINITE, itemsize),
41 io_signature::make(1, 1, itemsize)),
42 d_itemsize(itemsize),
43 d_blocksize(blocksize)
44 {
45 set_fixed_rate(true);
46 set_output_multiple(d_blocksize);
47 }
48
check_topology(int ninputs,int noutputs)49 bool interleave_impl::check_topology(int ninputs, int noutputs)
50 {
51 set_relative_rate((uint64_t)ninputs, 1);
52 d_ninputs = ninputs;
53 set_output_multiple(d_blocksize * d_ninputs);
54 return true;
55 }
56
57
fixed_rate_ninput_to_noutput(int ninput)58 int interleave_impl::fixed_rate_ninput_to_noutput(int ninput)
59 {
60 return ninput * d_ninputs;
61 }
62
fixed_rate_noutput_to_ninput(int noutput)63 int interleave_impl::fixed_rate_noutput_to_ninput(int noutput)
64 {
65 return (noutput / d_ninputs);
66 }
67
forecast(int noutput_items,gr_vector_int & ninput_items_required)68 void interleave_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required)
69 {
70 for (unsigned int i = 0; i < ninput_items_required.size(); ++i) {
71 ninput_items_required[i] = noutput_items / ninput_items_required.size();
72 }
73 }
74
general_work(int noutput_items,gr_vector_int & ninput_items,gr_vector_const_void_star & input_items,gr_vector_void_star & output_items)75 int interleave_impl::general_work(int noutput_items,
76 gr_vector_int& ninput_items,
77 gr_vector_const_void_star& input_items,
78 gr_vector_void_star& output_items)
79 {
80 size_t noutput_blocks = (size_t)(noutput_items / d_blocksize);
81 const char** in = (const char**)&input_items[0];
82 char* out = (char*)output_items[0];
83
84 for (unsigned int i = 0; i < noutput_blocks; i += d_ninputs) {
85 for (unsigned int n = 0; n < d_ninputs; n++) {
86 memcpy(out, in[n], d_itemsize * d_blocksize);
87 out += d_itemsize * d_blocksize;
88 in[n] += d_itemsize * d_blocksize;
89 }
90 }
91 consume_each(noutput_items / d_ninputs);
92 return noutput_items;
93 }
94
95
96 } /* namespace blocks */
97 } /* namespace gr */
98