-
Notifications
You must be signed in to change notification settings - Fork 36
/
SmallStationaryContextMap.cpp
41 lines (36 loc) · 1.17 KB
/
SmallStationaryContextMap.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
#include "SmallStationaryContextMap.hpp"
SmallStationaryContextMap::SmallStationaryContextMap(const Shared* const sh, const int bitsOfContext, const int inputBits, const int rate, const int scale) :
shared(sh),
data((UINT64_C(1) << bitsOfContext) * ((UINT64_C(1) << inputBits) - 1)),
mask((1U << bitsOfContext) - 1),
stride((1U << inputBits) - 1),
bTotal(inputBits), rate(rate), scale(scale) {
assert(inputBits > 0 && inputBits <= 8);
reset();
set(0);
}
void SmallStationaryContextMap::set(uint32_t ctx) {
context = (ctx & mask) * stride;
bCount = b = 0;
}
void SmallStationaryContextMap::reset() {
for( uint32_t i = 0; i < data.size(); ++i ) {
data[i] = 0x7FFF;
}
cp = &data[0];
}
void SmallStationaryContextMap::update() {
INJECT_SHARED_y
*cp += ((y << 16) - (*cp) + (1 << (rate - 1))) >> rate;
b += static_cast<uint32_t>((y != 0) && b > 0);
}
void SmallStationaryContextMap::mix(Mixer &m) {
shared->GetUpdateBroadcaster()->subscribe(this);
cp = &data[context + b];
const int prediction = (*cp) >> 4;
m.add((stretch(prediction) * scale) >> 8);
m.add(((prediction - 2048) * scale) >> 9);
bCount++;
b += b + 1;
assert(bCount <= bTotal);
}