-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutogain.hpp
More file actions
61 lines (48 loc) · 1020 Bytes
/
Autogain.hpp
File metadata and controls
61 lines (48 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Autogain.hpp
// OpenGLTutorial
//
// Created by Robby Tong on 2/4/19.
// Copyright © 2019 Robby Tong. All rights reserved.
//
#ifndef Autogain_hpp
#define Autogain_hpp
#include <stdio.h>
#include <math.h>
class Autogain
{
private:
double last_x;
double last_y;
double ALPHA = 0.99;
double MAX_GAIN = 1.0E2;
public:
double mGain;
Autogain()
{
last_x = 0.0;
last_y = 0.0;
mGain = 1.0;
}
float work(float x)
{
double xsq = x * x;
/* short-time signal variance */
double ysq = last_x * (1 - ALPHA) + last_y * ALPHA;
last_y = ysq;
last_x = xsq;
double y = sqrt(ysq);
double gain;
if(y >= (1.0 / MAX_GAIN))
{
gain = 1.0 / y;
}
else
{
gain = MAX_GAIN;
}
mGain = gain;
return (float) (x * gain/2.0f);
}
};
#endif /* Autogain_hpp */