Fixes constrained VBR

Also removes the 8 byte/packet lower bound
This commit is contained in:
Jean-Marc Valin 2011-01-12 11:27:03 -05:00
parent 4420390799
commit 6b565268fb
3 changed files with 7 additions and 8 deletions

View file

@ -1164,7 +1164,10 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
nbAvailableBytes = target+(1<<(BITRES+2))>>(BITRES+3); nbAvailableBytes = target+(1<<(BITRES+2))>>(BITRES+3);
nbAvailableBytes=IMAX(min_allowed,nbAvailableBytes); nbAvailableBytes=IMAX(min_allowed,nbAvailableBytes);
/* TODO: if we're busting, this will increase the reservoir by too much */
nbCompressedBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes);
nbAvailableBytes = nbCompressedBytes - nbFilledBytes;
target=nbAvailableBytes<<(BITRES+3); target=nbAvailableBytes<<(BITRES+3);
if (st->vbr_count < 970) if (st->vbr_count < 970)
@ -1191,7 +1194,6 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
st->vbr_reservoir = 0; st->vbr_reservoir = 0;
/*printf ("+%d\n", adjust);*/ /*printf ("+%d\n", adjust);*/
} }
nbCompressedBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes);
/* This moves the raw bits to take into account the new compressed size */ /* This moves the raw bits to take into account the new compressed size */
ec_byte_shrink(&buf, nbCompressedBytes); ec_byte_shrink(&buf, nbCompressedBytes);

View file

@ -533,9 +533,9 @@ int main(int argc, char **argv)
/*printf ("page granulepos: %d %d %d\n", skip_samples, page_nb_packets, (int)page_granule);*/ /*printf ("page granulepos: %d %d %d\n", skip_samples, page_nb_packets, (int)page_granule);*/
last_granule = page_granule; last_granule = page_granule;
/*Extract all available packets*/ /*Extract all available packets*/
while (!eos && ogg_stream_packetout(&os, &op) == 1 && op.bytes>=8) while (!eos && ogg_stream_packetout(&os, &op) == 1)
{ {
if (!memcmp(op.packet, "CELT ", 8)) { if (op.bytes>=8 && !memcmp(op.packet, "CELT ", 8)) {
celt_serialno = os.serialno; celt_serialno = os.serialno;
} }
if (celt_serialno == -1 || os.serialno != celt_serialno) if (celt_serialno == -1 || os.serialno != celt_serialno)

View file

@ -484,10 +484,7 @@ int main(int argc, char **argv)
bytes_per_packet = (bitrate*1000*frame_size/rate+4)/8; bytes_per_packet = (bitrate*1000*frame_size/rate+4)/8;
if (bytes_per_packet < 8) { if (bytes_per_packet > MAX_FRAME_BYTES) {
bytes_per_packet=8;
fprintf (stderr, "Warning: Requested bitrate (%0.3fkbit/sec) is too low. Setting CELT to 8 bytes/frame.\n",bitrate);
} else if (bytes_per_packet > MAX_FRAME_BYTES) {
bytes_per_packet=MAX_FRAME_BYTES; bytes_per_packet=MAX_FRAME_BYTES;
fprintf (stderr, "Warning: Requested bitrate (%0.3fkbit/sec) is too high. Setting CELT to %d bytes/frame.\n",bitrate,MAX_FRAME_BYTES); fprintf (stderr, "Warning: Requested bitrate (%0.3fkbit/sec) is too high. Setting CELT to %d bytes/frame.\n",bitrate,MAX_FRAME_BYTES);
} }