From 862e18256a4a90338b083c655fe3b7e529f9947e Mon Sep 17 00:00:00 2001
From: Jean-Marc Valin <jean-marc.valin@octasic.com>
Date: Tue, 20 Jul 2010 12:19:00 -0400
Subject: [PATCH] SILK encoder control struct no longer part of the state

---
 src/hybrid_encoder.c | 44 ++++++++++++++++++++++++--------------------
 src/hybrid_encoder.h |  1 -
 2 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/src/hybrid_encoder.c b/src/hybrid_encoder.c
index 2acf3eb5e..fd9f599d9 100644
--- a/src/hybrid_encoder.c
+++ b/src/hybrid_encoder.c
@@ -45,9 +45,12 @@ HybridEncoder *hybrid_encoder_create(int Fs)
 {
 	HybridEncoder *st;
 	int ret, encSizeBytes;
+    SKP_SILK_SDK_EncControlStruct encControl;
 
 	st = calloc(sizeof(HybridEncoder), 1);
 
+    st->Fs = Fs;
+
     /* Create SILK encoder */
     ret = SKP_Silk_SDK_Get_Encoder_Size( &encSizeBytes );
     if( ret ) {
@@ -55,23 +58,16 @@ HybridEncoder *hybrid_encoder_create(int Fs)
     }
 	st->silk_enc = malloc(encSizeBytes);
 
-    ret = SKP_Silk_SDK_InitEncoder( st->silk_enc, &st->encControl );
+    /*encControl.API_sampleRate        = st->Fs;
+    encControl.packetLossPercentage  = 0;
+    encControl.useInBandFEC          = 0;
+    encControl.useDTX                = 0;
+    encControl.complexity            = 2;*/
+    ret = SKP_Silk_SDK_InitEncoder( st->silk_enc, &encControl );
     if( ret ) {
         /* Handle error */
     }
 
-    st->Fs = Fs;
-
-    /* Set Encoder parameters */
-    st->encControl.API_sampleRate        = Fs;
-    st->encControl.maxInternalSampleRate = 16000;
-    st->encControl.packetSize            = Fs/50;
-    st->encControl.packetLossPercentage  = 0;
-    st->encControl.useInBandFEC          = 0;
-    st->encControl.useDTX                = 0;
-    st->encControl.complexity            = 2;
-    st->encControl.bitRate               = 18000;
-
     /* Create CELT encoder */
 	/* We should not have to create a CELT mode for each encoder state */
 	st->celt_mode = celt_mode_create(Fs, Fs/50, NULL);
@@ -93,27 +89,35 @@ int hybrid_encode(HybridEncoder *st, const short *pcm, int frame_size,
 	SKP_int16 nBytes;
 	ec_enc enc;
 	ec_byte_buffer buf;
+	SKP_SILK_SDK_EncControlStruct encControl;
 
 	ec_byte_writeinit_buffer(&buf, data, bytes_per_packet);
 	ec_enc_init(&enc,&buf);
 
 	if (st->mode != MODE_CELT_ONLY)
 	{
-	    st->encControl.bitRate = (bytes_per_packet*50*8+6000)/2;
+	    /* Set Encoder parameters */
+	    encControl.API_sampleRate        = st->Fs;
+	    encControl.packetLossPercentage  = 0;
+	    encControl.useInBandFEC          = 0;
+	    encControl.useDTX                = 0;
+	    encControl.complexity            = 2;
+
+	    encControl.bitRate = (bytes_per_packet*50*8+6000)/2;
 	    if (st->Fs / frame_size == 100)
-	        st->encControl.bitRate += 5000;
-	    st->encControl.packetSize = frame_size;
+	        encControl.bitRate += 5000;
+	    encControl.packetSize = frame_size;
 
 	    if (st->bandwidth == BANDWIDTH_NARROWBAND)
-	        st->encControl.maxInternalSampleRate = 8000;
+	        encControl.maxInternalSampleRate = 8000;
 	    else if (st->bandwidth == BANDWIDTH_MEDIUMBAND)
-            st->encControl.maxInternalSampleRate = 12000;
+            encControl.maxInternalSampleRate = 12000;
 	    else
-	        st->encControl.maxInternalSampleRate = 16000;
+	        encControl.maxInternalSampleRate = 16000;
 
 	    /* Call SILK encoder for the low band */
 	    nBytes = bytes_per_packet;
-	    ret = SKP_Silk_SDK_Encode( st->silk_enc, &st->encControl, pcm, frame_size, &enc, &nBytes );
+	    ret = SKP_Silk_SDK_Encode( st->silk_enc, &encControl, pcm, frame_size, &enc, &nBytes );
 	    if( ret ) {
 	        fprintf (stderr, "SILK encode error\n");
 	        /* Handle error */
diff --git a/src/hybrid_encoder.h b/src/hybrid_encoder.h
index 6e4c62a8c..adb5f1df2 100644
--- a/src/hybrid_encoder.h
+++ b/src/hybrid_encoder.h
@@ -43,7 +43,6 @@ struct HybridEncoder {
 	CELTMode    *celt_mode;
 	CELTEncoder *celt_enc;
 	void        *silk_enc;
-	SKP_SILK_SDK_EncControlStruct encControl;
 
     int          mode;
 	int          bandwidth;
-- 
GitLab