Changeset 7178

Show
Ignore:
Timestamp:
02/27/08 04:57:51 (5 years ago)
Author:
kazuho
Message:

elementsof(freq) should be 257 including total freq. at the end
use a safer method for rounding the frequency table

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/cplusplus/range_coder/build_table.pl

    r7161 r7178  
    3232 
    3333my @freq; 
    34 my $acc = 0; 
    3534my $cc = sum @cnt; 
    36 my ($mult, $mult_diff) = (0x8000, 0); 
     35my $mult = 0x8000; 
    3736while (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} 
     47push @freq, 0x8000; 
    5248 
    5349print "#define MAX_FREQ 0x8000\n";