-
Notifications
You must be signed in to change notification settings - Fork 4
/
sample_phasor.h
66 lines (54 loc) · 1.24 KB
/
sample_phasor.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
#pragma once
#include "phasor.h"
template <typename T>
class Sample : public Phasor
{
public:
Sample() {}
~Sample() {}
void Init(T *start, float sr, size_t len)
{
mem_start_ = start;
Phasor::Init(sr, len);
}
// danger = it should be the same length as the original sample otherwise the phasor won't work
void SetSample(T *start)
{
mem_start_ = start;
}
float Process(bool *eot)
{
size_t idx0, idx1;
T s0, s1;
float sf, sample;
if (play_) {
idx0 = (size_t)cur_pos_;
if (reverse_) {
idx1 = (idx0 == start_pos_) ? end_pos_ : idx0 - 1;
} else {
idx1 = (idx0 == end_pos_) ? start_pos_ : idx0 + 1;
}
sf = cur_pos_ - idx0;
s0 = mem_start_[idx0];
s1 = mem_start_[idx1];
switch(sizeof(T))
{
case 2:
sample = s162f(T(s0 + sf * (s1 - s0)));
break;
case 4:
sample = s0 + sf * (s1 - s0);
break;
default:
// TODO: deal with other sample formats
break;
}
} else {
sample = 0.0f;
}
Phasor::Process(eot);
return sample;
}
private:
T *mem_start_;
};