-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDetector.h
64 lines (53 loc) · 1.12 KB
/
Detector.h
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
64
#ifndef __DETECTOR_H__
#define __DETECTOR_H__
#include "Common.h"
#include "Thread.h"
#include "Pool.h"
#include "ModuleBase.h"
#include <string>
using namespace std;
class TwoBuffer {
public:
TwoBuffer() : a(NULL), b(NULL), la(-1), lb(-1) {}
TwoBuffer(short*a, short*b, int la, int lb) :
a(a), b(b), la(la), lb(lb){}
~TwoBuffer() {
if(a) delete[] a;
if(b) delete[] b;
}
short get(int i) {
if(i < 0 || i >= la + lb) return -1;
if(i < la) return a[i];
else return b[i - la];
}
void swap_out(short* c, int lc) {
short* temp = a;
a = b;
b = c;
la = lb;
lb = lc;
if(temp) delete[] temp;
}
private:
short* a;
short* b;
int la;
int lb;
};
class Detector : public ModuleBase
{
private:
static Mutex mtx;
Pool<short*> * pool;
string id;
size_t num_items;
protected:
virtual void run();
public:
Detector(Pool<short*> * pool, string id)
: pool(pool), id(id), num_items(0) {}
void execute(size_t);
double goertzel(TwoBuffer &buf, double coef,
int x, int length);
};
#endif