Skip to content

Commit 02621de

Browse files
author
kazuho
committed
elementsof(freq) should be 257 including total freq. at the end
use a safer method for rounding the frequency table git-svn-id: http://svn.coderepos.org/share/lang/cplusplus/range_coder@7178 d0d07461-0603-4401-acd4-de1884942a52
1 parent e311db8 commit 02621de

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

build_table.pl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,20 @@
3131
}
3232

3333
my @freq;
34-
my $acc = 0;
3534
my $cc = sum @cnt;
36-
my ($mult, $mult_diff) = (0x8000, 0);
35+
my $mult = 0x8000;
3736
while (1) {
38-
$acc = 0;
37+
print STDERR "$mult\n";
38+
my $acc = 0;
3939
for (my $i = 0; $i < 256; $i++) {
4040
push @freq, $acc;
4141
$acc += $cnt[$i] != 0 ? max(int($cnt[$i] / $cc * $mult + 0.5), 1) : 0;
4242
}
43-
last if $acc == 0x8000;
43+
last if $acc <= 0x8000;
4444
@freq = ();
45-
$mult_diff = $mult_diff != 0 ? $mult_diff / 2 : abs($acc - 0x8000);
46-
if ($acc < 0x8000) {
47-
$mult += $mult_diff;
48-
} else {
49-
$mult -= $mult_diff;
50-
}
45+
$mult--;
5146
}
47+
push @freq, 0x8000;
5248

5349
print "#define MAX_FREQ 0x8000\n";
5450
print "static short freq[] __attribute__((aligned(16))) = {", join(',', map { $_ - 0x8000 } @freq), "};\n";

0 commit comments

Comments
 (0)