3
* Copyright 2004,2006 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_unpacked_to_packed_ss.h>
30
#include <gr_io_signature.h>
33
static const unsigned int BITS_PER_TYPE = sizeof(short) * 8;
36
gr_unpacked_to_packed_ss_sptr
37
gr_make_unpacked_to_packed_ss (unsigned int bits_per_chunk, gr_endianness_t endianness)
39
return gr_unpacked_to_packed_ss_sptr
40
(new gr_unpacked_to_packed_ss (bits_per_chunk,endianness));
43
gr_unpacked_to_packed_ss::gr_unpacked_to_packed_ss (unsigned int bits_per_chunk,
44
gr_endianness_t endianness)
45
: gr_block ("unpacked_to_packed_ss",
46
gr_make_io_signature (1, -1, sizeof (short)),
47
gr_make_io_signature (1, -1, sizeof (short))),
48
d_bits_per_chunk(bits_per_chunk),d_endianness(endianness),d_index(0)
50
assert (bits_per_chunk <= BITS_PER_TYPE);
51
assert (bits_per_chunk > 0);
53
set_relative_rate (bits_per_chunk/(1.0 * BITS_PER_TYPE));
57
gr_unpacked_to_packed_ss::forecast(int noutput_items, gr_vector_int &ninput_items_required)
59
int input_required = (int) ceil( (d_index+noutput_items * 1.0 * BITS_PER_TYPE)/d_bits_per_chunk);
60
unsigned ninputs = ninput_items_required.size();
61
for (unsigned int i = 0; i < ninputs; i++) {
62
ninput_items_required[i] = input_required;
67
get_bit_be1 (const short *in_vector,unsigned int bit_addr, unsigned int bits_per_chunk) {
68
unsigned int byte_addr = (int)bit_addr/bits_per_chunk;
69
short x = in_vector[byte_addr];
70
unsigned int residue = bit_addr - byte_addr * bits_per_chunk;
71
//printf("Bit addr %d byte addr %d residue %d val %d\n",bit_addr,byte_addr,residue,(x>>(bits_per_chunk-1-residue))&1);
72
return (x >> (bits_per_chunk-1-residue))&1;
76
gr_unpacked_to_packed_ss::general_work (int noutput_items,
77
gr_vector_int &ninput_items,
78
gr_vector_const_void_star &input_items,
79
gr_vector_void_star &output_items)
81
unsigned int index_tmp = d_index;
83
assert (input_items.size() == output_items.size());
84
int nstreams = input_items.size();
86
for (int m=0; m< nstreams; m++) {
87
const short *in = (short *) input_items[m];
88
short *out = (short *) output_items[m];
91
// per stream processing
93
//assert((ninput_items[m]-d_index)*d_bits_per_chunk >= noutput_items*BITS_PER_TYPE);
98
for(int i=0;i<noutput_items;i++) {
100
for(unsigned int j=0; j<BITS_PER_TYPE; j++) {
101
tmp = (tmp<<1) | get_bit_be1(in,index_tmp,d_bits_per_chunk);
109
for(int i=0;i<noutput_items;i++) {
111
for(unsigned int j=0; j<BITS_PER_TYPE; j++) {
112
tmp = (tmp>>1)| (get_bit_be1(in,index_tmp,d_bits_per_chunk)<<(BITS_PER_TYPE-1));
125
consume_each ((int)(d_index/d_bits_per_chunk));
126
d_index = d_index%d_bits_per_chunk;
128
return noutput_items;