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 2, 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.
27 #include <gr_squelch_base_ff.h>
28 #include <gr_io_signature.h>
30 gr_squelch_base_ff::gr_squelch_base_ff(const char *name, int ramp, bool gate) :
32 gr_make_io_signature(1, 1, sizeof(float)),
33 gr_make_io_signature(1, 1, sizeof(float)))
38 d_envelope = d_ramp ? 0.0 : 1.0;
42 int gr_squelch_base_ff::general_work(int noutput_items,
43 gr_vector_int &ninput_items,
44 gr_vector_const_void_star &input_items,
45 gr_vector_void_star &output_items)
47 const float *in = (const float *) input_items[0];
48 float *out = (float *) output_items[0];
52 for (int i = 0; i < noutput_items; i++) {
55 // Adjust envelope based on current state
59 d_state = d_ramp ? ST_ATTACK : ST_UNMUTED; // If not ramping, go straight to unmuted
64 d_state = d_ramp ? ST_DECAY : ST_MUTED; // If not ramping, go straight to muted
68 d_envelope = 0.5-std::cos(M_PI*(++d_ramped)/d_ramp)/2.0; // FIXME: precalculate window for speed
69 if (d_ramped >= d_ramp) { // use >= in case d_ramp is set to lower value elsewhere
76 d_envelope = 0.5-std::cos(M_PI*(--d_ramped)/d_ramp)/2.0; // FIXME: precalculate window for speed
82 // If unmuted, copy input times envelope to output
83 // Otherwise, if not gating, copy zero to output
84 if (d_state != ST_MUTED)
85 out[j++] = in[i]*d_envelope;
91 consume_each(noutput_items); // Use all the inputs
92 return j; // But only report outputs copied