Use a smarter per-band bitrate cap.

The previous "dumb cap" of (64<<LM)*(C<<BITRES) was not actually
 achievable by many (most) bands, and did not take the cost of
 coding theta for splits into account, and so was too small for some
 bands.
This patch adds code to compute a fairly accurate estimate of the
 real maximum per-band rate (an estimate only because of rounding
 effects and the fact that the bit usage for theta is variable),
 which is then truncated and stored in an 8-bit table in the mode.

This gives improved quality at all rates over 160 kbps/channel,
 prevents bits from being wasted all the way up to 255 kbps/channel
 (the maximum rate allowed, and approximately the maximum number of
 bits that can usefully be used regardless of the allocation), and
 prevents dynalloc and trim from producing enormous waste
 (eliminating the need for encoder logic to prevent this).
This commit is contained in:
Timothy B. Terriberry 2011-01-29 12:57:18 -08:00 committed by Jean-Marc Valin
parent 9b34bd835c
commit c564307463
6 changed files with 150 additions and 17 deletions

View file

@ -129,6 +129,11 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
for (j=0;j<mode->cache.size;j++)
fprintf (file, "%d, ", mode->cache.bits[j]);
fprintf (file, "};\n");
fprintf (file, "static const unsigned char cache_caps%d[%d] = {\n", mode->Fs/mdctSize, (mode->maxLM+1)*2*mode->nbEBands);
for (j=0;j<(mode->maxLM+1)*2*mode->nbEBands;j++)
fprintf (file, "%d, ", mode->cache.caps[j]);
fprintf (file, "};\n");
fprintf(file, "#endif\n");
fprintf(file, "\n");
@ -226,8 +231,8 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
fprintf(file, "%d,\t/* nbShortMdcts */\n", mode->nbShortMdcts);
fprintf(file, "%d,\t/* shortMdctSize */\n", mode->shortMdctSize);
fprintf(file, "logN%d,\t/* logN */\n", framerate);
fprintf(file, "{%d, cache_index%d, cache_bits%d},\t/* cache */\n",
mode->cache.size, mode->Fs/mdctSize, mode->Fs/mdctSize);
fprintf(file, "{%d, cache_index%d, cache_bits%d, cache_caps%d},\t/* cache */\n",
mode->cache.size, mode->Fs/mdctSize, mode->Fs/mdctSize, mode->Fs/mdctSize);
fprintf(file, "};\n");
}
fprintf(file, "\n");