Merge branch 'upstream' into dfsg-orig
[debian/gnuradio] / gr-howto-write-a-block / lib / howto_square2_ff.cc
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 /*
24  * config.h is generated by configure.  It contains the results
25  * of probing for features, options etc.  It should be the first
26  * file included in your .cc file.
27  */
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <howto_square2_ff.h>
33 #include <gr_io_signature.h>
34
35 /*
36  * Create a new instance of howto_square2_ff and return
37  * a boost shared_ptr.  This is effectively the public constructor.
38  */
39 howto_square2_ff_sptr 
40 howto_make_square2_ff ()
41 {
42   return howto_square2_ff_sptr (new howto_square2_ff ());
43 }
44
45 /*
46  * Specify constraints on number of input and output streams.
47  * This info is used to construct the input and output signatures
48  * (2nd & 3rd args to gr_block's constructor).  The input and
49  * output signatures are used by the runtime system to
50  * check that a valid number and type of inputs and outputs
51  * are connected to this block.  In this case, we accept
52  * only 1 input and 1 output.
53  */
54 static const int MIN_IN = 1;    // mininum number of input streams
55 static const int MAX_IN = 1;    // maximum number of input streams
56 static const int MIN_OUT = 1;   // minimum number of output streams
57 static const int MAX_OUT = 1;   // maximum number of output streams
58
59 /*
60  * The private constructor
61  */
62 howto_square2_ff::howto_square2_ff ()
63   : gr_sync_block ("square2_ff",
64                    gr_make_io_signature (MIN_IN, MAX_IN, sizeof (float)),
65                    gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (float)))
66 {
67   // nothing else required in this example
68 }
69
70 /*
71  * Our virtual destructor.
72  */
73 howto_square2_ff::~howto_square2_ff ()
74 {
75   // nothing else required in this example
76 }
77
78 int 
79 howto_square2_ff::work (int noutput_items,
80                         gr_vector_const_void_star &input_items,
81                         gr_vector_void_star &output_items)
82 {
83   const float *in = (const float *) input_items[0];
84   float *out = (float *) output_items[0];
85
86   for (int i = 0; i < noutput_items; i++){
87     out[i] = in[i] * in[i];
88   }
89
90   // Tell runtime system how many output items we produced.
91   return noutput_items;
92 }