ref: 2f0ca7618d8af91439921ddd99f09c9869a1cf9b
parent: b6c3f06b538413701a76087036ddb775fa7126da
author: Jean-Marc Valin <[email protected]>
date: Thu Sep 1 12:56:40 EDT 2011
Simplifying buffering to make an Opus-level highpass possible
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -467,6 +467,12 @@
ec_enc_init(&enc, data, max_data_bytes-1);
+ ALLOC(pcm_buf, (st->delay_compensation+frame_size)*st->channels, opus_val16);
+ for (i=0;i<st->delay_compensation*st->channels;i++)
+ pcm_buf[i] = st->delay_buffer[(st->encoder_buffer-st->delay_compensation)*st->channels+i];
+ for (i=0;i<frame_size*st->channels;i++)
+ pcm_buf[st->delay_compensation*st->channels + i] = pcm[i];
+
/* SILK processing */
if (st->mode != MODE_CELT_ONLY)
{
@@ -537,10 +543,10 @@
}
#ifdef FIXED_POINT
- pcm_silk = pcm;
+ pcm_silk = pcm_buf+st->delay_compensation*st->channels;
#else
for (i=0;i<frame_size*st->channels;i++)
- pcm_silk[i] = FLOAT2INT16(pcm[i]);
+ pcm_silk[i] = FLOAT2INT16(pcm_buf[st->delay_compensation*st->channels + i]);
#endif
ret = silk_Encode( silk_enc, &st->silk_mode, pcm_silk, frame_size, &enc, &nBytes, 0 );
if( ret ) {
@@ -634,12 +640,10 @@
nb_compr_bytes = 0;
}
- ALLOC(pcm_buf, IMAX(frame_size, st->Fs/200)*st->channels, opus_val16);
- for (i=0;i<IMIN(frame_size, st->delay_compensation)*st->channels;i++)
- pcm_buf[i] = st->delay_buffer[(st->encoder_buffer-st->delay_compensation)*st->channels+i];
- for (;i<frame_size*st->channels;i++)
- pcm_buf[i] = pcm[i-st->delay_compensation*st->channels];
+ for (i=0;i<st->encoder_buffer*st->channels;i++)
+ st->delay_buffer[i] = pcm_buf[(frame_size+st->delay_compensation-st->encoder_buffer)*st->channels+i];
+
if( st->mode == MODE_HYBRID && st->stream_channels == 2 ) {
/* Apply stereo width reduction (at low bitrates) */
if( st->hybrid_stereo_width_Q14 < (1 << 14) || st->silk_mode.stereoWidth_Q14 < (1 << 14) ) {
@@ -735,17 +739,6 @@
}
- if (frame_size>st->encoder_buffer)
- {
- for (i=0;i<st->encoder_buffer*st->channels;i++)
- st->delay_buffer[i] = pcm[(frame_size-st->encoder_buffer)*st->channels+i];
- } else {
- int tmp = st->encoder_buffer-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];
- }
/* Signalling the mode in the first byte */
data--;