Friday, October 12, 2012

Understanding a Singal Processing Block in GNU Radio : general_work()

Function : general_work()

The function general_work() implements the process of converting the input streams to output streams

Following are the arguments to this function :

virtual int general_work (
                 int                                             noutput_items,
                 gr_vector_int                            &ninput_items,
                 gr_vector_const_void_star        &input_items,
                 gr_vector_void_star                   &output_items) = 0;

The above definition can be found in gr_block.h and it is a virtual function hence can be redefined in the derived class.

Its a pure virtual function and we definitely need to override in case we are making our won signal processing block

Lets see what these different arguments do

noutput_items : number of output items to write on each output stream

ninput_items : number of input items available on each input stream

input_items : vector of pointers to the elements of the input(s) streams i.e. element i of this vector points to the ith input stream

output_items : vector of pointers to the elements of the output(s) streams i.e. element i of this vector points to ith output stream

A signal processing block can have multiple inputs and multiple outputs

ninput_items is a vector whose ith element is the number of available items on the ith input stream

However noutput_items is not a vector but scalar because GNU Radio implementation forces the number of output items to write on each output stream to be the same

Return value of the general_work() is the number of items actually written to each output stream, or -1 for EOF(end of file)

It is OK to return a value less than noutput_items.  -1 <= return value <= noutput_items

To create a signal processing block we simple define how to create output_items from input_items assuming that all the parameters are provided to us. i.e. we implement the signal processing algorithm in this method i.e. general_work()

After we have defined general_work() for our custom signal processing block, we need to invoke the consume() function

void consume (int which_input, int how_many_items);

to indicate to the scheduler how many items (how_many_items) have been processed on each input stream (which_input)

Since the scheduler is providing us all the appropriate parameters for us to write our own block , we need to feedback the scheduler so it knows which element have been used , so it can mark appropriate memory for deletion or reuse, and update pointers to point to the new data.

This feedback of our signal processing process to the scheduler is provided via the consume function

Reference :

No comments:

Post a Comment