3 * Copyright 2002,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 3, 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.
23 #ifndef _GRI_AGC2_FF_H_
24 #define _GRI_AGC2_FF_H_
29 * \brief high performance Automatic Gain Control class with attack and decay rate
31 * Power is approximated by absolute value
37 gri_agc2_ff (float attack_rate = 1e-1, float decay_rate = 1e-2, float reference = 1.0,
38 float gain = 1.0, float max_gain = 0.0)
39 : _attack_rate(attack_rate), _decay_rate(decay_rate), _reference(reference),
40 _gain(gain), _max_gain(max_gain) {};
42 float attack_rate () const { return _attack_rate; }
43 float decay_rate () const { return _decay_rate; }
44 float reference () const { return _reference; }
45 float gain () const { return _gain; }
46 float max_gain () const { return _max_gain; }
48 void set_attack_rate (float rate) { _attack_rate = rate; }
49 void set_decay_rate (float rate) { _decay_rate = rate; }
50 void set_reference (float reference) { _reference = reference; }
51 void set_gain (float gain) { _gain = gain; }
52 void set_max_gain (float max_gain) { _max_gain = max_gain; }
54 float scale (float input){
55 float output = input * _gain;
57 float tmp = (fabsf(output)) - _reference;
58 float rate = _decay_rate;
59 if(fabsf(tmp) > _gain)
64 fprintf(stdout, "rate = %f\ttmp = %f\t gain = %f\n", rate, tmp, _gain);
67 // Not sure about this
71 if (_max_gain > 0.0 && _gain > _max_gain)
76 void scaleN (float output[], const float input[], unsigned n){
77 for (unsigned i = 0; i < n; i++)
78 output[i] = scale (input[i]);
82 float _attack_rate; // attack_rate for fast changing signals
83 float _decay_rate; // decay rate for slow changing signals
84 float _reference; // reference value
85 float _gain; // current gain
86 float _max_gain; // maximum gain
89 #endif /* _GRI_AGC2_FF_H_ */