ref: c172f57d52194ec61721bde5c1bbc8514259b2c3
parent: f919dd7445be38ec8c379279cab9a70b3f5957a8
author: Jean-Marc Valin <[email protected]>
date: Wed Feb 9 08:34:03 EST 2011
Fixes buffering issues with CELT-only mode at 2.5 ms
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -211,8 +211,8 @@
}
}
- for (i=0;i<ENCODER_DELAY_COMPENSATION*st->channels;i++)
- pcm_buf[i] = st->delay_buffer[i];
+ for (i=0;i<IMIN(frame_size, ENCODER_DELAY_COMPENSATION)*st->channels;i++)
+ pcm_buf[i] = st->delay_buffer[i];
for (;i<frame_size*st->channels;i++)
pcm_buf[i] = pcm[i-ENCODER_DELAY_COMPENSATION*st->channels];
@@ -220,8 +220,18 @@
/* Encode high band with CELT */
ret = celt_encode_with_ec(st->celt_enc, pcm_buf, frame_size, NULL, nb_compr_bytes, &enc);
- for (i=0;i<ENCODER_DELAY_COMPENSATION*st->channels;i++)
- st->delay_buffer[i] = pcm[frame_size*st->channels-ENCODER_DELAY_COMPENSATION*st->channels+i];
+
+ if (frame_size>ENCODER_DELAY_COMPENSATION)
+ {
+ for (i=0;i<ENCODER_DELAY_COMPENSATION*st->channels;i++)
+ st->delay_buffer[i] = pcm[(frame_size-ENCODER_DELAY_COMPENSATION)*st->channels+i];
+ } else {
+ int tmp = ENCODER_DELAY_COMPENSATION-frame_size;
+ for (i=0;i<tmp*st->channels;i++)
+ st->delay_buffer[i] = st->delay_buffer[i+frame_size*st->channels];
+ for (i=0;i<frame_size*st->channels;i++)
+ st->delay_buffer[tmp*st->channels+i] = pcm[i];
+ }
} else {
ret = (ec_tell(&enc)+7)>>3;
ec_enc_done(&enc);