gri_agc2_cc.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _GRI_AGC2_CC_H_
00024 #define _GRI_AGC2_CC_H_
00025
00026 #include <math.h>
00027
00035 class gri_agc2_cc {
00036
00037 public:
00038 gri_agc2_cc (float attack_rate = 1e-1, float decay_rate = 1e-2, float reference = 1.0,
00039 float gain = 1.0, float max_gain = 0.0)
00040 : _attack_rate(attack_rate), _decay_rate(decay_rate), _reference(reference),
00041 _gain(gain), _max_gain(max_gain) {};
00042
00043 float decay_rate () const { return _decay_rate; }
00044 float attack_rate () const { return _attack_rate; }
00045 float reference () const { return _reference; }
00046 float gain () const { return _gain; }
00047 float max_gain() const { return _max_gain; }
00048
00049 void set_decay_rate (float rate) { _decay_rate = rate; }
00050 void set_attack_rate (float rate) { _attack_rate = rate; }
00051 void set_reference (float reference) { _reference = reference; }
00052 void set_gain (float gain) { _gain = gain; }
00053 void set_max_gain(float max_gain) { _max_gain = max_gain; }
00054
00055 gr_complex scale (gr_complex input){
00056 gr_complex output = input * _gain;
00057
00058 float tmp = -_reference + sqrt(output.real()*output.real() +
00059 output.imag()*output.imag());
00060 float rate = _decay_rate;
00061 if((tmp) > _gain)
00062 rate = _attack_rate;
00063 _gain -= tmp*rate;
00064
00065 #if 0
00066 fprintf(stdout, "rate = %f\ttmp = %f\t gain = %f\n", rate, tmp, _gain);
00067 #endif
00068
00069
00070
00071 if (_gain < 0.0)
00072 _gain = 10e-5;
00073
00074 if (_max_gain > 0.0 && _gain > _max_gain)
00075 _gain = _max_gain;
00076 return output;
00077 }
00078
00079 void scaleN (gr_complex output[], const gr_complex input[], unsigned n){
00080 for (unsigned i = 0; i < n; i++)
00081 output[i] = scale (input[i]);
00082 }
00083
00084 protected:
00085 float _attack_rate;
00086 float _decay_rate;
00087 float _reference;
00088 float _gain;
00089 float _max_gain;
00090 };
00091
00092 #endif