shithub: opus

Download patch

ref: e6f53b730328093831f992f1bac78cdb2e266ded
parent: 3c8bd3ffc7342089c74a7386ae9785c473cff5fc
author: Jean-Marc Valin <[email protected]>
date: Sun Jan 30 18:44:51 EST 2011

Updated to CELT's new API

--- a/configure.ac
+++ b/configure.ac
@@ -3,7 +3,7 @@
 
 AC_PREREQ([2.59])
 AC_INIT(src/opus.h)
-AM_INIT_AUTOMAKE(opus,20101113)
+AM_INIT_AUTOMAKE(opus,20110122)
 
 # Checks for programs.
 AC_PROG_CC
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -46,18 +46,14 @@
 {
     char *raw_state;
 	int ret, silkDecSizeBytes, celtDecSizeBytes;
-	CELTMode *celtMode;
 	OpusDecoder *st;
 
-    /* We should not have to create a CELT mode for each encoder state */
-    celtMode = celt_mode_create(Fs, Fs/50, NULL);
-
 	/* Initialize SILK encoder */
     ret = SKP_Silk_SDK_Get_Decoder_Size( &silkDecSizeBytes );
     if( ret ) {
         /* Handle error */
     }
-    celtDecSizeBytes = celt_decoder_get_size(celtMode, 1);
+    celtDecSizeBytes = celt_decoder_get_size(1);
     raw_state = calloc(sizeof(OpusDecoder)+silkDecSizeBytes+celtDecSizeBytes, 1);
     st = (OpusDecoder*)raw_state;
     st->silk_dec = (void*)(raw_state+sizeof(OpusDecoder));
@@ -64,7 +60,6 @@
     st->celt_dec = (CELTDecoder*)(raw_state+sizeof(OpusDecoder)+silkDecSizeBytes);
 
     st->Fs = Fs;
-    st->celt_mode = celtMode;
 
     /* Reset decoder */
     ret = SKP_Silk_SDK_InitDecoder( st->silk_dec );
@@ -73,7 +68,7 @@
     }
 
 	/* Initialize CELT decoder */
-	st->celt_dec = celt_decoder_init(st->celt_dec, st->celt_mode, 1, NULL);
+	st->celt_dec = celt_decoder_init(st->celt_dec, 48000, 1, NULL);
 
 	return st;
 
@@ -166,10 +161,25 @@
 
     if (st->mode != MODE_SILK_ONLY && st->bandwidth > BANDWIDTH_WIDEBAND)
     {
-        if (st->bandwidth == BANDWIDTH_SUPERWIDEBAND)
-            celt_decoder_ctl(st->celt_dec, CELT_SET_END_BAND(20));
-        else
-            celt_decoder_ctl(st->celt_dec, CELT_SET_END_BAND(21));
+    	int endband;
+
+	    switch(st->bandwidth)
+	    {
+	    case BANDWIDTH_NARROWBAND:
+	    	endband = 13;
+	    	break;
+	    case BANDWIDTH_WIDEBAND:
+	    	endband = 17;
+	    	break;
+	    case BANDWIDTH_SUPERWIDEBAND:
+	    	endband = 19;
+	    	break;
+	    case BANDWIDTH_FULLBAND:
+	    	endband = 21;
+	    	break;
+	    }
+	    celt_decoder_ctl(st->celt_dec, CELT_SET_END_BAND(endband));
+
         /* Encode high band with CELT */
         celt_ret = celt_decode_with_ec(st->celt_dec, data, len, pcm_celt, frame_size, &dec);
         for (i=0;i<frame_size;i++)
@@ -221,7 +231,5 @@
 
 void opus_decoder_destroy(OpusDecoder *st)
 {
-	celt_mode_destroy(st->celt_mode);
-
 	free(st);
 }
--- a/src/opus_decoder.h
+++ b/src/opus_decoder.h
@@ -36,7 +36,6 @@
 #include "opus.h"
 
 struct OpusDecoder {
-	CELTMode    *celt_mode;
 	CELTDecoder *celt_dec;
 	void        *silk_dec;
 
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -44,20 +44,16 @@
 OpusEncoder *opus_encoder_create(int Fs)
 {
     char *raw_state;
-    CELTMode *celtMode;
 	OpusEncoder *st;
 	int ret, silkEncSizeBytes, celtEncSizeBytes;
     SKP_SILK_SDK_EncControlStruct encControl;
 
-    /* We should not have to create a CELT mode for each encoder state */
-    celtMode = celt_mode_create(Fs, Fs/50, NULL);
-
     /* Create SILK encoder */
     ret = SKP_Silk_SDK_Get_Encoder_Size( &silkEncSizeBytes );
     if( ret ) {
     	/* Handle error */
     }
-    celtEncSizeBytes = celt_encoder_get_size(celtMode, 1);
+    celtEncSizeBytes = celt_encoder_get_size(1);
     raw_state = calloc(sizeof(OpusEncoder)+silkEncSizeBytes+celtEncSizeBytes, 1);
     st = (OpusEncoder*)raw_state;
     st->silk_enc = (void*)(raw_state+sizeof(OpusEncoder));
@@ -64,7 +60,6 @@
     st->celt_enc = (CELTEncoder*)(raw_state+sizeof(OpusEncoder)+silkEncSizeBytes);
 
     st->Fs = Fs;
-    st->celt_mode = celtMode;
 
     /*encControl.API_sampleRate        = st->Fs;
     encControl.packetLossPercentage  = 0;
@@ -78,7 +73,7 @@
 
     /* Create CELT encoder */
 	/* Initialize CELT encoder */
-	st->celt_enc = celt_encoder_init(st->celt_enc, st->celt_mode, 1, NULL);
+	st->celt_enc = celt_encoder_init(st->celt_enc, Fs, 1, NULL);
 
 	st->mode = MODE_HYBRID;
 	st->bandwidth = BANDWIDTH_FULLBAND;
@@ -119,19 +114,19 @@
 	        if (st->Fs  == 100 * frame_size)
 	            encControl.bitRate -= 5000;
 	    }
-            encControl.payloadSize_ms = 1000 * frame_size / st->Fs;
+	    encControl.payloadSize_ms = 1000 * frame_size / st->Fs;
 
-            if (st->mode == MODE_HYBRID)
-               encControl.minInternalSampleRate = 16000;
-            else
-               encControl.minInternalSampleRate = 8000;
+	    if (st->mode == MODE_HYBRID)
+	    	encControl.minInternalSampleRate = 16000;
+	    else
+	    	encControl.minInternalSampleRate = 8000;
 
 	    if (st->bandwidth == BANDWIDTH_NARROWBAND)
 	        encControl.maxInternalSampleRate = 8000;
 	    else if (st->bandwidth == BANDWIDTH_MEDIUMBAND)
-               encControl.maxInternalSampleRate = 12000;
+	    	encControl.maxInternalSampleRate = 12000;
 	    else
-               encControl.maxInternalSampleRate = 16000;
+	    	encControl.maxInternalSampleRate = 16000;
 
 	    /* Call SILK encoder for the low band */
 	    nBytes = bytes_per_packet;
@@ -153,12 +148,25 @@
 
 	if (st->mode != MODE_SILK_ONLY && st->bandwidth > BANDWIDTH_WIDEBAND)
 	{
+		int endband;
 	    short pcm_buf[960];
 
-        if (st->bandwidth == BANDWIDTH_SUPERWIDEBAND)
-            celt_encoder_ctl(st->celt_enc, CELT_SET_END_BAND(20));
-        else
-            celt_encoder_ctl(st->celt_enc, CELT_SET_END_BAND(21));
+	    switch(st->bandwidth)
+	    {
+	    case BANDWIDTH_NARROWBAND:
+	    	endband = 13;
+	    	break;
+	    case BANDWIDTH_WIDEBAND:
+	    	endband = 17;
+	    	break;
+	    case BANDWIDTH_SUPERWIDEBAND:
+	    	endband = 19;
+	    	break;
+	    case BANDWIDTH_FULLBAND:
+	    	endband = 21;
+	    	break;
+	    }
+	    celt_encoder_ctl(st->celt_enc, CELT_SET_END_BAND(endband));
 
 	    for (i=0;i<ENCODER_DELAY_COMPENSATION;i++)
 	        pcm_buf[i] = st->delay_buffer[i];
@@ -269,7 +277,6 @@
 
 void opus_encoder_destroy(OpusEncoder *st)
 {
-	celt_mode_destroy(st->celt_mode);
 	free(st);
 }
 
--- a/src/opus_encoder.h
+++ b/src/opus_encoder.h
@@ -40,7 +40,6 @@
 #define ENCODER_DELAY_COMPENSATION 130
 
 struct OpusEncoder {
-	CELTMode    *celt_mode;
 	CELTEncoder *celt_enc;
 	void        *silk_enc;