Hi Caruiz, you don't even tell us what goes wrong, so it might be hard to answer your question ;)
Anyway, that's not how GNU Radio really works. For the sample streams, real time just happens to pass by and has no meaning. So the concept "generates samples sometimes" doesn't exist in GNU Radio -- it just may take longer. There are various factors that determine when your block's general_work is called. You were right to have the forecast with the nitems_required[0] = 0; so why did you comment that out? I guess it was because your block started to run free and basically never consumed on input stream 1; and that's exactly the problem here: GNU Radio will always try to call your blocks as often as possible, i.e. whenever there is space free to put output into and when there is enough input. Assuming the noise source is fast, and your signal source takes relatively long times, especially when your CPU is busy generating noise and passing it through your block, then you will always never consume signal samples. Even with throttle between the noise source and your block (beware: NEVER use throttle -- UNLESS you really just need to reduce the *average* sample rate of a stream), there is absolutely no reliable correlation between the duration of no-signal samples and real time passing with signal present. Just an example: Assume your source produces 100 samples with a sample rate (that only you know about and GNU Radio doesn't even care about) of 1kS/s, and the next work call of the source takes 0.9s, to produce 100 samples again: s - - - - - - - - - s - - - - - - - - - s - - - - - - - - - ... [REAL TIME axis] There will never ever be 100 samples signal + noise, 900 samples noise only etc... but s+n[100] n[121200] s+n[100] n[80000] s+n[100] .... Because the noise source will produce as fast as possible, and that means it's only bound by CPU time available and the speed of samples going through your flow graph. Please note: real world sampling rate is a concept utterly meaningless in GNU Radio and is only occasionally used to calculate relative frequencies. Greetings, Marcus On 25.06.2014 11:15, caruiz.ext wrote: > Hello, > > I'm doing a block with two inputs (signal and noise) and one output. > > Signal input block generates samples sometimes. For example: > 2,3,-,-,4,-,-,-,5,1,1,-,4,55... > Noise block generates samples always. For example: 1,1,0,2,2,1,2,3,4,2... > > I want to create a block that adds noise to the signal and generate > samples always: > > Signal 2,3,-,-,4,-,-,-,5,1,1,-,4,55... > Noise 1,1,0,2,2,1,2,3,4,2,3,4,1,12... > > Output 3,4,0,2,6,1,2,3,9,3,4,4,5,67... > > > > I have written this code, what is the fail? > > Thank you ;) > > > > > > #ifdef HAVE_CONFIG_H > #include "config.h" > #endif > > #include <gnuradio/io_signature.h> > #include "add_noise_fff_impl.h" > > namespace gr { > namespace howto { > > add_noise_fff::sptr > add_noise_fff::make() > { > return gnuradio::get_initial_sptr > (new add_noise_fff_impl()); > } > > /* > * The private constructor > */ > add_noise_fff_impl::add_noise_fff_impl() > : gr::block("add_noise_fff", > gr::io_signature::make(2,2, sizeof(float)), > gr::io_signature::make(1,1, sizeof(float))) > {} > > /* > * Our virtual destructor. > */ > add_noise_fff_impl::~add_noise_fff_impl() > { > } > > void > add_noise_fff_impl::forecast (int noutput_items, gr_vector_int > &ninput_items_required) > { > ninput_items_required[1] = noutput_items; > //ninput_items_required[0] = 0; > } > > int > add_noise_fff_impl::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 *in = (const float *) input_items[0]; > const float *in_noise = (const float *) input_items[1]; > > float *out = (float *) output_items[0]; > > > int j=0; > int i=0; > for(;i<noutput_items;++i){ > if(i<ninput_items[0]){ > ++j; > out[i]=in[i]+in_noise[i]; > } > else > out[i]=in_noise[i]; > } > > //consume the inputs > this->consume(0, j); //consume port 0 input > this->consume(1, i); //consume port 1 input > > > // Tell runtime system how many output items we produced. > return noutput_items; > } > > } /* namespace howto */ > } /* namespace gr */ > > > > > *********************************************************************************************** > > > > > > #ifndef INCLUDED_HOWTO_ADD_NOISE_FFF_IMPL_H > #define INCLUDED_HOWTO_ADD_NOISE_FFF_IMPL_H > > #include <howto/add_noise_fff.h> > > namespace gr { > namespace howto { > > class add_noise_fff_impl : public add_noise_fff > { > private: > // Nothing to declare in this block. > > public: > add_noise_fff_impl(); > ~add_noise_fff_impl(); > > // Where all the action really happens > void forecast (int noutput_items, gr_vector_int > &ninput_items_required); > > int general_work(int noutput_items, > gr_vector_int &ninput_items, > gr_vector_const_void_star &input_items, > gr_vector_void_star &output_items); > }; > > } // namespace howto > } // namespace gr > > #endif /* INCLUDED_HOWTO_ADD_NOISE_FFF_IMPL_H */ > > > > _______________________________________________ > Discuss-gnuradio mailing list > Discuss-gnuradio@gnu.org > https://lists.gnu.org/mailman/listinfo/discuss-gnuradio _______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio