/* -*- c++ -*- */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "integer_source_impl.h" namespace gr { namespace activecat { integer_source::sptr integer_source::make(const std::vector &data, bool repeat, int times) { return gnuradio::get_initial_sptr (new integer_source_impl(data, repeat, times)); } // constructor integer_source_impl::integer_source_impl(const std::vector &data, bool repeat, int times) : gr::sync_block("integer_source", gr::io_signature::make(0, 0, 0), gr::io_signature::make( 1, 1, sizeof(int) )), d_data( data ), d_repeat( repeat ), d_times( times ), d_counter1( 0 ), d_counter2( 0 ) { } // destructor integer_source_impl::~integer_source_impl() { } // d_counter1: counts the number of round the &data array has repeated. // d_counter2: counts the n-th element of the &data array int integer_source_impl::work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { int *out = (int *) output_items[0]; if ( d_counter1 >= d_times ) // has repeated over the &data array so many times, enough. return -1; const unsigned int datasize = d_data.size(); unsigned int output_counter = 0; for (int i=0; i < noutput_items; i++) { if ( d_counter1 < d_times ) { out[i] = d_data[ d_counter2 ]; output_counter++; d_counter2++; if ( d_counter2 >= datasize ) // d_counter2 is a number between 0 and datasize; inclusive of 0, exclusive of datasize. { d_counter2 = 0; d_counter1++; } } else { return output_counter; // has repeated over the &data array so many times, enough. } if ( d_repeat && d_counter1 >= d_times ) d_counter1 = 0; } return noutput_items; } } /* namespace activecat */ } /* namespace gr */