[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Discuss-gnuradio] How to check if more input is available on an inp
From: |
Eric Blossom |
Subject: |
Re: [Discuss-gnuradio] How to check if more input is available on an input stream |
Date: |
Wed, 7 Jan 2009 13:38:28 -0800 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
On Wed, Jan 07, 2009 at 02:38:34PM -0600, Mir Ali wrote:
> Hi Eric,
>
> I actually forgot to mention one more thing.
>
> I use N items of first stream and one item on second stream to produce N
> items on output stream.
> I am actually spreading data. If the spreading code is N-character bytes
> long, then each bit of data input byte (i.e. a total of 8 bits on input byte
> on second stream) will produce 8*N output items.
>
> The input to the spreading stream is uninterrupted from a sequence generator
> block. But the input to the data stream i.e. the second input stream can be
> from a file which will exhaust when file is read completely. So i want to
> check if any data is available on the second stream(i.e. the data stream) in
> the work function each time i am done with the previous data byte.
>
> I hope i make myself clear. Sorry for the confusion earlier.
>
> Thanks
> Ali
OK, no problem. Try this:
static const int N = 8;
my_new_block::my_new_block() : ...
{
...
set_output_multiple(N);
...
}
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;
}
void f(float *out, const float *a, const float *b)
{
// write out[0] through out[N-1] using using inputs a[0] through a[N-1] and
b[0]
...
}
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];
assert(noutput_items % N == 0);
for (int i = 0; i < noutput_items; i += N){
f(&out[i], &in0[i], &in1[i/N]);
}
consume(0, noutput_items);
consume(1, noutput_items / N);
return noutput_items;
}
Note that there's no need to "check for input". That's what forecast
does for you. general_work won't be called until everything is OK.
You will have enough input to compute noutput_items.
Eric