-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsp_modules.h
67 lines (53 loc) · 1.99 KB
/
dsp_modules.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
65
66
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename input, typename output = input>
class Identity : public SampleProcessor<input, output> {
public:
inline virtual ~Identity() {};
inline Identity(SampleSource<input> * in = NULL) {
connect(in);
}
virtual inline __attribute((alwaysinline)) output read() {
return SampleProcessor<input, output>::source->read();
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class UnityMix : public SampleSource<int8_t> {
public:
Identity<int8_t> input1;
Identity<int8_t> input2;
inline virtual ~UnityMix() {};
inline UnityMix(SampleSource<int8_t> * in1, SampleSource<int8_t> * in2) {
input1.connect(in1);
input2.connect(in2);
}
inline virtual int8_t read() {
uint16_t tmp;
tmp += input1.read();
tmp += input2.read();
return tmp / 2;
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename input>
class ConvertToUnsigned : public SampleProcessor<input, typename sample_type_traits<input>::unsigned_type> {
public:
inline virtual ~ConvertToUnsigned() {};
inline ConvertToUnsigned(SampleSource<input> * in) {
connect(in);
}
inline virtual uint8_t process(input v) {
return sample_type_traits<input>::to_uint8_t(v);
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename input>
class ConvertToSigned : public SampleProcessor<input, typename sample_type_traits<input>::signed_type> {
public:
inline virtual ~ConvertToSigned() {};
inline ConvertToSigned(SampleSource<input> * in) {
connect(in);
}
inline virtual int8_t process(input v) {
return sample_type_traits<input>::to_int8_t(v);
}
};