1 /* -*- c++ -*- */
2 /*
3 * Copyright 2004,2010,2013,2018,2019 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 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include "mute_impl.h"
29 #include <gnuradio/io_signature.h>
30 #include <string.h>
31 #include <algorithm>
32
33 namespace gr {
34 namespace blocks {
35
36 template <class T>
make(bool mute)37 typename mute_blk<T>::sptr mute_blk<T>::make(bool mute)
38 {
39 return gnuradio::get_initial_sptr(new mute_impl<T>(mute));
40 }
41
42 template <class T>
mute_impl(bool mute)43 mute_impl<T>::mute_impl(bool mute)
44 : sync_block("mute",
45 io_signature::make(1, 1, sizeof(T)),
46 io_signature::make(1, 1, sizeof(T))),
47 d_mute(mute)
48 {
49 this->message_port_register_in(pmt::intern("set_mute"));
50 this->set_msg_handler(pmt::intern("set_mute"),
51 [this](pmt::pmt_t msg) { this->set_mute_pmt(msg); });
52 }
53
54 template <class T>
~mute_impl()55 mute_impl<T>::~mute_impl()
56 {
57 }
58
59 template <class T>
work(int noutput_items,gr_vector_const_void_star & input_items,gr_vector_void_star & output_items)60 int mute_impl<T>::work(int noutput_items,
61 gr_vector_const_void_star& input_items,
62 gr_vector_void_star& output_items)
63 {
64 T* iptr = (T*)input_items[0];
65 T* optr = (T*)output_items[0];
66
67 int size = noutput_items;
68
69 if (d_mute) {
70 std::fill_n(optr, noutput_items, 0);
71 } else {
72 while (size >= 8) {
73 *optr++ = *iptr++;
74 *optr++ = *iptr++;
75 *optr++ = *iptr++;
76 *optr++ = *iptr++;
77 *optr++ = *iptr++;
78 *optr++ = *iptr++;
79 *optr++ = *iptr++;
80 *optr++ = *iptr++;
81 size -= 8;
82 }
83
84 while (size-- > 0)
85 *optr++ = *iptr++;
86 }
87
88 return noutput_items;
89 }
90
91 template class mute_blk<std::int16_t>;
92 template class mute_blk<std::int32_t>;
93 template class mute_blk<float>;
94 template class mute_blk<gr_complex>;
95 } /* namespace blocks */
96 } /* namespace gr */
97