3 * Copyright 2004 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.
23 // WARNING: this file is machine generated. Edits will be over written
29 #include <gr_packed_to_unpacked_bb.h>
30 #include <gr_io_signature.h>
32 #include <gr_log2_const.h>
34 static const unsigned int BITS_PER_TYPE = sizeof(unsigned char) * 8;
35 static const unsigned int LOG2_L_TYPE = gr_log2_const<sizeof(unsigned char) * 8>();
38 gr_packed_to_unpacked_bb_sptr
39 gr_make_packed_to_unpacked_bb (unsigned int bits_per_chunk, gr_endianness_t endianness)
41 return gr_packed_to_unpacked_bb_sptr
42 (new gr_packed_to_unpacked_bb (bits_per_chunk,endianness));
45 gr_packed_to_unpacked_bb::gr_packed_to_unpacked_bb (unsigned int bits_per_chunk,
46 gr_endianness_t endianness)
47 : gr_block ("packed_to_unpacked_bb",
48 gr_make_io_signature (1, -1, sizeof (unsigned char)),
49 gr_make_io_signature (1, -1, sizeof (unsigned char))),
50 d_bits_per_chunk(bits_per_chunk),d_endianness(endianness),d_index(0)
52 assert (bits_per_chunk <= BITS_PER_TYPE);
53 assert (bits_per_chunk > 0);
55 set_relative_rate ((1.0 * BITS_PER_TYPE) / bits_per_chunk);
59 gr_packed_to_unpacked_bb::forecast(int noutput_items, gr_vector_int &ninput_items_required)
62 int input_required = (int) ceil((d_index + noutput_items * d_bits_per_chunk) / (1.0 * BITS_PER_TYPE));
63 unsigned ninputs = ninput_items_required.size();
64 for (unsigned int i = 0; i < ninputs; i++) {
65 ninput_items_required[i] = input_required;
66 //printf("Forecast wants %d needs %d\n",noutput_items,ninput_items_required[i]);
71 get_bit_le (const unsigned char *in_vector,unsigned int bit_addr)
73 unsigned char x = in_vector[bit_addr>>LOG2_L_TYPE];
74 return (x>>(bit_addr&(BITS_PER_TYPE-1)))&1;
78 get_bit_be (const unsigned char *in_vector,unsigned int bit_addr)
80 unsigned char x = in_vector[bit_addr>>LOG2_L_TYPE];
81 return (x>>((BITS_PER_TYPE-1)-(bit_addr&(BITS_PER_TYPE-1))))&1;
85 gr_packed_to_unpacked_bb::general_work (int noutput_items,
86 gr_vector_int &ninput_items,
87 gr_vector_const_void_star &input_items,
88 gr_vector_void_star &output_items)
90 unsigned int index_tmp = d_index;
92 assert (input_items.size() == output_items.size());
93 int nstreams = input_items.size();
95 for (int m=0; m < nstreams; m++){
96 const unsigned char *in = (unsigned char *) input_items[m];
97 unsigned char *out = (unsigned char *) output_items[m];
100 // per stream processing
102 switch (d_endianness){
105 for (int i = 0; i < noutput_items; i++){
106 //printf("here msb %d\n",i);
108 for(unsigned int j=0; j<d_bits_per_chunk; j++, index_tmp++)
109 x = (x<<1) | get_bit_be(in, index_tmp);
115 for (int i = 0; i < noutput_items; i++){
116 //printf("here lsb %d\n",i);
118 for(unsigned int j=0; j<d_bits_per_chunk; j++, index_tmp++)
119 x = (x<<1) | get_bit_le(in, index_tmp);
128 //printf("almost got to end\n");
129 assert(ninput_items[m] >= (int) ((d_index+(BITS_PER_TYPE-1))>>LOG2_L_TYPE));
133 consume_each (d_index >> LOG2_L_TYPE);
134 d_index = d_index & (BITS_PER_TYPE-1);
135 //printf("got to end\n");
136 return noutput_items;