summaryrefslogtreecommitdiff
path: root/gnuradio-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r--gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc1
-rw-r--r--gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc1
-rw-r--r--gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc1
-rw-r--r--gnuradio-core/src/lib/general/CMakeLists.txt1
-rw-r--r--gnuradio-core/src/lib/general/general.i2
-rw-r--r--gnuradio-core/src/lib/general/gr_vector_map.cc117
-rw-r--r--gnuradio-core/src/lib/general/gr_vector_map.h83
-rw-r--r--gnuradio-core/src/lib/general/gr_vector_map.i28
-rw-r--r--gnuradio-core/src/python/build_utils.py4
-rw-r--r--gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py105
10 files changed, 341 insertions, 2 deletions
diff --git a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc
index cb7c93962..a8cb849e2 100644
--- a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc
+++ b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc
@@ -96,6 +96,7 @@ gr_pfb_channelizer_ccf::gr_pfb_channelizer_ccf (unsigned int numchans,
gr_pfb_channelizer_ccf::~gr_pfb_channelizer_ccf ()
{
+ delete d_fft;
delete [] d_idxlut;
for(unsigned int i = 0; i < d_numchans; i++) {
diff --git a/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc
index c973daf82..e563daa51 100644
--- a/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc
+++ b/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc
@@ -69,6 +69,7 @@ gr_pfb_decimator_ccf::gr_pfb_decimator_ccf (unsigned int decim,
gr_pfb_decimator_ccf::~gr_pfb_decimator_ccf ()
{
+ delete d_fft;
for(unsigned int i = 0; i < d_rate; i++) {
delete d_filters[i];
}
diff --git a/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc
index 9910a1851..cd01aaff5 100644
--- a/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc
+++ b/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc
@@ -74,6 +74,7 @@ gr_pfb_synthesizer_ccf::gr_pfb_synthesizer_ccf
gr_pfb_synthesizer_ccf::~gr_pfb_synthesizer_ccf ()
{
+ delete d_fft;
for(unsigned int i = 0; i < d_twox*d_numchans; i++) {
delete d_filters[i];
}
diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt
index 207d85c4c..0ad55e38a 100644
--- a/gnuradio-core/src/lib/general/CMakeLists.txt
+++ b/gnuradio-core/src/lib/general/CMakeLists.txt
@@ -281,6 +281,7 @@ set(gr_core_general_triple_threats
gr_transcendental
gr_uchar_to_float
gr_vco_f
+ gr_vector_map
gr_vector_to_stream
gr_vector_to_streams
gr_unpack_k_bits_bb
diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i
index cd8c279c9..54d9a8670 100644
--- a/gnuradio-core/src/lib/general/general.i
+++ b/gnuradio-core/src/lib/general/general.i
@@ -137,6 +137,7 @@
#include <gr_cpm.h>
#include <gr_correlate_access_code_tag_bb.h>
#include <gr_add_ff.h>
+#include <gr_vector_map.h>
%}
%include "gri_control_loop.i"
@@ -254,3 +255,4 @@
%include "gr_cpm.i"
%include "gr_correlate_access_code_tag_bb.i"
%include "gr_add_ff.i"
+%include "gr_vector_map.i"
diff --git a/gnuradio-core/src/lib/general/gr_vector_map.cc b/gnuradio-core/src/lib/general/gr_vector_map.cc
new file mode 100644
index 000000000..4cf2ed118
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_vector_map.cc
@@ -0,0 +1,117 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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.
+ *
+ * GNU Radio 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 GNU Radio; 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 <gr_vector_map.h>
+#include <gr_io_signature.h>
+#include <string.h>
+
+std::vector<int>
+get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens)
+{
+ std::vector<int> in_sizeofs;
+ for(unsigned int i; i < in_vlens.size(); i++) {
+ in_sizeofs.push_back(in_vlens[i]*item_size);
+ }
+ return in_sizeofs;
+}
+
+std::vector<int>
+get_out_sizeofs(size_t item_size,
+ std::vector< std::vector< std::vector<size_t> > > mapping)
+{
+ std::vector<int> out_sizeofs;
+ for(unsigned int i; i < mapping.size(); i++) {
+ out_sizeofs.push_back(mapping[i].size()*item_size);
+ }
+ return out_sizeofs;
+}
+
+gr_vector_map_sptr
+gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens,
+ std::vector< std::vector< std::vector<size_t> > > mapping)
+{
+ return gnuradio::get_initial_sptr(new gr_vector_map(item_size,
+ in_vlens,
+ mapping));
+}
+
+gr_vector_map::gr_vector_map(size_t item_size, std::vector<size_t> in_vlens,
+ std::vector< std::vector< std::vector<size_t> > > mapping)
+ : gr_sync_block("vector_map",
+ gr_make_io_signaturev(in_vlens.size(), in_vlens.size(),
+ get_in_sizeofs(item_size, in_vlens)),
+ gr_make_io_signaturev(mapping.size(), mapping.size(),
+ get_out_sizeofs(item_size, mapping))),
+ d_item_size(item_size), d_in_vlens(in_vlens)
+{
+ set_mapping(mapping);
+}
+
+void
+gr_vector_map::set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping) {
+ // Make sure the contents of the mapping vectors are possible.
+ for(unsigned int i=0; i<mapping.size(); i++) {
+ for(unsigned int j=0; j<mapping[i].size(); j++) {
+ if(mapping[i][j].size() != 2) {
+ throw std::runtime_error("Mapping must be of the form (out_mapping_stream1, out_mapping_stream2, ...), where out_mapping_stream1 is of the form (mapping_element1, mapping_element2, ...), where mapping_element1 is of the form (input_stream, input_element). This error is raised because a mapping_element vector does not contain exactly 2 items.");
+ }
+ unsigned int s = mapping[i][j][0];
+ unsigned int index = mapping[i][j][1];
+ if(s >= d_in_vlens.size()) {
+ throw std::runtime_error("Stream numbers in mapping must be less than the number of input streams.");
+ }
+ if((index < 0) || (index >= d_in_vlens[s])) {
+ throw std::runtime_error ("Indices in mapping must be greater than 0 and less than the input vector lengths.");
+ }
+ }
+ }
+ gruel::scoped_lock guard(d_mutex);
+ d_mapping = mapping;
+}
+
+int
+gr_vector_map::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ const char **inv = (const char **) &input_items[0];
+ char **outv = (char **) &output_items[0];
+
+ for(unsigned int n = 0; n < (unsigned int)(noutput_items); n++) {
+ for(unsigned int i = 0; i < d_mapping.size(); i++) {
+ unsigned int out_vlen = d_mapping[i].size();
+ for(unsigned int j = 0; j < out_vlen; j++) {
+ unsigned int s = d_mapping[i][j][0];
+ unsigned int k = d_mapping[i][j][1];
+ memcpy(outv[i] + out_vlen*d_item_size*n +
+ d_item_size*j, inv[s] + d_in_vlens[s]*d_item_size*n +
+ k*d_item_size, d_item_size);
+ }
+ }
+ }
+
+ return noutput_items;
+}
diff --git a/gnuradio-core/src/lib/general/gr_vector_map.h b/gnuradio-core/src/lib/general/gr_vector_map.h
new file mode 100644
index 000000000..f5492b1e3
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_vector_map.h
@@ -0,0 +1,83 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_VECTOR_MAP_H
+#define INCLUDED_GR_VECTOR_MAP_H
+
+#include <vector>
+#include <gr_core_api.h>
+#include <gr_sync_interpolator.h>
+#include <gruel/thread.h>
+
+class gr_vector_map;
+typedef boost::shared_ptr<gr_vector_map> gr_vector_map_sptr;
+
+GR_CORE_API gr_vector_map_sptr
+gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens,
+ std::vector< std::vector< std::vector<size_t> > > mapping);
+
+/*!
+ * \brief Maps elements from a set of input vectors to a set of output vectors.
+ *
+ * If in[i] is the input vector in the i'th stream then the output
+ * vector in the j'th stream is:
+ *
+ * out[j][k] = in[mapping[j][k][0]][mapping[j][k][1]]
+ *
+ * That is mapping is of the form (out_stream1_mapping,
+ * out_stream2_mapping, ...) and out_stream1_mapping is of the form
+ * (element1_mapping, element2_mapping, ...) and element1_mapping is
+ * of the form (in_stream, in_element).
+ *
+ * \param item_size (integer) size of vector elements
+ *
+ * \param in_vlens (vector of integers) number of elements in each
+ * input vector
+ *
+ * \param mapping (vector of vectors of vectors of integers) how to
+ * map elements from input to output vectors
+ *
+ * \ingroup slicedice_blk
+ */
+class GR_CORE_API gr_vector_map : public gr_sync_block
+{
+ friend GR_CORE_API gr_vector_map_sptr
+ gr_make_vector_map(size_t item_size, std::vector<size_t> in_vlens,
+ std::vector< std::vector< std::vector<size_t> > > mapping);
+ size_t d_item_size;
+ std::vector<size_t> d_in_vlens;
+ std::vector< std::vector< std::vector<size_t> > > d_mapping;
+ gruel::mutex d_mutex; // mutex to protect set/work access
+
+ protected:
+ gr_vector_map(size_t item_size, std::vector<size_t> in_vlens,
+ std::vector< std::vector< std::vector<size_t> > > mapping);
+
+ public:
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping);
+};
+
+#endif /* INCLUDED_GR_VECTOR_MAP_H */
diff --git a/gnuradio-core/src/lib/general/gr_vector_map.i b/gnuradio-core/src/lib/general/gr_vector_map.i
new file mode 100644
index 000000000..e9fa3f27e
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_vector_map.i
@@ -0,0 +1,28 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr, vector_map);
+
+%template() std::vector<size_t>;
+%template() std::vector< std::vector< std::vector<size_t> > >;
+
+%include "gr_vector_map.h"
diff --git a/gnuradio-core/src/python/build_utils.py b/gnuradio-core/src/python/build_utils.py
index 0660941d5..ce0757912 100644
--- a/gnuradio-core/src/python/build_utils.py
+++ b/gnuradio-core/src/python/build_utils.py
@@ -176,11 +176,11 @@ def is_complex (code3):
return '0'
-def standard_dict (name, code3):
+def standard_dict (name, code3, package='gr'):
d = {}
d['NAME'] = name
d['GUARD_NAME'] = 'INCLUDED_%s_H' % name.upper ()
- d['BASE_NAME'] = re.sub ('^gr_', '', name)
+ d['BASE_NAME'] = re.sub ('^' + package + '_', '', name)
d['SPTR_NAME'] = '%s_sptr' % name
d['WARNING'] = 'WARNING: this file is machine generated. Edits will be over written'
d['COPYRIGHT'] = copyright
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py b/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py
new file mode 100644
index 000000000..12f4be589
--- /dev/null
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+#
+# Copyright 2012 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio 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.
+#
+# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+from gnuradio import gr, gr_unittest
+import math
+
+class test_vector_map(gr_unittest.TestCase):
+
+ def setUp (self):
+ self.tb = gr.top_block()
+
+ def tearDown (self):
+ self.tb = None
+
+ def test_reversing(self):
+ # Chunk data in blocks of N and reverse the block contents.
+ N = 5
+ src_data = range(0, 20)
+ expected_result = []
+ for i in range(N-1, len(src_data), N):
+ for j in range(0, N):
+ expected_result.append(1.0*(i-j))
+ mapping = [list(reversed([(0, i) for i in range(0, N)]))]
+ src = gr.vector_source_f(src_data, False, N)
+ vmap = gr.vector_map(gr.sizeof_float, (N, ), mapping)
+ dst = gr.vector_sink_f(N)
+ self.tb.connect(src, vmap, dst)
+ self.tb.run()
+ result_data = list(dst.data())
+ self.assertEqual(expected_result, result_data)
+
+ def test_vector_to_streams(self):
+ # Split an input vector into N streams.
+ N = 5
+ M = 20
+ src_data = range(0, M)
+ expected_results = []
+ for n in range(0, N):
+ expected_results.append(range(n, M, N))
+ mapping = [[(0, n)] for n in range(0, N)]
+ src = gr.vector_source_f(src_data, False, N)
+ vmap = gr.vector_map(gr.sizeof_float, (N, ), mapping)
+ dsts = [gr.vector_sink_f(1) for n in range(0, N)]
+ self.tb.connect(src, vmap)
+ for n in range(0, N):
+ self.tb.connect((vmap, n), dsts[n])
+ self.tb.run()
+ for n in range(0, N):
+ result_data = list(dsts[n].data())
+ self.assertEqual(expected_results[n], result_data)
+
+ def test_interleaving(self):
+ # Takes 3 streams (a, b and c)
+ # Outputs 2 streams.
+ # First (d) is interleaving of a and b.
+ # Second (e) is interleaving of a and b and c. c is taken in
+ # chunks of 2 which are reversed.
+ A = (1, 2, 3, 4, 5)
+ B = (11, 12, 13, 14, 15)
+ C = (99, 98, 97, 96, 95, 94, 93, 92, 91, 90)
+ expected_D = (1, 11, 2, 12, 3, 13, 4, 14, 5, 15)
+ expected_E = (1, 11, 98, 99, 2, 12, 96, 97, 3, 13, 94, 95,
+ 4, 14, 92, 93, 5, 15, 90, 91)
+ mapping = [[(0, 0), (1, 0)], # mapping to produce D
+ [(0, 0), (1, 0), (2, 1), (2, 0)], # mapping to produce E
+ ]
+ srcA = gr.vector_source_f(A, False, 1)
+ srcB = gr.vector_source_f(B, False, 1)
+ srcC = gr.vector_source_f(C, False, 2)
+ vmap = gr.vector_map(gr.sizeof_int, (1, 1, 2), mapping)
+ dstD = gr.vector_sink_f(2)
+ dstE = gr.vector_sink_f(4)
+ self.tb.connect(srcA, (vmap, 0))
+ self.tb.connect(srcB, (vmap, 1))
+ self.tb.connect(srcC, (vmap, 2))
+ self.tb.connect((vmap, 0), dstD)
+ self.tb.connect((vmap, 1), dstE)
+ self.tb.run()
+ self.assertEqual(expected_D, dstD.data())
+ self.assertEqual(expected_E, dstE.data())
+
+
+
+if __name__ == '__main__':
+ gr_unittest.run(test_vector_map, "test_vector_map.xml")
+