-
Notifications
You must be signed in to change notification settings - Fork 8
/
highpass.cpp
63 lines (51 loc) · 1.2 KB
/
highpass.cpp
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
62
63
#include "highpass.h"
#include<qfont.h>
#include<stdio.h>
Highpass::Highpass() : QComboBox() {
dcValue = 0;
setMinimumWidth ( fontMetrics().horizontalAdvance("1000Hz_") );
addItem(tr("off"),-1);
addItem(tr("-DC"),0);
addItem(tr("0.1Hz"),1);
addItem(tr("0.2Hz"),2);
addItem(tr("0.5Hz"),5);
addItem(tr("1Hz"),10);
addItem(tr("2Hz"), 20);
addItem(tr("5Hz"), 50);
addItem(tr("10Hz"),100);
connect(this,
SIGNAL( activated(int) ),
this,
SLOT( setFrequencyIndex(int) ) );
setCurrentIndex(0);
}
void Highpass::setFrequencyIndex ( int index ) {
frequency = itemData(index).toFloat()/10.0;
if (frequency > 0) {
hp.setup(samplingrate,
(float)frequency);
//_RPT1(0, "Highpass cutoff: %f Hz\n", frequency);
}
}
void Highpass::setFrequency(float f) {
int index = findData(((int)(f * 10)));
if (index != -1) {
setCurrentIndex(index);
setFrequencyIndex(index);
}
}
float Highpass::filter(float v) {
if (dcCtr > 0) {
dcValue = dcValue + (v - dcValue) / INERTIA_FOR_DC_DETECTION;
dcCtr--;
}
if (frequency == 0) {
v = v - dcValue;
return v;
}
dcCtr = samplingrate;
if (frequency > 0) {
return hp.filter(v);
}
return v;
}