Skip to content

Commit 3996827

Browse files
committed
Merge remote-tracking branch 'tom/set_max_noutput_items'
2 parents 7f07703 + c422e26 commit 3996827

File tree

4 files changed

+115
-9
lines changed

4 files changed

+115
-9
lines changed

gnuradio-runtime/lib/flat_flowgraph.cc

+7
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ namespace gr {
177177
catch(std::bad_alloc&) {
178178
b = make_buffer(nitems, item_size, grblock);
179179
}
180+
181+
// Set the max noutput items size here to make sure it's always
182+
// set in the block and available in the start() method.
183+
// But don't overwrite if the user has set this externally.
184+
if(!grblock->is_set_max_noutput_items())
185+
grblock->set_max_noutput_items(nitems);
186+
180187
return b;
181188
}
182189

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2016 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+
from gnuradio import gr, gr_unittest, blocks
24+
25+
class test_block_behavior(gr_unittest.TestCase):
26+
27+
def setUp(self):
28+
self.tb = gr.top_block()
29+
30+
def tearDown(self):
31+
self.tb = None
32+
33+
def test_000(self):
34+
'''
35+
Tests the max noutput sizes set by the scheduler. When creating
36+
the block, there is no block_detail and so the max buffer size
37+
is 0. When the top_block is run, it builds the detail and
38+
buffers and sets the max value. test_0001 tests when the
39+
max_noutput_items is set by hand.
40+
41+
'''
42+
43+
src = blocks.null_source(gr.sizeof_float)
44+
op = blocks.head(gr.sizeof_float, 100)
45+
snk = blocks.null_sink(gr.sizeof_float)
46+
47+
maxn_pre = op.max_noutput_items()
48+
49+
self.tb.connect(src, op, snk)
50+
self.tb.run()
51+
52+
maxn_post = op.max_noutput_items()
53+
54+
self.assertEqual(maxn_pre, 0)
55+
self.assertEqual(maxn_post, 16384)
56+
57+
def test_001(self):
58+
'''
59+
Tests the max noutput size when being explicitly set.
60+
'''
61+
62+
src = blocks.null_source(gr.sizeof_float)
63+
op = blocks.head(gr.sizeof_float, 100)
64+
snk = blocks.null_sink(gr.sizeof_float)
65+
66+
op.set_max_noutput_items(1024)
67+
68+
maxn_pre = op.max_noutput_items()
69+
70+
self.tb.connect(src, op, snk)
71+
self.tb.run()
72+
73+
maxn_post = op.max_noutput_items()
74+
75+
self.assertEqual(maxn_pre, 1024)
76+
self.assertEqual(maxn_post, 1024)
77+
78+
if __name__ == '__main__':
79+
gr_unittest.run(test_block_behavior, "test_block_behavior.xml")

gr-filter/lib/pfb_decimator_ccf_impl.cc

+24-8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ namespace gr {
7373
else {
7474
set_history(d_taps_per_filter);
7575
}
76+
77+
d_tmp = NULL;
78+
}
79+
80+
bool pfb_decimator_ccf_impl::start()
81+
{
82+
if(d_use_fft_filters) {
83+
d_tmp = fft::malloc_complex(max_noutput_items()*d_rate);
84+
}
85+
86+
return block::start();
87+
}
88+
89+
bool pfb_decimator_ccf_impl::stop()
90+
{
91+
if((d_use_fft_filters) && (d_tmp)) {
92+
fft::free(d_tmp);
93+
}
94+
95+
return block::stop();
7696
}
7797

7898
pfb_decimator_ccf_impl::~pfb_decimator_ccf_impl()
@@ -198,14 +218,13 @@ namespace gr {
198218
gr_complex *out = (gr_complex *)output_items[0];
199219

200220
int i;
201-
gr_complex *tmp = fft::malloc_complex(noutput_items*d_rate);
202221

203222
// Filter each input stream by the FFT filters; do all
204223
// noutput_items at once to avoid repeated calls to the FFT
205224
// setup and operation.
206225
for(unsigned int j = 0; j < d_rate; j++) {
207226
in = (gr_complex*)input_items[d_rate-j-1];
208-
d_fft_filters[j]->filter(noutput_items, in, &(tmp[j*noutput_items]));
227+
d_fft_filters[j]->filter(noutput_items, in, &(d_tmp[j*noutput_items]));
209228
}
210229

211230
// Rotate and add filter outputs (k=channel number; M=number of
@@ -214,11 +233,10 @@ namespace gr {
214233
for(i = 0; i < noutput_items; i++) {
215234
out[i] = 0;
216235
for(unsigned int j = 0; j < d_rate; j++) {
217-
out[i] += tmp[j*noutput_items+i]*d_rotator[j];
236+
out[i] += d_tmp[j*noutput_items+i]*d_rotator[j];
218237
}
219238
}
220239

221-
fft::free(tmp);
222240
return noutput_items;
223241
}
224242

@@ -231,18 +249,17 @@ namespace gr {
231249
gr_complex *out = (gr_complex *)output_items[0];
232250

233251
int i;
234-
gr_complex *tmp = fft::malloc_complex(noutput_items*d_rate);
235252

236253
for(unsigned int j = 0; j < d_rate; j++) {
237254
in = (gr_complex*)input_items[d_rate-j-1];
238-
d_fft_filters[j]->filter(noutput_items, in, &tmp[j*noutput_items]);
255+
d_fft_filters[j]->filter(noutput_items, in, &d_tmp[j*noutput_items]);
239256
}
240257

241258
// Performs the rotate and add operations by implementing it as
242259
// an FFT.
243260
for(i = 0; i < noutput_items; i++) {
244261
for(unsigned int j = 0; j < d_rate; j++) {
245-
d_fft->get_inbuf()[j] = tmp[j*noutput_items + i];
262+
d_fft->get_inbuf()[j] = d_tmp[j*noutput_items + i];
246263
}
247264

248265
// Perform the FFT to do the complex multiply despinning for all channels
@@ -252,7 +269,6 @@ namespace gr {
252269
out[i] = d_fft->get_outbuf()[d_chan];
253270
}
254271

255-
fft::free(tmp);
256272
return noutput_items;
257273
}
258274

gr-filter/lib/pfb_decimator_ccf_impl.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace gr {
4040
bool d_use_fft_rotator;
4141
bool d_use_fft_filters;
4242
gr_complex *d_rotator;
43+
gr_complex *d_tmp; // used for fft filters
4344
gr::thread::mutex d_mutex; // mutex to protect set/work access
4445

4546
inline int work_fir_exp(int noutput_items,
@@ -55,7 +56,6 @@ namespace gr {
5556
gr_vector_const_void_star &input_items,
5657
gr_vector_void_star &output_items);
5758

58-
5959
public:
6060
pfb_decimator_ccf_impl(unsigned int decim,
6161
const std::vector<float> &taps,
@@ -70,6 +70,10 @@ namespace gr {
7070
std::vector<std::vector<float> > taps() const;
7171
void set_channel(const unsigned int channel);
7272

73+
// Overload to create/destroy d_tmp based on max_noutput_items.
74+
bool start();
75+
bool stop();
76+
7377
int work(int noutput_items,
7478
gr_vector_const_void_star &input_items,
7579
gr_vector_void_star &output_items);

0 commit comments

Comments
 (0)