-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathAPM1.cpp
35 lines (32 loc) · 1017 Bytes
/
APM1.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
#include "APM1.hpp"
#include "Array.hpp"
#include "UpdateBroadcaster.hpp"
#include "Squash.hpp"
#include "Stretch.hpp"
APM1::APM1(const Shared* const sh, const int n, const int r) : shared(sh), index(0), n(n), t(n * 33), rate(r) {
assert(n > 0 && rate > 0 && rate < 32);
// maps p, cxt -> p initially
for( int i = 0; i < n; ++i ) {
for( int j = 0; j < 33; ++j ) {
if( i == 0 ) {
t[i * 33 + j] = squash((j - 16) * 128) * 16;
} else {
t[i * 33 + j] = t[j];
}
}
}
}
int APM1::p(int pr, const int cxt) {
shared->GetUpdateBroadcaster()->subscribe(this);
assert(pr >= 0 && pr < 4096 && cxt >= 0 && cxt < n);
pr = stretch(pr);
const int w = pr & 127; // interpolation weight (33 points)
index = ((pr + 2048) >> 7) + cxt * 33;
return (t[index] * (128 - w) + t[index + 1] * w) >> 11;
}
void APM1::update() {
INJECT_SHARED_y
const int g = (y << 16) + (y << rate) - y - y;
t[index] += (g - t[index]) >> rate;
t[index + 1] += (g - t[index + 1]) >> rate;
}