# C++ block that generate extra data

**URL:** <https://www.ruby-forum.com/t/c-block-that-generate-extra-data/212318>\
**Category:** GNU Radio\
**Created:** [September 29, 2011, 4:15pm UTC](https://www.ruby-forum.com/t/c-block-that-generate-extra-data/212318 "2011-09-29T16:15:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [September 29, 2011, 4:15pm UTC](https://www.ruby-forum.com/t/c-block-that-generate-extra-data/212318/1 "2011-09-29T16:15:07Z")

</div>

Hello,  
i have a block that takes 3 bytes of data in and output 4bytes of data  
(3:4).  
It’s possible to generate, sometimes, extra output?  
I mean, sometimes it take 3 bytes and output 5 bytes. It’s possible? How  
i tell to the scheduler?  
Thank you

---

<div class="post-metadata">

**Author:** ![Mattia\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e68b1a/32.png) [@Mattia\_R](https://www.ruby-forum.com/u/Mattia_R)\
**Post date:** [September 29, 2011, 4:21pm UTC](https://www.ruby-forum.com/t/c-block-that-generate-extra-data/212318/2 "2011-09-29T16:21:56Z")

</div>

On Thu, Sep 29, 2011 at 04:14:04PM +0200, Mattia R. wrote:

> Hello,
> 
> i have a block that takes 3 bytes of data in and output 4bytes of data (3:4).
> 
> It’s possible to generate, sometimes, extra output?
> 
> I mean, sometimes it take 3 bytes and output 5 bytes. It’s possible? How i tell  
> to the scheduler?

That’s possible if you create a gr\_block and use the general\_work()  
function (so don’t derive from a sync\_interpolator).  
The general\_work() function lets you manually set how many bytes were  
consumed and how many were written to the output buffer. But you _must_  
check the output buffer’s large enough.

However, you sacrifice some performance and possibly some functionality  
of GNU Radio (e.g., IIRC, I don’t think you could propagate stream tags  
automatically through this kind of block).

Perhaps re-thinking your signal flow is more optimal.

## MB

Karlsruhe Institute of Technology (KIT)  
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin B.  
Research Associate

Kaiserstraße 12  
Building 05.01  
76131 Karlsruhe

Phone: +49 721 608-43790  
Fax: +49 721 608-46071  
www.cel.kit.edu

KIT – University of the State of Baden-Württemberg and  
National Laboratory of the Helmholtz Association

---

<div class="post-metadata">

**Author:** ![Mattia\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e68b1a/32.png) [@Mattia\_R](https://www.ruby-forum.com/u/Mattia_R)\
**Post date:** [September 29, 2011, 6:05pm UTC](https://www.ruby-forum.com/t/c-block-that-generate-extra-data/212318/3 "2011-09-29T18:05:42Z")

</div>

Thank you for the reply.  
How can i reallocate the output buffer if is too small?  
Let’s assume that my block has an input itemsize of 3 byte and an output  
itemsize of 4 byte. Forecast with 1:1.  
If the scheduler keeps to give to my block only 4 bytes for output, how  
can  
i force to give me more?  
Thanks

-----Messaggio originale-----  
From: Martin B.  
Sent: Thursday, September 29, 2011 4:20 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Discuss-gnuradio] C++ block that generate extra data

* * *

Discuss-gnuradio mailing list  
removed\_email\_address@domain.invalid  
[https://lists.gnu.org/mailman/listinfo/discuss-gnuradio](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

---

<div class="post-metadata">

**Author:** ![Mattia\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e68b1a/32.png) [@Mattia\_R](https://www.ruby-forum.com/u/Mattia_R)\
**Post date:** [September 29, 2011, 6:57pm UTC](https://www.ruby-forum.com/t/c-block-that-generate-extra-data/212318/4 "2011-09-29T18:57:03Z")

</div>

I think you should tell it in the constructor.  
like this:

#define NR\_OF\_WORDS\_ADDITIONALLY\_NEEDED 4

my\_usrp\_rx\_tx::my\_usrp\_rx\_tx(void) : gr\_block(“my\_usrp\_rx\_tx”,  
gr\_make\_io\_signature(1, 1, sizeof(short)),  
gr\_make\_io\_signature(1, 1, sizeof(short)))  
{  
set\_output\_multiple(NR\_OF\_WORDS\_ADDITIONALLY\_NEEDED);  
}

Then in general work function, for example, you can increment “manually”  
4  
words before your out buffer will say “bang”.

Patrik

----- Original Message -----  
From: “Mattia R.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: “gnu radio” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Thursday, September 29, 2011 19:04  
Subject: Re: [Discuss-gnuradio] C++ block that generate extra data
