[xiph-commits] r9413 - trunk/speex/libspeex

jm at motherfish-iii.xiph.org jm at motherfish-iii.xiph.org
Wed Jun 8 22:09:56 PDT 2005


Author: jm
Date: 2005-06-08 22:09:53 -0700 (Wed, 08 Jun 2005)
New Revision: 9413

Modified:
   trunk/speex/libspeex/misc.c
   trunk/speex/libspeex/misc.h
   trunk/speex/libspeex/nb_celp.c
   trunk/speex/libspeex/sb_celp.c
Log:
Allow the stack to be allocated with speex_alloc_scratch()


Modified: trunk/speex/libspeex/misc.c
===================================================================
--- trunk/speex/libspeex/misc.c	2005-06-09 04:44:49 UTC (rev 9412)
+++ trunk/speex/libspeex/misc.c	2005-06-09 05:09:53 UTC (rev 9413)
@@ -131,6 +131,10 @@
 {
    return calloc(size,1);
 }
+void *speex_alloc_scratch (int size)
+{
+   return calloc(size,1);
+}
 
 void *speex_realloc (void *ptr, int size)
 {
@@ -141,6 +145,10 @@
 {
    free(ptr);
 }
+void speex_free_scratch (void *ptr)
+{
+   free(ptr);
+}
 
 #ifndef OVERRIDE_SPEEX_MOVE
 void *speex_move (void *dest, void *src, int n)

Modified: trunk/speex/libspeex/misc.h
===================================================================
--- trunk/speex/libspeex/misc.h	2005-06-09 04:44:49 UTC (rev 9412)
+++ trunk/speex/libspeex/misc.h	2005-06-09 05:09:53 UTC (rev 9413)
@@ -55,12 +55,18 @@
 /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_free */
 void *speex_alloc (int size);
 
+/** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
+void *speex_alloc_scratch (int size);
+
 /** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, speex_alloc and speex_free */
 void *speex_realloc (void *ptr, int size);
 
 /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_alloc */
 void speex_free (void *ptr);
 
+/** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
+void speex_free_scratch (void *ptr);
+
 /** Speex wrapper for mem_move */
 void *speex_move (void *dest, void *src, int n);
 

Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c	2005-06-09 04:44:49 UTC (rev 9412)
+++ trunk/speex/libspeex/nb_celp.c	2005-06-09 05:09:53 UTC (rev 9413)
@@ -105,16 +105,13 @@
    int i;
 
    mode=(const SpeexNBMode *)m->mode;
-#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
    st = (EncState*)speex_alloc(sizeof(EncState));
    if (!st)
       return NULL;
+#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
    st->stack = NULL;
 #else
-   st = (EncState*)speex_alloc(sizeof(EncState)+NB_ENC_STACK);
-   if (!st)
-      return NULL;
-   st->stack = ((char*)st) + sizeof(EncState);
+   st->stack = (char*)speex_alloc_scratch(NB_ENC_STACK);
 #endif
    
    st->mode=m;
@@ -221,6 +218,9 @@
 {
    EncState *st=(EncState *)state;
    /* Free all allocated memory */
+#if !(defined(VAR_ARRAYS) || defined (USE_ALLOCA))
+   speex_free_scratch(st->stack);
+#endif
 
    speex_free (st->inBuf);
    speex_free (st->excBuf);
@@ -975,16 +975,13 @@
    int i;
 
    mode=(const SpeexNBMode*)m->mode;
-#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
    st = (DecState *)speex_alloc(sizeof(DecState));
    if (!st)
       return NULL;
+#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
    st->stack = NULL;
 #else
-   st = (DecState *)speex_alloc(sizeof(DecState)+NB_DEC_STACK);
-   if (!st)
-      return NULL;
-   st->stack = ((char*)st) + sizeof(DecState);
+   st->stack = (char*)speex_alloc_scratch(NB_DEC_STACK);
 #endif
 
    st->mode=m;
@@ -1057,6 +1054,10 @@
    DecState *st;
    st=(DecState*)state;
    
+#if !(defined(VAR_ARRAYS) || defined (USE_ALLOCA))
+   speex_free_scratch(st->stack);
+#endif
+
    speex_free (st->inBuf);
    speex_free (st->excBuf);
    speex_free (st->innov);

Modified: trunk/speex/libspeex/sb_celp.c
===================================================================
--- trunk/speex/libspeex/sb_celp.c	2005-06-09 04:44:49 UTC (rev 9412)
+++ trunk/speex/libspeex/sb_celp.c	2005-06-09 05:09:53 UTC (rev 9413)
@@ -227,16 +227,13 @@
    SBEncState *st;
    const SpeexSBMode *mode;
 
-#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
    st = (SBEncState*)speex_alloc(sizeof(SBEncState));
    if (!st)
       return NULL;
+#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
    st->stack = NULL;
 #else
-   st = (SBEncState*)speex_alloc(sizeof(SBEncState)+SB_ENC_STACK);
-   if (!st)
-      return NULL;
-   st->stack = ((char*)st) + sizeof(SBEncState);
+   st->stack = (char*)speex_alloc_scratch(SB_ENC_STACK);
 #endif
    st->mode = m;
    mode = (const SpeexSBMode*)m->mode;
@@ -337,6 +334,9 @@
    SBEncState *st=(SBEncState*)state;
 
    speex_encoder_destroy(st->st_low);
+#if !(defined(VAR_ARRAYS) || defined (USE_ALLOCA))
+   speex_free_scratch(st->stack);
+#endif
 
    speex_free(st);
 }
@@ -796,16 +796,13 @@
 {
    SBDecState *st;
    const SpeexSBMode *mode;
-#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
    st = (SBDecState*)speex_alloc(sizeof(SBDecState));
    if (!st)
       return NULL;
+#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
    st->stack = NULL;
-#else   
-   st = (SBDecState*)speex_alloc(sizeof(SBDecState)+SB_DEC_STACK);
-   if (!st)
-      return NULL;
-   st->stack = ((char*)st) + sizeof(SBDecState);
+#else
+   st->stack = (char*)speex_alloc_scratch(SB_DEC_STACK);
 #endif
    st->mode = m;
    mode=(const SpeexSBMode*)m->mode;
@@ -862,7 +859,9 @@
    SBDecState *st;
    st = (SBDecState*)state;
    speex_decoder_destroy(st->st_low);
-
+#if !(defined(VAR_ARRAYS) || defined (USE_ALLOCA))
+   speex_free_scratch(st->stack);
+#endif
    speex_free(state);
 }
 



More information about the commits mailing list