shithub: opus

Download patch

ref: ae18090b550cb9a116712be2f9d96957d7f305f3
parent: 060d1f9ad3dddbdc018c07729cd10a428dbe24e4
author: Jean-Marc Valin <[email protected]>
date: Mon Jul 19 07:44:36 EDT 2010

Support for 32 kHz sampling rate

--- a/src/hybrid.h
+++ b/src/hybrid.h
@@ -76,7 +76,7 @@
 typedef struct HybridEncoder HybridEncoder;
 typedef struct HybridDecoder HybridDecoder;
 
-HybridEncoder *hybrid_encoder_create();
+HybridEncoder *hybrid_encoder_create(int Fs);
 
 int hybrid_encode(HybridEncoder *st, const short *pcm, int frame_size,
 		unsigned char *data, int bytes_per_packet);
@@ -85,7 +85,7 @@
 
 void hybrid_encoder_ctl(HybridEncoder *st, int request, ...);
 
-HybridDecoder *hybrid_decoder_create();
+HybridDecoder *hybrid_decoder_create(int Fs);
 
 int hybrid_decode(HybridDecoder *st, const unsigned char *data, int len,
 		short *pcm, int frame_size);
--- a/src/hybrid_decoder.c
+++ b/src/hybrid_decoder.c
@@ -42,7 +42,7 @@
 #include "SKP_Silk_SDK_API.h"
 
 
-HybridDecoder *hybrid_decoder_create()
+HybridDecoder *hybrid_decoder_create(int Fs)
 {
 	int ret, decSizeBytes;
 	HybridDecoder *st;
@@ -49,6 +49,8 @@
 
 	st = malloc(sizeof(HybridDecoder));
 
+	st->Fs = Fs;
+
 	/* Initialize SILK encoder */
     ret = SKP_Silk_SDK_Get_Decoder_Size( &decSizeBytes );
     if( ret ) {
@@ -63,7 +65,7 @@
     }
 
 	/* We should not have to create a CELT mode for each encoder state */
-	st->celt_mode = celt_mode_create(48000, 960, NULL);
+	st->celt_mode = celt_mode_create(Fs, Fs/50, NULL);
 	/* Initialize CELT encoder */
 	st->celt_dec = celt_decoder_create(st->celt_mode, 1, NULL);
 
@@ -85,7 +87,7 @@
 
     if (st->mode != MODE_CELT_ONLY)
     {
-        DecControl.API_sampleRate = 48000;
+        DecControl.API_sampleRate = st->Fs;
         /* Call SILK encoder for the low band */
         silk_ret = SKP_Silk_SDK_Decode( st->silk_dec, &DecControl, 0, &dec, len, pcm, &silk_frame_size );
         if (silk_ret)
--- a/src/hybrid_decoder.h
+++ b/src/hybrid_decoder.h
@@ -42,6 +42,8 @@
 
     int          mode;
     int          bandwidth;
+    /* Sampling rate (at the API level) */
+    int          Fs;
 };
 
 
--- a/src/hybrid_encoder.c
+++ b/src/hybrid_encoder.c
@@ -41,7 +41,7 @@
 #include "modes.h"
 #include "SKP_Silk_SDK_API.h"
 
-HybridEncoder *hybrid_encoder_create()
+HybridEncoder *hybrid_encoder_create(int Fs)
 {
 	HybridEncoder *st;
 	int ret, encSizeBytes;
@@ -59,10 +59,13 @@
     if( ret ) {
         /* Handle error */
     }
+
+    st->Fs = Fs;
+
     /* Set Encoder parameters */
-    st->encControl.API_sampleRate        = 48000;
+    st->encControl.API_sampleRate        = Fs;
     st->encControl.maxInternalSampleRate = 16000;
-    st->encControl.packetSize            = 960;
+    st->encControl.packetSize            = Fs/50;
     st->encControl.packetLossPercentage  = 0;
     st->encControl.useInBandFEC          = 0;
     st->encControl.useDTX                = 0;
@@ -71,7 +74,7 @@
 
     /* Create CELT encoder */
 	/* We should not have to create a CELT mode for each encoder state */
-	st->celt_mode = celt_mode_create(48000, 960, NULL);
+	st->celt_mode = celt_mode_create(Fs, Fs/50, NULL);
 	/* Initialize CELT encoder */
 	st->celt_enc = celt_encoder_create(st->celt_mode, 1, NULL);
 
@@ -97,6 +100,8 @@
 	if (st->mode != MODE_CELT_ONLY)
 	{
 	    st->encControl.bitRate = (bytes_per_packet*50*8+6000)/2;
+	    if (st->Fs / frame_size == 100)
+	        st->encControl.bitRate += 5000;
 	    st->encControl.packetSize = frame_size;
 	    /* Call SILK encoder for the low band */
 	    nBytes = bytes_per_packet;
@@ -127,7 +132,6 @@
 
         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, buf, NULL, frame_size, data, bytes_per_packet, &enc);
 	    for (i=0;i<ENCODER_DELAY_COMPENSATION;i++)
 	        st->delay_buffer[i] = pcm[frame_size-ENCODER_DELAY_COMPENSATION+i];
--- a/src/hybrid_encoder.h
+++ b/src/hybrid_encoder.h
@@ -48,6 +48,8 @@
     int          mode;
 	int          bandwidth;
     int          vbr_rate;
+    /* Sampling rate (at the API level) */
+    int          Fs;
 
     short        delay_buffer[ENCODER_DELAY_COMPENSATION];
 };
--- a/src/test_hybrid.c
+++ b/src/test_hybrid.c
@@ -94,8 +94,8 @@
       return 1;
    }
 
-   enc = hybrid_encoder_create();
-   dec = hybrid_decoder_create();
+   enc = hybrid_encoder_create(rate);
+   dec = hybrid_decoder_create(rate);
 
    mode = MODE_HYBRID;
    hybrid_encoder_ctl(enc, HYBRID_SET_BANDWIDTH(BANDWIDTH_FULLBAND));