1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012 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 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include "interleaved_short_array_to_complex.h"
28 #include "interleaved_short_to_complex_impl.h"
29 #include <gnuradio/io_signature.h>
30 
31 namespace gr {
32 namespace blocks {
33 
make(bool vector_input,bool swap)34 interleaved_short_to_complex::sptr interleaved_short_to_complex::make(bool vector_input,
35                                                                       bool swap)
36 {
37     return gnuradio::get_initial_sptr(
38         new interleaved_short_to_complex_impl(vector_input, swap));
39 }
40 
interleaved_short_to_complex_impl(bool vector_input,bool swap)41 interleaved_short_to_complex_impl::interleaved_short_to_complex_impl(bool vector_input,
42                                                                      bool swap)
43     : sync_decimator("interleaved_short_to_complex",
44                      gr::io_signature::make(1, 1, (vector_input ? 2 : 1) * sizeof(short)),
45                      gr::io_signature::make(1, 1, sizeof(gr_complex)),
46                      vector_input ? 1 : 2),
47       d_swap(swap)
48 {
49 }
50 
set_swap(bool swap)51 void interleaved_short_to_complex_impl::set_swap(bool swap) { d_swap = swap; }
52 
work(int noutput_items,gr_vector_const_void_star & input_items,gr_vector_void_star & output_items)53 int interleaved_short_to_complex_impl::work(int noutput_items,
54                                             gr_vector_const_void_star& input_items,
55                                             gr_vector_void_star& output_items)
56 {
57     const short* in = (const short*)input_items[0];
58     gr_complex* out = (gr_complex*)output_items[0];
59 
60     interleaved_short_array_to_complex(in, out, 2 * noutput_items);
61 
62     if (d_swap) {
63         float* p = (float*)output_items[0];
64         for (int i = 0; i < noutput_items; ++i) {
65             float f = p[2 * i + 1];
66             p[2 * i + 1] = p[2 * i + 0];
67             p[2 * i + 0] = f;
68         }
69     }
70 
71     return noutput_items;
72 }
73 
74 } /* namespace blocks */
75 } /* namespace gr */
76