shithub: opus

Download patch

ref: e2d1ef1fa0dd5df1da3f7ce477522a3966414a5a
parent: 24f36e0a95abe099545e0a660169f7c7fe083b63
author: Jean-Marc Valin <[email protected]>
date: Tue Jul 6 11:39:19 EDT 2010

Delay compensation, disabling the CELT pitch predictor

--- a/src/hybrid_encoder.c
+++ b/src/hybrid_encoder.c
@@ -46,7 +46,7 @@
 	HybridEncoder *st;
 	int ret, encSizeBytes;
 
-	st = malloc(sizeof(HybridEncoder));
+	st = calloc(sizeof(HybridEncoder), 1);
 
     /* Create SILK encoder */
     ret = SKP_Silk_SDK_Get_Encoder_Size( &encSizeBytes );
@@ -77,6 +77,7 @@
 
 	st->mode = MODE_HYBRID;
 	st->bandwidth = BANDWIDTH_FULLBAND;
+	st->vbr_rate = 0;
 
 	return st;
 }
@@ -84,6 +85,7 @@
 int hybrid_encode(HybridEncoder *st, const short *pcm, int frame_size,
 		unsigned char *data, int bytes_per_packet)
 {
+    int i;
 	int ret=0;
 	SKP_int16 nBytes;
 	ec_enc enc;
@@ -94,7 +96,7 @@
 
 	if (st->mode != MODE_CELT_ONLY)
 	{
-	    st->encControl.bitRate               = (bytes_per_packet*50*8+4000)/2;
+	    st->encControl.bitRate = (bytes_per_packet*50*8+6000)/2;
 	    /* Call SILK encoder for the low band */
 	    nBytes = bytes_per_packet;
 	    ret = SKP_Silk_SDK_Encode( st->silk_enc, &st->encControl, pcm, 960, &enc, &nBytes );
@@ -115,9 +117,19 @@
 
 	if (st->mode != MODE_SILK_ONLY)
 	{
+	    short buf[960];
+
+	    for (i=0;i<ENCODER_DELAY_COMPENSATION;i++)
+	        buf[i] = st->delay_buffer[i];
+        for (;i<960;i++)
+            buf[i] = pcm[i-ENCODER_DELAY_COMPENSATION];
+
+        celt_encoder_ctl(st->celt_enc, CELT_SET_PREDICTION(1));
 	    /* Encode high band with CELT */
 	    /* FIXME: Do some delay compensation here */
-	    ret = celt_encode_with_ec(st->celt_enc, pcm, NULL, frame_size, data, bytes_per_packet, &enc);
+	    ret = celt_encode_with_ec(st->celt_enc, buf, NULL, frame_size, data, bytes_per_packet, &enc);
+	    for (i=0;i<ENCODER_DELAY_COMPENSATION;i++)
+	        st->delay_buffer[i] = pcm[960-ENCODER_DELAY_COMPENSATION+i];
 	} else {
 	    ec_enc_done(&enc);
 	}
--- a/src/hybrid_encoder.h
+++ b/src/hybrid_encoder.h
@@ -36,6 +36,9 @@
 #include "hybrid.h"
 #include "SKP_Silk_SDK_API.h"
 
+/* FIXME: This is only valid for 48 kHz */
+#define ENCODER_DELAY_COMPENSATION 130
+
 struct HybridEncoder {
 	CELTMode    *celt_mode;
 	CELTEncoder *celt_enc;
@@ -45,6 +48,8 @@
     int          mode;
 	int          bandwidth;
     int          vbr_rate;
+
+    short        delay_buffer[ENCODER_DELAY_COMPENSATION];
 };