Support for 32 kHz sampling rate
authorJean-Marc Valin <jean-marc.valin@octasic.com>
Mon, 19 Jul 2010 15:44:36 +0000 (11:44 -0400)
committerJean-Marc Valin <jean-marc.valin@octasic.com>
Mon, 19 Jul 2010 15:44:36 +0000 (11:44 -0400)
celt
src/hybrid.h
src/hybrid_decoder.c
src/hybrid_decoder.h
src/hybrid_encoder.c
src/hybrid_encoder.h
src/test_hybrid.c

diff --git a/celt b/celt
index 8952c45..b1e017f 160000 (submodule)
--- a/celt
+++ b/celt
@@ -1 +1 @@
-Subproject commit 8952c45ea54a5608cd61fe2e137e39d0c3b19853
+Subproject commit b1e017f58d2bb319eb7bc3305048185a9c8fe9d9
index 94d9f06..ae1566d 100644 (file)
@@ -76,7 +76,7 @@ extern "C" {
 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_destroy(HybridEncoder *st);
 
 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);
index 2d258a4..8eab5c9 100644 (file)
 #include "SKP_Silk_SDK_API.h"
 
 
-HybridDecoder *hybrid_decoder_create()
+HybridDecoder *hybrid_decoder_create(int Fs)
 {
        int ret, decSizeBytes;
        HybridDecoder *st;
 
        st = malloc(sizeof(HybridDecoder));
 
+       st->Fs = Fs;
+
        /* Initialize SILK encoder */
     ret = SKP_Silk_SDK_Get_Decoder_Size( &decSizeBytes );
     if( ret ) {
@@ -63,7 +65,7 @@ HybridDecoder *hybrid_decoder_create()
     }
 
        /* 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 @@ int hybrid_decode(HybridDecoder *st, const unsigned char *data,
 
     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)
index eeeb0ee..b5a54fb 100644 (file)
@@ -42,6 +42,8 @@ struct HybridDecoder {
 
     int          mode;
     int          bandwidth;
+    /* Sampling rate (at the API level) */
+    int          Fs;
 };
 
 
index b2222c1..413f08b 100644 (file)
@@ -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 @@ HybridEncoder *hybrid_encoder_create()
     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 @@ HybridEncoder *hybrid_encoder_create()
 
     /* 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 @@ int hybrid_encode(HybridEncoder *st, const short *pcm, int frame_size,
        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 @@ int hybrid_encode(HybridEncoder *st, const short *pcm, int frame_size,
 
         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];
index 0d834a5..6e4c62a 100644 (file)
@@ -48,6 +48,8 @@ struct HybridEncoder {
     int          mode;
        int          bandwidth;
     int          vbr_rate;
+    /* Sampling rate (at the API level) */
+    int          Fs;
 
     short        delay_buffer[ENCODER_DELAY_COMPENSATION];
 };
index 06ae843..9a5af09 100644 (file)
@@ -94,8 +94,8 @@ int main(int argc, char *argv[])
       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));