~ubuntu-branches/ubuntu/trusty/gnuradio/trusty

« back to all changes in this revision

Viewing changes to gnuradio-core/src/lib/gengen/gr_packed_to_unpacked_ii.cc

  • Committer: Bazaar Package Importer
  • Author(s): Kamal Mostafa
  • Date: 2010-03-13 07:46:01 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100313074601-zjsa893a87bozyh7
Tags: 3.2.2.dfsg-1ubuntu1
* Fix build for Ubuntu lucid (LP: #260406)
  - add binary package dep for libusrp0, libusrp2-0: adduser
  - debian/rules clean: remove pre-built Qt moc files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- c++ -*- */
 
2
/*
 
3
 * Copyright 2004 Free Software Foundation, Inc.
 
4
 * 
 
5
 * This file is part of GNU Radio
 
6
 * 
 
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)
 
10
 * any later version.
 
11
 * 
 
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.
 
16
 * 
 
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.
 
21
 */
 
22
 
 
23
// WARNING: this file is machine generated.  Edits will be over written
 
24
 
 
25
#ifdef HAVE_CONFIG_H
 
26
#include "config.h"
 
27
#endif
 
28
 
 
29
#include <gr_packed_to_unpacked_ii.h>
 
30
#include <gr_io_signature.h>
 
31
#include <assert.h>
 
32
#include <gr_log2_const.h>
 
33
 
 
34
static const unsigned int BITS_PER_TYPE = sizeof(int) * 8;
 
35
static const unsigned int LOG2_L_TYPE = gr_log2_const<sizeof(int) * 8>();
 
36
 
 
37
 
 
38
gr_packed_to_unpacked_ii_sptr 
 
39
gr_make_packed_to_unpacked_ii (unsigned int bits_per_chunk, gr_endianness_t endianness)
 
40
{
 
41
  return gr_packed_to_unpacked_ii_sptr 
 
42
    (new gr_packed_to_unpacked_ii (bits_per_chunk,endianness));
 
43
}
 
44
 
 
45
gr_packed_to_unpacked_ii::gr_packed_to_unpacked_ii (unsigned int bits_per_chunk, 
 
46
                                                    gr_endianness_t endianness)
 
47
  : gr_block ("packed_to_unpacked_ii",
 
48
              gr_make_io_signature (1, -1, sizeof (int)),
 
49
              gr_make_io_signature (1, -1, sizeof (int))),
 
50
    d_bits_per_chunk(bits_per_chunk),d_endianness(endianness),d_index(0)
 
51
{
 
52
  assert (bits_per_chunk <= BITS_PER_TYPE);
 
53
  assert (bits_per_chunk > 0);
 
54
 
 
55
  set_relative_rate ((1.0 * BITS_PER_TYPE) / bits_per_chunk);
 
56
}
 
57
 
 
58
void
 
59
gr_packed_to_unpacked_ii::forecast(int noutput_items, gr_vector_int &ninput_items_required)
 
60
{
 
61
 
 
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]);
 
67
  }
 
68
}
 
69
 
 
70
unsigned int
 
71
get_bit_le (const int *in_vector,unsigned int bit_addr)
 
72
{
 
73
  int x = in_vector[bit_addr>>LOG2_L_TYPE];
 
74
  return (x>>(bit_addr&(BITS_PER_TYPE-1)))&1;
 
75
}
 
76
 
 
77
unsigned int
 
78
get_bit_be (const int *in_vector,unsigned int bit_addr)
 
79
{
 
80
  int x = in_vector[bit_addr>>LOG2_L_TYPE];
 
81
  return (x>>((BITS_PER_TYPE-1)-(bit_addr&(BITS_PER_TYPE-1))))&1;
 
82
}
 
83
 
 
84
int
 
85
gr_packed_to_unpacked_ii::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)
 
89
{
 
90
  unsigned int index_tmp = d_index;
 
91
 
 
92
  assert (input_items.size() == output_items.size());
 
93
  int nstreams = input_items.size();
 
94
 
 
95
  for (int m=0; m < nstreams; m++){
 
96
    const int *in = (int *) input_items[m];
 
97
    int *out = (int *) output_items[m];
 
98
    index_tmp = d_index;
 
99
 
 
100
    // per stream processing
 
101
 
 
102
    switch (d_endianness){
 
103
 
 
104
    case GR_MSB_FIRST:
 
105
      for (int i = 0; i < noutput_items; i++){
 
106
        //printf("here msb %d\n",i);
 
107
        int x = 0;
 
108
        for(unsigned int j=0; j<d_bits_per_chunk; j++, index_tmp++)
 
109
          x = (x<<1) | get_bit_be(in, index_tmp);
 
110
        out[i] = x;
 
111
      }
 
112
      break;
 
113
 
 
114
    case GR_LSB_FIRST:
 
115
      for (int i = 0; i < noutput_items; i++){
 
116
        //printf("here lsb %d\n",i);
 
117
        int x = 0;
 
118
        for(unsigned int j=0; j<d_bits_per_chunk; j++, index_tmp++)
 
119
          x = (x<<1) | get_bit_le(in, index_tmp);
 
120
        out[i] = x;
 
121
      }
 
122
      break;
 
123
 
 
124
    default:
 
125
      assert(0);
 
126
    }
 
127
 
 
128
    //printf("almost got to end\n");
 
129
    assert(ninput_items[m] >= (int) ((d_index+(BITS_PER_TYPE-1))>>LOG2_L_TYPE));
 
130
  }
 
131
 
 
132
  d_index = index_tmp;
 
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;
 
137
}