[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Discuss-gnuradio] Variable rate output blocks
From: |
Eric Blossom |
Subject: |
Re: [Discuss-gnuradio] Variable rate output blocks |
Date: |
Fri, 4 Jul 2003 21:26:52 -0700 |
User-agent: |
Mutt/1.4i |
On Fri, Jul 04, 2003 at 08:33:20PM +0100, S?rgio Rui Silva wrote:
> Hi all,
>
> I want to create a block that accepts a fixed rate input and
> generates a variable rate output. For example if I have 1000
> input samples each time the work function is called, the block
> will generate a random number of output samples that can go from
> 0 to 1000. What is the correct and best way to do this with GNU
> Radio.
>
> S?rgio Rui Silva
As long as your work method calls ...
sync (output.index)
... you may return less than the number of samples requested.
You'll want to create a forecast method that indicates how much input
has been consumed. Without a custom forecast method, the input and
output rates are identical.
E.g.,
class GrMyClass : public <foo> {
...
VrSampleIndex d_next_input;
...
};
GrMyClass::GrMyClass ()
{
...
d_next_input = 0;
...
}
int
GrMyClass::forecast (VrSampleRange output,
VrSampleRange inputs[])
{
for(unsigned int i=0;i<numberInputs;i++) {
inputs[i].index=next_input;
inputs[i].size=output.size;
}
return 0; // OK
}
int
GrMyClass::work (VrSampleRange output, void *ao[],
VrSampleRange inputs[], void *ai[])
{
float *in = ((float **) ai)[0];
float *out = ((float **) ao)[0];
sync (output.index); // force in-order computation
int number_of_outputs_to_compute;
int r = some_random_function ();
int k;
number_of_outputs_to_compute = std::min (output.size, r)
for (k = 0; k < number_of_outputs_to_compute; k++){
out[k] = <the next output value>;
}
d_next_input += <number of input samples consumed>;
return k;
}
Take a look at gnuradio/src/gnu/lib/dtv/GrAtscBitTimingLoop2.{h,cc}
for a complete example.
Eric