3 * Copyright 2005,2007,2010 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
26 #include <gr_skiphead.h>
27 #include <gr_io_signature.h>
30 gr_skiphead::gr_skiphead (size_t itemsize, size_t nitems_to_skip)
31 : gr_block ("skiphead",
32 gr_make_io_signature(1, 1, itemsize),
33 gr_make_io_signature(1, 1, itemsize)),
34 d_nitems_to_skip(nitems_to_skip), d_nitems(0)
39 gr_make_skiphead (size_t itemsize, size_t nitems_to_skip)
41 return gnuradio::get_initial_sptr(new gr_skiphead (itemsize, nitems_to_skip));
45 gr_skiphead::general_work(int noutput_items,
46 gr_vector_int &ninput_items_ignored,
47 gr_vector_const_void_star &input_items,
48 gr_vector_void_star &output_items)
50 const char *in = (const char *) input_items[0];
51 char *out = (char *) output_items[0];
53 int ninput_items = noutput_items; // we've got at least this many input items
54 int ii = 0; // input index
56 while (ii < ninput_items){
58 long long ni_total = ii + d_nitems; // total items processed so far
59 if (ni_total < d_nitems_to_skip){ // need to skip some more
61 int n_to_skip = (int) std::min(d_nitems_to_skip - ni_total,
62 (long long)(ninput_items - ii));
66 else { // nothing left to skip. copy away
68 int n_to_copy = ninput_items - ii;
70 size_t itemsize = output_signature()->sizeof_stream_item(0);
71 memcpy(out, in + (ii*itemsize), n_to_copy*itemsize);
74 d_nitems += ninput_items;
75 consume_each(ninput_items);
80 d_nitems += ninput_items;
81 consume_each(ninput_items);