Added SILK encoder to the hybrid -- totally untested
authorJean-Marc Valin <jean-marc.valin@octasic.com>
Mon, 5 Jul 2010 15:11:54 +0000 (11:11 -0400)
committerJean-Marc Valin <jean-marc.valin@octasic.com>
Mon, 5 Jul 2010 15:11:54 +0000 (11:11 -0400)
src/Makefile
src/hybrid_encoder.c
src/hybrid_encoder.h

index d777400..639ca28 100644 (file)
@@ -1,2 +1,2 @@
 all:
-       gcc -DHAVE_CONFIG_H -I../celt -W -Wextra -Wall -O3 -g -I../ -I../celt/libcelt -L../celt/libcelt/.libs/ -o test_hybrid test_hybrid.c hybrid_decoder.c hybrid_encoder.c -lcelt0 -lm
+       gcc -DHAVE_CONFIG_H -I../celt -W -Wextra -Wall -O3 -g -I../ -I../celt/libcelt -L../celt/libcelt/.libs/ -o test_hybrid test_hybrid.c hybrid_decoder.c hybrid_encoder.c ../silk/test/SKP_debug.o ../silk/libSKP_SILK_SDK.a -lcelt0 -I../silk/interface -lm
index 6e19c43..bedebd4 100644 (file)
 #include "hybrid_encoder.h"
 #include "celt/libcelt/entenc.h"
 #include "celt/libcelt/modes.h"
+#include "SKP_Silk_SDK_API.h"
 
 HybridEncoder *hybrid_encoder_create()
 {
        HybridEncoder *st;
+       int ret, encSizeBytes;
 
        st = malloc(sizeof(HybridEncoder));
 
-       /* FIXME: Initialize SILK encoder here */
-       st->silk_enc = NULL;
-
+    /* Create SILK encoder */
+    ret = SKP_Silk_SDK_Get_Encoder_Size( &encSizeBytes );
+    if( ret ) {
+       /* Handle error */
+    }
+       st->silk_enc = malloc(encSizeBytes);
+
+    ret = SKP_Silk_SDK_InitEncoder( st->silk_enc, &st->encControl );
+    if( ret ) {
+        /* Handle error */
+    }
+    /* Set Encoder parameters */
+    st->encControl.API_sampleRate        = 48000;
+    st->encControl.maxInternalSampleRate = 16000;
+    st->encControl.packetSize            = 960;
+    st->encControl.packetLossPercentage  = 0;
+    st->encControl.useInBandFEC          = 0;
+    st->encControl.useDTX                = 0;
+    st->encControl.complexity            = 2;
+    st->encControl.bitRate               = 20000;
+
+    /* 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);
        /* Initialize CELT encoder */
@@ -58,7 +79,8 @@ HybridEncoder *hybrid_encoder_create()
 int hybrid_encode(HybridEncoder *st, const short *pcm, int frame_size,
                unsigned char *data, int bytes_per_packet)
 {
-       int celt_ret;
+       int silk_ret, celt_ret;
+       SKP_int16 nBytes;
        ec_enc enc;
        ec_byte_buffer buf;
 
@@ -66,6 +88,10 @@ int hybrid_encode(HybridEncoder *st, const short *pcm, int frame_size,
        ec_enc_init(&enc,&buf);
 
        /* FIXME: Call SILK encoder for the low band */
+       silk_ret = SKP_Silk_SDK_Encode( st->silk_enc, &st->encControl, pcm, 960, &enc, &nBytes );
+    if( silk_ret ) {
+        /* Handle error */
+    }
 
        /* This should be adjusted based on the SILK bandwidth */
        celt_encoder_ctl(st->celt_enc, CELT_SET_START_BAND(13));
@@ -78,7 +104,7 @@ int hybrid_encode(HybridEncoder *st, const short *pcm, int frame_size,
 
 void hybrid_encoder_destroy(HybridEncoder *st)
 {
-       /* FIXME: Destroy SILK encoder state */
+       free(st->silk_enc);
 
        celt_encoder_destroy(st->celt_enc);
        celt_mode_destroy(st->celt_mode);
index 2b2a4e9..8d8269c 100644 (file)
 
 #include "celt/libcelt/celt.h"
 #include "hybrid.h"
+#include "SKP_Silk_SDK_API.h"
 
 struct HybridEncoder {
        CELTMode    *celt_mode;
        CELTEncoder *celt_enc;
        void        *silk_enc;
+       SKP_SILK_SDK_EncControlStruct encControl;
 };