111 lines
2.8 KiB
C++
111 lines
2.8 KiB
C++
|
/* -*- c++ -*- */
|
||
|
/*
|
||
|
* Copyright 2019 Thomas Kolb.
|
||
|
*
|
||
|
* This is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 3, or (at your option)
|
||
|
* any later version.
|
||
|
*
|
||
|
* This software is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this software; see the file COPYING. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#ifdef HAVE_CONFIG_H
|
||
|
#include "config.h"
|
||
|
#endif
|
||
|
|
||
|
#include <gnuradio/io_signature.h>
|
||
|
#include "symbol_interleaver_impl.h"
|
||
|
|
||
|
namespace gr {
|
||
|
namespace hamnet70 {
|
||
|
|
||
|
symbol_interleaver::sptr
|
||
|
symbol_interleaver::make(size_t interleaver_width, bool deinterleave, const std::string &length_tag)
|
||
|
{
|
||
|
return gnuradio::get_initial_sptr
|
||
|
(new symbol_interleaver_impl(interleaver_width, deinterleave, length_tag));
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* The private constructor
|
||
|
*/
|
||
|
symbol_interleaver_impl::symbol_interleaver_impl(size_t interleaver_width, bool deinterleave, const std::string &length_tag)
|
||
|
: gr::tagged_stream_block("symbol_interleaver",
|
||
|
gr::io_signature::make(1, 1, sizeof(gr_complex)),
|
||
|
gr::io_signature::make(1, 1, sizeof(gr_complex)), length_tag),
|
||
|
d_width(interleaver_width),
|
||
|
d_deinterleave(deinterleave)
|
||
|
{}
|
||
|
|
||
|
/*
|
||
|
* Our virtual destructor.
|
||
|
*/
|
||
|
symbol_interleaver_impl::~symbol_interleaver_impl()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
int
|
||
|
symbol_interleaver_impl::calculate_output_stream_length(const gr_vector_int &ninput_items)
|
||
|
{
|
||
|
int noutput_items = ninput_items[0];
|
||
|
return noutput_items ;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
symbol_interleaver_impl::work (int noutput_items,
|
||
|
gr_vector_int &ninput_items,
|
||
|
gr_vector_const_void_star &input_items,
|
||
|
gr_vector_void_star &output_items)
|
||
|
{
|
||
|
const gr_complex *in = (const gr_complex *) input_items[0];
|
||
|
gr_complex *out = (gr_complex *) output_items[0];
|
||
|
|
||
|
size_t nitems = ninput_items[0];
|
||
|
|
||
|
size_t ncols = d_width;
|
||
|
size_t nfullcols = nitems % d_width;
|
||
|
|
||
|
size_t nrows = nitems / d_width;
|
||
|
if(nitems % nrows != 0) {
|
||
|
nrows++;
|
||
|
}
|
||
|
|
||
|
size_t row = 0;
|
||
|
size_t col = 0;
|
||
|
|
||
|
for(size_t i = 0; i < nitems; i++) {
|
||
|
size_t swapped_i = ncols * row + col;
|
||
|
|
||
|
row++;
|
||
|
if ((col >= nfullcols && row == (nrows-1))
|
||
|
|| row == nrows) {
|
||
|
col++;
|
||
|
row = 0;
|
||
|
}
|
||
|
|
||
|
if(d_deinterleave) {
|
||
|
out[i] = in[swapped_i];
|
||
|
} else { /* interleave */
|
||
|
out[swapped_i] = in[i];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
noutput_items = nitems;
|
||
|
|
||
|
// Tell runtime system how many output items we produced.
|
||
|
return noutput_items;
|
||
|
}
|
||
|
|
||
|
} /* namespace hamnet70 */
|
||
|
} /* namespace gr */
|
||
|
|