summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Müller <mmueller@gnuradio.org>2021-06-20 18:54:36 +0200
committermormj <34754695+mormj@users.noreply.github.com>2021-07-19 07:21:16 -0400
commitdd97527daadea86f7175c4c019dbeb96c2f47219 (patch)
treeb4753f2438c15fd75cb9dd3775cb9e6a10b96cb3
parent59af4f80dc9a1406ea7b4fde3b8d547a22c951ed (diff)
blocks: Throttle consume-only mode
When throttling a sample flow, it's not necessary to produce items at the desired average rate - consuming them at a limited rate suffices to slow down the processing of the whole flow graph just as well, and avoids a copy. Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
-rw-r--r--gr-blocks/include/gnuradio/blocks/throttle.h8
-rw-r--r--gr-blocks/lib/throttle_impl.cc10
-rw-r--r--gr-blocks/python/blocks/bindings/throttle_python.cc2
3 files changed, 16 insertions, 4 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/throttle.h b/gr-blocks/include/gnuradio/blocks/throttle.h
index 9372a8711b..b8a5151e17 100644
--- a/gr-blocks/include/gnuradio/blocks/throttle.h
+++ b/gr-blocks/include/gnuradio/blocks/throttle.h
@@ -1,6 +1,7 @@
/* -*- c++ -*- */
/*
* Copyright 2005-2011,2013 Free Software Foundation, Inc.
+ * Copyright 2021 Marcus Müller
*
* This file is part of GNU Radio
*
@@ -30,6 +31,13 @@ namespace blocks {
* precisely controlling the rate of samples. That should be
* controlled by a source or sink tied to sample clock. E.g., a
* USRP or audio card.
+ *
+ * You can insert this block "in series" with your sample flow, in which case it does a
+ * throttled copy of input to output. Alternatively, you can not connect its output and
+ * just connect this block's input in parallel to an existing block in your flow graph. In
+ * that case, Throttle will limit the rate at which samples are consumed; especially at
+ * higher rates, where the copying overhead might be significant, this is functionally not
+ * different to copying at a limited rate.
*/
class BLOCKS_API throttle : virtual public sync_block
{
diff --git a/gr-blocks/lib/throttle_impl.cc b/gr-blocks/lib/throttle_impl.cc
index 199ddea588..201d7ce86f 100644
--- a/gr-blocks/lib/throttle_impl.cc
+++ b/gr-blocks/lib/throttle_impl.cc
@@ -32,7 +32,7 @@ throttle::sptr throttle::make(size_t itemsize, double samples_per_sec, bool igno
throttle_impl::throttle_impl(size_t itemsize, double samples_per_second, bool ignore_tags)
: sync_block("throttle",
io_signature::make(1, 1, itemsize),
- io_signature::make(1, 1, itemsize)),
+ io_signature::make(0, 1, itemsize)),
d_itemsize(itemsize),
d_ignore_tags(ignore_tags)
{
@@ -78,8 +78,12 @@ int throttle_impl::work(int noutput_items,
// copy all samples output[i] <= input[i]
const char* in = (const char*)input_items[0];
- char* out = (char*)output_items[0];
- std::memcpy(out, in, noutput_items * d_itemsize);
+
+ // iff we have a connected output, then copy
+ if (!output_items.empty()) {
+ char* out = reinterpret_cast<char*>(output_items[0]);
+ std::memcpy(out, in, noutput_items * d_itemsize);
+ }
d_total_samples += noutput_items;
auto now = std::chrono::steady_clock::now();
diff --git a/gr-blocks/python/blocks/bindings/throttle_python.cc b/gr-blocks/python/blocks/bindings/throttle_python.cc
index 88bf0ca443..3a67c3fc95 100644
--- a/gr-blocks/python/blocks/bindings/throttle_python.cc
+++ b/gr-blocks/python/blocks/bindings/throttle_python.cc
@@ -14,7 +14,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(throttle.h) */
-/* BINDTOOL_HEADER_FILE_HASH(e32468fa73eff1abd796a3fbf4dbb8e0) */
+/* BINDTOOL_HEADER_FILE_HASH(c3a597508d581cabdc653faaa323232c) */
/***********************************************************************************/
#include <pybind11/complex.h>