ref: 2e8a55cc074d8ac28b0dafa93208980678d77028
parent: bcdfe6340aa3865d32c01100f54ae5297eea5066
author: Jean-Marc Valin <[email protected]>
date: Tue Aug 31 07:31:54 EDT 2010
Hybrid decoder also in a single block of memory
--- a/src/hybrid_decoder.c
+++ b/src/hybrid_decoder.c
@@ -44,20 +44,28 @@
HybridDecoder *hybrid_decoder_create(int Fs)
{
- int ret, decSizeBytes;
+ char *raw_state;
+ int ret, silkDecSizeBytes, celtDecSizeBytes;
+ CELTMode *celtMode;
HybridDecoder *st;
- st = malloc(sizeof(HybridDecoder));
+ /* We should not have to create a CELT mode for each encoder state */
+ celtMode = celt_mode_create(Fs, Fs/50, NULL);
- st->Fs = Fs;
-
/* Initialize SILK encoder */
- ret = SKP_Silk_SDK_Get_Decoder_Size( &decSizeBytes );
+ ret = SKP_Silk_SDK_Get_Decoder_Size( &silkDecSizeBytes );
if( ret ) {
/* Handle error */
}
- st->silk_dec = malloc( decSizeBytes );
+ celtDecSizeBytes = celt_decoder_get_size(celtMode, 1);
+ raw_state = calloc(sizeof(HybridDecoder)+silkDecSizeBytes+celtDecSizeBytes, 1);
+ st = (HybridDecoder*)raw_state;
+ st->silk_dec = (void*)(raw_state+sizeof(HybridDecoder));
+ st->celt_dec = (CELTDecoder*)(raw_state+sizeof(HybridDecoder)+silkDecSizeBytes);
+ st->Fs = Fs;
+ st->celt_mode = celtMode;
+
/* Reset decoder */
ret = SKP_Silk_SDK_InitDecoder( st->silk_dec );
if( ret ) {
@@ -64,10 +72,8 @@
/* Handle error */
}
- /* We should not have to create a CELT mode for each encoder state */
- st->celt_mode = celt_mode_create(Fs, Fs/50, NULL);
- /* Initialize CELT encoder */
- st->celt_dec = celt_decoder_create(st->celt_mode, 1, NULL);
+ /* Initialize CELT decoder */
+ st->celt_dec = celt_decoder_init(st->celt_dec, st->celt_mode, 1, NULL);
return st;
@@ -171,8 +177,6 @@
void hybrid_decoder_destroy(HybridDecoder *st)
{
- free(st->silk_dec);
- celt_decoder_destroy(st->celt_dec);
celt_mode_destroy(st->celt_mode);
free(st);
--- a/src/hybrid_encoder.c
+++ b/src/hybrid_encoder.c
@@ -54,10 +54,10 @@
/* Create SILK encoder */
ret = SKP_Silk_SDK_Get_Encoder_Size( &silkEncSizeBytes );
- celtEncSizeBytes = celt_encoder_get_size(celtMode, 1);
if( ret ) {
/* Handle error */
}
+ celtEncSizeBytes = celt_encoder_get_size(celtMode, 1);
raw_state = calloc(sizeof(HybridEncoder)+silkEncSizeBytes+celtEncSizeBytes, 1);
st = (HybridEncoder*)raw_state;
st->silk_enc = (void*)(raw_state+sizeof(HybridEncoder));