|
From: | Mir Ali |
Subject: | Re: [Discuss-gnuradio] How to check if more input is available on an input stream |
Date: | Wed, 7 Jan 2009 14:38:34 -0600 |
You should be deriving your class from gr_block (you may already be doing this).On Wed, Jan 07, 2009 at 04:44:39AM -0600, Mir Ali wrote:
> Hi,
> I have a simple question. I have a block that has 2 input streams and the
> inputs are consumed at different rates. For each 1 input consumed on the
> first input stream N inputs are consumed in the second stream.
>
> The forecast function and set_multiple call of this block are as shown
> below,
>
> my_new_block::forecast(int noutput_items,gr_vector_int
> &ninput_items_required){
> assert(noutput_items % N==0); # the
>
>
> int items_on_first_input_stream = noutput_items;
> int items_on_second_input_stream = noutput_items/(8*N);
> ninput_items_required[0]=items_on_first_input_stream;
> ninput_items_required[1]=items_on_data_input_stream;
> }
>
>
> {
> set_output_multiple(8*N); # the output items are a multiple of 8*N.
> }
> For each (8*N) inputs consumed on second stream 1 input is consumed on first
> stream.
> If the first stream has uninterrupted supply but the second one doesn't then
> how should I check if input is available on the second stream. Will the
> input_vector contain NULL values when nothing is in it? If it is true should
> i just do
>
> if(second_stream[next_item]==null){
> .......
> }
>
> Please clarify.
>
> Thanks
> Ali
There is no need to call set_output_multiple.
If I understand you correctly, to produce a single output item, you
need a single item on the first input stream, and N (== 8) items on the
second stream.
Assuming I'm understanding you correctly, then your forecast routine
should be:
static const int N = 8;
void
my_new_block::forecast(int noutput_items, gr_vector_int &ninput_items_required)ninput_items_required[0] = noutput_items;
{
ninput_items_required[1] = noutput_items * N;
}
You then need to override general_work, not work:
(I'm assuming that your input and output types are float. Change as required)
float f(const float *a, const float *b)
{
// Produce a single float value by using a[0] and b[0] through b[N-1]...
return XXX;
}
int
my_new_block::general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const float *in0 = (const float *)input_items[0];
const float *in1 = (const float *)input_items[1];
float *out = (float *)output_items[0];
for (int i = 0; i < noutput_items; i++){
out[i] = f(&in0[i], &in1[i * N]);
}
consume(0, noutput_items);
consume(1, noutput_items * N);
return noutput_items;
}
Eric
[Prev in Thread] | Current Thread | [Next in Thread] |