[xiph-commits] r9076 - in trunk/speex: . include/speex libspeex

jm at motherfish-iii.xiph.org jm at motherfish-iii.xiph.org
Mon Mar 14 21:18:12 PST 2005


Author: jm
Date: 2005-03-14 21:18:02 -0800 (Mon, 14 Mar 2005)
New Revision: 9076

Modified:
   trunk/speex/configure.ac
   trunk/speex/include/speex/speex_bits.h
   trunk/speex/include/speex/speex_header.h
   trunk/speex/libspeex/arch.h
   trunk/speex/libspeex/bits.c
   trunk/speex/libspeex/cb_search.c
   trunk/speex/libspeex/filters.c
   trunk/speex/libspeex/filters.h
   trunk/speex/libspeex/fixed_arm4.h
   trunk/speex/libspeex/fixed_arm5e.h
   trunk/speex/libspeex/fixed_debug.h
   trunk/speex/libspeex/fixed_generic.h
   trunk/speex/libspeex/jitter.c
   trunk/speex/libspeex/lpc.c
   trunk/speex/libspeex/lsp.c
   trunk/speex/libspeex/ltp.c
   trunk/speex/libspeex/misc.c
   trunk/speex/libspeex/misc.h
   trunk/speex/libspeex/modes.c
   trunk/speex/libspeex/nb_celp.c
   trunk/speex/libspeex/quant_lsp.c
   trunk/speex/libspeex/sb_celp.c
   trunk/speex/libspeex/speex.c
   trunk/speex/libspeex/speex_callbacks.c
   trunk/speex/libspeex/speex_header.c
   trunk/speex/libspeex/testenc.c
Log:
Merged a modified version of Jamey Hicks' C55 patch, fixed a
long-standing fixed-point wideband overflow. Replaced some 
"+" and "-" with ADD() and SUB().


Modified: trunk/speex/configure.ac
===================================================================
--- trunk/speex/configure.ac	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/configure.ac	2005-03-15 05:18:02 UTC (rev 9076)
@@ -59,6 +59,11 @@
 AC_DEFINE_UNQUOTED(SPEEX_MICRO_VERSION, ${SPEEX_MICRO_VERSION}, [Version micro])
 AC_DEFINE_UNQUOTED(SPEEX_EXTRA_VERSION, "${SPEEX_EXTRA_VERSION}", [Version extra])
 
+AC_ARG_ENABLE(wideband, [  --disable-wideband       disable wideband codec],
+[if test "$enableval" = no; then
+  AC_DEFINE([DISABLE_WIDEBAND], , [Disable wideband codec])
+fi])
+
 AC_ARG_ENABLE(valgrind, [  --enable-valgrind       enable valgrind extra checks],
 [if test "$enableval" = yes; then
   AC_DEFINE([ENABLE_VALGRIND], , [Enable valgrind extra checks])
@@ -95,6 +100,11 @@
   AC_DEFINE([EPIC_48K], , [Enable support for Epic 4.8 kbps mode])
 fi])
 
+AC_ARG_ENABLE(ti-c55x, [  --enable-ti-c55x         enable support for TI C55X DSP],
+[if test "$enableval" = yes; then
+  AC_DEFINE([TI_C55X], , [Enable support for TI C55X DSP])
+fi])
+
 dnl Output the makefiles and version.h.
 
 AC_OUTPUT([Makefile libspeex/Makefile src/Makefile doc/Makefile Speex.spec

Modified: trunk/speex/include/speex/speex_bits.h
===================================================================
--- trunk/speex/include/speex/speex_bits.h	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/include/speex/speex_bits.h	2005-03-15 05:18:02 UTC (rev 9076)
@@ -42,11 +42,11 @@
 
 /** Bit-packing data structure representing (part of) a bit-stream. */
 typedef struct SpeexBits {
-   char *bytes;   /**< "raw" data */
+   char *chars;   /**< "raw" data */
    int   nbBits;  /**< Total number of bits stored in the stream*/
-   int   bytePtr; /**< Position of the byte "cursor" */
-   int   bitPtr;  /**< Position of the bit "cursor" within the current byte */
-   int   owner;   /**< Does the struct "own" the "raw" buffer (member "bytes") */
+   int   charPtr; /**< Position of the byte "cursor" */
+   int   bitPtr;  /**< Position of the bit "cursor" within the current char */
+   int   owner;   /**< Does the struct "own" the "raw" buffer (member "chars") */
    int   overflow;/**< Set to one if we try to read past the valid data */
    int   buf_size;/**< Allocated size for buffer */
    int   reserved1; /**< Reserved for future use */

Modified: trunk/speex/include/speex/speex_header.h
===================================================================
--- trunk/speex/include/speex/speex_header.h	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/include/speex/speex_header.h	2005-03-15 05:18:02 UTC (rev 9076)
@@ -43,26 +43,30 @@
 
 struct SpeexMode;
 
+typedef   signed long spx_int32_t;
+
+#define SPEEX_HEADER_STRING_LENGTH 8
+
 /** Maximum number of characters for encoding the Speex version number in the header */
 #define SPEEX_HEADER_VERSION_LENGTH 20
 
 /** Speex header info for file-based formats */
 typedef struct SpeexHeader {
-   char speex_string[8];       /**< Identifies a Speex bit-stream, always set to "Speex   " */
-   char speex_version[SPEEX_HEADER_VERSION_LENGTH]; /**< Speex version */
-   int speex_version_id;       /**< Version for Speex (for checking compatibility) */
-   int header_size;            /**< Total size of the header ( sizeof(SpeexHeader) ) */
-   int rate;                   /**< Sampling rate used */
-   int mode;                   /**< Mode used (0 for narrowband, 1 for wideband) */
-   int mode_bitstream_version; /**< Version ID of the bit-stream */
-   int nb_channels;            /**< Number of channels encoded */
-   int bitrate;                /**< Bit-rate used */
-   int frame_size;             /**< Size of frames */
-   int vbr;                    /**< 1 for a VBR encoding, 0 otherwise */
-   int frames_per_packet;      /**< Number of frames stored per Ogg packet */
-   int extra_headers;          /**< Number of additional headers after the comments */
-   int reserved1;              /**< Reserved for future use, must be zero */
-   int reserved2;              /**< Reserved for future use, must be zero */
+   char speex_string[SPEEX_HEADER_STRING_LENGTH];   /**< Identifies a Speex bit-stream, always set to "Speex   " */
+   char speex_version[SPEEX_HEADER_VERSION_LENGTH]; /**< Speex version */ 
+   spx_int32_t speex_version_id;       /**< Version for Speex (for checking compatibility) */
+   spx_int32_t header_size;            /**< Total size of the header ( sizeof(SpeexHeader) ) */
+   spx_int32_t rate;                   /**< Sampling rate used */
+   spx_int32_t mode;                   /**< Mode used (0 for narrowband, 1 for wideband) */
+   spx_int32_t mode_bitstream_version; /**< Version ID of the bit-stream */
+   spx_int32_t nb_channels;            /**< Number of channels encoded */
+   spx_int32_t bitrate;                /**< Bit-rate used */
+   spx_int32_t frame_size;             /**< Size of frames */
+   spx_int32_t vbr;                    /**< 1 for a VBR encoding, 0 otherwise */
+   spx_int32_t frames_per_packet;      /**< Number of frames stored per Ogg packet */
+   spx_int32_t extra_headers;          /**< Number of additional headers after the comments */
+   spx_int32_t reserved1;              /**< Reserved for future use, must be zero */
+   spx_int32_t reserved2;              /**< Reserved for future use, must be zero */
 } SpeexHeader;
 
 /** Initializes a SpeexHeader using basic information */

Modified: trunk/speex/libspeex/arch.h
===================================================================
--- trunk/speex/libspeex/arch.h	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/arch.h	2005-03-15 05:18:02 UTC (rev 9076)
@@ -37,6 +37,10 @@
 
 #define ABS(x) ((x) < 0 ? (-(x)) : (x))
 
+/* FIXME: Should provide better detection */
+/*typedef   signed long spx_int32_t;*/
+typedef unsigned long spx_uint32_t;
+
 #ifdef FIXED_POINT
 
 typedef signed short spx_word16_t;
@@ -109,8 +113,8 @@
 #define SUB32(a,b) ((a)-(b))
 #define ADD64(a,b) ((a)+(b))
 #define MULT16_16_16(a,b)     ((a)*(b))
-#define MULT16_16(a,b)     ((a)*(b))
-#define MAC16_16(c,a,b)     ((c)+(a)*(b))
+#define MULT16_16(a,b)     ((spx_word32_t)(a)*(spx_word32_t)(b))
+#define MAC16_16(c,a,b)     ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))
 
 #define MULT16_32_Q11(a,b)     ((a)*(b))
 #define MULT16_32_Q13(a,b)     ((a)*(b))
@@ -133,5 +137,19 @@
 #endif
 
 
+#ifdef CONFIG_TI_C55X
 
+/* 2 on TI C5x DSP */
+#define BYTES_PER_CHAR 2 
+#define BITS_PER_CHAR 16
+#define LOG2_BITS_PER_CHAR 4
+
+#else 
+
+#define BYTES_PER_CHAR 1
+#define BITS_PER_CHAR 8
+#define LOG2_BITS_PER_CHAR 3
+
 #endif
+
+#endif

Modified: trunk/speex/libspeex/bits.c
===================================================================
--- trunk/speex/libspeex/bits.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/bits.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -40,16 +40,16 @@
 #include "misc.h"
 
 /** Maximum size of the bit-stream (for fixed-size allocation) */
-#define MAX_BYTES_PER_FRAME 2000
+#define MAX_BYTES_PER_FRAME (2000/BYTES_PER_CHAR)
 
 void speex_bits_init(SpeexBits *bits)
 {
-   bits->bytes = (char*)speex_alloc(MAX_BYTES_PER_FRAME);
+   bits->chars = (char*)speex_alloc(MAX_BYTES_PER_FRAME);
    bits->buf_size = MAX_BYTES_PER_FRAME;
 
-   bits->bytes[0]=0;
+   bits->chars[0]=0;
    bits->nbBits=0;
-   bits->bytePtr=0;
+   bits->charPtr=0;
    bits->bitPtr=0;
    bits->owner=1;
    bits->overflow=0;
@@ -57,12 +57,12 @@
 
 void speex_bits_init_buffer(SpeexBits *bits, void *buff, int buf_size)
 {
-   bits->bytes = (char*)buff;
+   bits->chars = (char*)buff;
    bits->buf_size = buf_size;
 
-   bits->bytes[0]=0;
+   bits->chars[0]=0;
    bits->nbBits=0;
-   bits->bytePtr=0;
+   bits->charPtr=0;
    bits->bitPtr=0;
    bits->owner=0;
    bits->overflow=0;
@@ -71,27 +71,27 @@
 void speex_bits_destroy(SpeexBits *bits)
 {
    if (bits->owner)
-      speex_free(bits->bytes);
+      speex_free(bits->chars);
    /* Will do something once the allocation is dynamic */
 }
 
 void speex_bits_reset(SpeexBits *bits)
 {
-   bits->bytes[0]=0;
+   bits->chars[0]=0;
    bits->nbBits=0;
-   bits->bytePtr=0;
+   bits->charPtr=0;
    bits->bitPtr=0;
    bits->overflow=0;
 }
 
 void speex_bits_rewind(SpeexBits *bits)
 {
-   bits->bytePtr=0;
+   bits->charPtr=0;
    bits->bitPtr=0;
    bits->overflow=0;
 }
 
-void speex_bits_read_from(SpeexBits *bits, char *bytes, int len)
+void speex_bits_read_from(SpeexBits *bits, char *chars, int len)
 {
    int i;
    if (len > bits->buf_size)
@@ -99,11 +99,11 @@
       speex_warning_int("Packet if larger than allocated buffer: ", len);
       if (bits->owner)
       {
-         char *tmp = (char*)speex_realloc(bits->bytes, len);
+         char *tmp = (char*)speex_realloc(bits->chars, len);
          if (tmp)
          {
             bits->buf_size=len;
-            bits->bytes=tmp;
+            bits->chars=tmp;
          } else {
             len=bits->buf_size;
             speex_warning("Could not resize input buffer: truncating input");
@@ -114,9 +114,9 @@
       }
    }
    for (i=0;i<len;i++)
-      bits->bytes[i]=bytes[i];
+      bits->chars[i]=chars[i];
    bits->nbBits=len<<3;
-   bits->bytePtr=0;
+   bits->charPtr=0;
    bits->bitPtr=0;
    bits->overflow=0;
 }
@@ -124,104 +124,111 @@
 static void speex_bits_flush(SpeexBits *bits)
 {
    int i;
-   if (bits->bytePtr>0)
+   int nchars = ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR);
+   if (bits->charPtr>0)
    {
-      for (i=bits->bytePtr;i<((bits->nbBits+7)>>3);i++)
-         bits->bytes[i-bits->bytePtr]=bits->bytes[i];
+     for (i=bits->charPtr;i<nchars; i++) 
+       bits->chars[i-bits->charPtr]=bits->chars[i];
    }
-   bits->nbBits -= bits->bytePtr<<3;
-   bits->bytePtr=0;
+   bits->nbBits -= bits->charPtr<<LOG2_BITS_PER_CHAR;
+   bits->charPtr=0;
 }
 
-void speex_bits_read_whole_bytes(SpeexBits *bits, char *bytes, int len)
+void speex_bits_read_whole_bytes(SpeexBits *bits, char *chars, int nbytes)
 {
    int i,pos;
+   int nchars = nbytes/BYTES_PER_CHAR;
 
-   if (((bits->nbBits+7)>>3)+len > bits->buf_size)
+   if (((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR)+nchars > bits->buf_size)
    {
       /* Packet is larger than allocated buffer */
       if (bits->owner)
       {
-         char *tmp = (char*)speex_realloc(bits->bytes, (bits->nbBits>>3)+len+1);
+         char *tmp = (char*)speex_realloc(bits->chars, (bits->nbBits>>LOG2_BITS_PER_CHAR)+nchars+1);
          if (tmp)
          {
-            bits->buf_size=(bits->nbBits>>3)+len+1;
-            bits->bytes=tmp;
+            bits->buf_size=(bits->nbBits>>LOG2_BITS_PER_CHAR)+nchars+1;
+            bits->chars=tmp;
          } else {
-            len=bits->buf_size-(bits->nbBits>>3)-1;
+            nchars=bits->buf_size-(bits->nbBits>>LOG2_BITS_PER_CHAR)-1;
             speex_warning("Could not resize input buffer: truncating input");
          }
       } else {
          speex_warning("Do not own input buffer: truncating input");
-         len=bits->buf_size;
+         nchars=bits->buf_size;
       }
    }
 
    speex_bits_flush(bits);
-   pos=bits->nbBits>>3;
-   for (i=0;i<len;i++)
-      bits->bytes[pos+i]=bytes[i];
-   bits->nbBits+=len<<3;
+   pos=bits->nbBits>>LOG2_BITS_PER_CHAR;
+   for (i=0;i<nchars;i++)
+      bits->chars[pos+i]=chars[i];
+   bits->nbBits+=nchars<<LOG2_BITS_PER_CHAR;
 }
 
-int speex_bits_write(SpeexBits *bits, char *bytes, int max_len)
+int speex_bits_write(SpeexBits *bits, char *chars, int max_nbytes)
 {
    int i;
-   int bytePtr, bitPtr, nbBits;
+   int max_nchars = max_nbytes/BYTES_PER_CHAR;
+   int charPtr, bitPtr, nbBits;
    
    /* Insert terminator, but save the data so we can put it back after */
    bitPtr=bits->bitPtr;
-   bytePtr=bits->bytePtr;
+   charPtr=bits->charPtr;
    nbBits=bits->nbBits;
    speex_bits_insert_terminator(bits);
    bits->bitPtr=bitPtr;
-   bits->bytePtr=bytePtr;
+   bits->charPtr=charPtr;
    bits->nbBits=nbBits;
 
-   if (max_len > ((bits->nbBits+7)>>3))
-      max_len = ((bits->nbBits+7)>>3);
-   for (i=0;i<max_len;i++)
-      bytes[i]=bits->bytes[i];
-   return max_len;
+   if (max_nchars > ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR))
+      max_nchars = ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR);
+#if BYTES_PER_CHAR==1
+#define HTOLS(A) (A)
+#else
+#define HTOLS(A) ((((A) >> 8)&0xff)|(((A) & 0xff)<<8))
+#endif
+   for (i=0;i<max_nchars;i++)
+      chars[i]=HTOLS(bits->chars[i]);
+   return max_nchars*BYTES_PER_CHAR;
 }
 
-int speex_bits_write_whole_bytes(SpeexBits *bits, char *bytes, int max_len)
+int speex_bits_write_whole_bytes(SpeexBits *bits, char *chars, int max_nbytes)
 {
+   int max_nchars = max_nbytes/BYTES_PER_CHAR;
    int i;
-   if (max_len > ((bits->nbBits)>>3))
-      max_len = ((bits->nbBits)>>3);
-   for (i=0;i<max_len;i++)
-      bytes[i]=bits->bytes[i];
+   if (max_nchars > ((bits->nbBits)>>LOG2_BITS_PER_CHAR))
+      max_nchars = ((bits->nbBits)>>LOG2_BITS_PER_CHAR);
+   for (i=0;i<max_nchars;i++)
+      chars[i]=bits->chars[i];
    
    if (bits->bitPtr>0)
-      bits->bytes[0]=bits->bytes[max_len];
+      bits->chars[0]=bits->chars[max_nchars];
    else
-      bits->bytes[0]=0;
-   for (i=1;i<((bits->nbBits)>>3)+1;i++)
-      bits->bytes[i]=0;
-   bits->bytePtr=0;
-   bits->nbBits &= 7;
-   return max_len;
+      bits->chars[0]=0;
+   for (i=1;i<((bits->nbBits)>>LOG2_BITS_PER_CHAR)+1;i++)
+      bits->chars[i]=0;
+   bits->charPtr=0;
+   bits->nbBits &= (BITS_PER_CHAR-1);
+   return max_nchars*BYTES_PER_CHAR;
 }
 
-
 void speex_bits_pack(SpeexBits *bits, int data, int nbBits)
 {
-   int i;
    unsigned int d=data;
 
-   if (bits->bytePtr+((nbBits+bits->bitPtr)>>3) >= bits->buf_size)
+   if (bits->charPtr+((nbBits+bits->bitPtr)>>LOG2_BITS_PER_CHAR) >= bits->buf_size)
    {
       speex_warning("Buffer too small to pack bits");
       if (bits->owner)
       {
-         char *tmp = (char*)speex_realloc(bits->bytes, ((bits->buf_size+5)*3)>>1);
+	int new_nchars = ((bits->buf_size+5)*3)>>1;
+         char *tmp = (char*)speex_realloc(bits->chars, new_nchars);
          if (tmp)
          {
-            for (i=bits->buf_size;i<(((bits->buf_size+5)*3)>>1);i++)
-               tmp[i]=0;
-            bits->buf_size=((bits->buf_size+5)*3)>>1;
-            bits->bytes=tmp;
+	    speex_memset_bytes(tmp, 0, new_nchars);
+            bits->buf_size=new_nchars;
+            bits->chars=tmp;
          } else {
             speex_warning("Could not resize input buffer: not packing");
             return;
@@ -236,14 +243,14 @@
    {
       int bit;
       bit = (d>>(nbBits-1))&1;
-      bits->bytes[bits->bytePtr] |= bit<<(7-bits->bitPtr);
+      bits->chars[bits->charPtr] |= bit<<(7-bits->bitPtr);
       bits->bitPtr++;
 
       if (bits->bitPtr==8)
       {
          bits->bitPtr=0;
-         bits->bytePtr++;
-         bits->bytes[bits->bytePtr] = 0;
+         bits->charPtr++;
+         bits->chars[bits->charPtr] = 0;
       }
       bits->nbBits++;
       nbBits--;
@@ -264,19 +271,19 @@
 unsigned int speex_bits_unpack_unsigned(SpeexBits *bits, int nbBits)
 {
    unsigned int d=0;
-   if ((bits->bytePtr<<3)+bits->bitPtr+nbBits>bits->nbBits)
+   if ((bits->charPtr<<LOG2_BITS_PER_CHAR)+bits->bitPtr+nbBits>bits->nbBits)
       bits->overflow=1;
    if (bits->overflow)
       return 0;
    while(nbBits)
    {
       d<<=1;
-      d |= (bits->bytes[bits->bytePtr]>>(7-bits->bitPtr))&1;
+      d |= (bits->chars[bits->charPtr]>>(BITS_PER_CHAR-1 - bits->bitPtr))&1;
       bits->bitPtr++;
-      if (bits->bitPtr==8)
+      if (bits->bitPtr==BITS_PER_CHAR)
       {
          bits->bitPtr=0;
-         bits->bytePtr++;
+         bits->charPtr++;
       }
       nbBits--;
    }
@@ -286,26 +293,26 @@
 unsigned int speex_bits_peek_unsigned(SpeexBits *bits, int nbBits)
 {
    unsigned int d=0;
-   int bitPtr, bytePtr;
-   char *bytes;
+   int bitPtr, charPtr;
+   char *chars;
 
-   if ((bits->bytePtr<<3)+bits->bitPtr+nbBits>bits->nbBits)
+   if ((bits->charPtr<<LOG2_BITS_PER_CHAR)+bits->bitPtr+nbBits>bits->nbBits)
      bits->overflow=1;
    if (bits->overflow)
       return 0;
 
    bitPtr=bits->bitPtr;
-   bytePtr=bits->bytePtr;
-   bytes = bits->bytes;
+   charPtr=bits->charPtr;
+   chars = bits->chars;
    while(nbBits)
    {
       d<<=1;
-      d |= (bytes[bytePtr]>>(7-bitPtr))&1;
+      d |= (chars[charPtr]>>(BITS_PER_CHAR-1 - bitPtr))&1;
       bitPtr++;
-      if (bitPtr==8)
+      if (bitPtr==BITS_PER_CHAR)
       {
          bitPtr=0;
-         bytePtr++;
+         charPtr++;
       }
       nbBits--;
    }
@@ -314,21 +321,21 @@
 
 int speex_bits_peek(SpeexBits *bits)
 {
-   if ((bits->bytePtr<<3)+bits->bitPtr+1>bits->nbBits)
+   if ((bits->charPtr<<LOG2_BITS_PER_CHAR)+bits->bitPtr+1>bits->nbBits)
       bits->overflow=1;
    if (bits->overflow)
       return 0;
-   return (bits->bytes[bits->bytePtr]>>(7-bits->bitPtr))&1;
+   return (bits->chars[bits->charPtr]>>(BITS_PER_CHAR-1 - bits->bitPtr))&1;
 }
 
 void speex_bits_advance(SpeexBits *bits, int n)
 {
-    if (((bits->bytePtr<<3)+bits->bitPtr+n>bits->nbBits) || bits->overflow){
+    if (((bits->charPtr<<LOG2_BITS_PER_CHAR)+bits->bitPtr+n>bits->nbBits) || bits->overflow){
       bits->overflow=1;
       return;
     }
-   bits->bytePtr += (bits->bitPtr+n) >> 3; /*divide by 8*/
-   bits->bitPtr = (bits->bitPtr+n) & 7;    /* modulo by 8*/
+   bits->charPtr += (bits->bitPtr+n) >> LOG2_BITS_PER_CHAR; /* divide by BITS_PER_CHAR */
+   bits->bitPtr = (bits->bitPtr+n) & (BITS_PER_CHAR-1);       /* modulo by BITS_PER_CHAR */
 }
 
 int speex_bits_remaining(SpeexBits *bits)
@@ -336,18 +343,18 @@
    if (bits->overflow)
       return -1;
    else
-      return bits->nbBits-((bits->bytePtr<<3)+bits->bitPtr);
+      return bits->nbBits-((bits->charPtr<<LOG2_BITS_PER_CHAR)+bits->bitPtr);
 }
 
 int speex_bits_nbytes(SpeexBits *bits)
 {
-   return ((bits->nbBits+7)>>3);
+   return ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR);
 }
 
 void speex_bits_insert_terminator(SpeexBits *bits)
 {
-   if (bits->bitPtr<7)
+   if (bits->bitPtr<BITS_PER_CHAR-1)
       speex_bits_pack(bits, 0, 1);
-   while (bits->bitPtr<7)
+   while (bits->bitPtr<BITS_PER_CHAR-1)
       speex_bits_pack(bits, 1, 1);
 }

Modified: trunk/speex/libspeex/cb_search.c
===================================================================
--- trunk/speex/libspeex/cb_search.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/cb_search.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -168,10 +168,10 @@
          res = resp+rind*subvect_size;
          if (sign>0)
             for (m=0;m<subvect_size;m++)
-               t[subvect_size*i+m] -= res[m];
+               t[subvect_size*i+m] = SUB16(t[subvect_size*i+m], res[m]);
          else
             for (m=0;m<subvect_size;m++)
-               t[subvect_size*i+m] += res[m];
+               t[subvect_size*i+m] = ADD16(t[subvect_size*i+m], res[m]);
 
 #ifdef FIXED_POINT
          if (sign)
@@ -217,7 +217,7 @@
    /* Update excitation */
    /* FIXME: We could update the excitation directly above */
    for (j=0;j<nsf;j++)
-      exc[j]+=e[j];
+      exc[j]=ADD32(exc[j],e[j]);
    
    /* Update target: only update target if necessary */
    if (update_target)
@@ -226,7 +226,7 @@
       ALLOC(r2, nsf, spx_sig_t);
       syn_percep_zero(e, ak, awk1, awk2, r2, nsf,p, stack);
       for (j=0;j<nsf;j++)
-         target[j]-=r2[j];
+         target[j]=SUB32(target[j],r2[j]);
    }
 }
 
@@ -393,10 +393,10 @@
                res = resp+rind*subvect_size;
                if (sign>0)
                   for (m=0;m<subvect_size;m++)
-                     t[subvect_size*i+m] -= res[m];
+                     t[subvect_size*i+m] = SUB16(t[subvect_size*i+m], res[m]);
                else
                   for (m=0;m<subvect_size;m++)
-                     t[subvect_size*i+m] += res[m];
+                     t[subvect_size*i+m] = ADD16(t[subvect_size*i+m], res[m]);
             }
             
             /*compute error (distance)*/
@@ -512,14 +512,14 @@
    }   
    /* Update excitation */
    for (j=0;j<nsf;j++)
-      exc[j]+=e[j];
+      exc[j]=ADD32(exc[j],e[j]);
    
    /* Update target: only update target if necessary */
    if (update_target)
    {
       syn_percep_zero(e, ak, awk1, awk2, r2, nsf,p, stack);
       for (j=0;j<nsf;j++)
-         target[j]-=r2[j];
+         target[j]=SUB32(target[j],r2[j]);
    }
 }
 

Modified: trunk/speex/libspeex/filters.c
===================================================================
--- trunk/speex/libspeex/filters.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/filters.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -148,14 +148,14 @@
       spx_word32_t sum2=0;
       spx_word16_t tmp;
       tmp = SHR(x[i],sig_shift);
-      sum2 += MULT16_16(tmp,tmp);
+      sum2 = MAC16_16(sum2,tmp,tmp);
       tmp = SHR(x[i+1],sig_shift);
-      sum2 += MULT16_16(tmp,tmp);
+      sum2 = MAC16_16(sum2,tmp,tmp);
       tmp = SHR(x[i+2],sig_shift);
-      sum2 += MULT16_16(tmp,tmp);
+      sum2 = MAC16_16(sum2,tmp,tmp);
       tmp = SHR(x[i+3],sig_shift);
-      sum2 += MULT16_16(tmp,tmp);
-      sum += SHR(sum2,6);
+      sum2 = MAC16_16(sum2,tmp,tmp);
+      sum = ADD32(sum,SHR(sum2,6));
    }
    
    return SHR(SHL((spx_word32_t)spx_sqrt(1+DIV32(sum,len)),(sig_shift+3)),SIG_SHIFT);
@@ -166,7 +166,7 @@
 #else
 
 
-int normalize16(const spx_sig_t *x, spx_word16_t *y, int max_scale, int len)
+int normalize16(const spx_sig_t *x, spx_word16_t *y, spx_sig_t max_scale, int len)
 {
    int i;
    spx_sig_t max_val=1;
@@ -201,11 +201,9 @@
 
    for (i=0;i<N;i++)
    {
-      int xh,xl,yh,yl;
       xi=SATURATE(x[i],805306368);
       yi = SATURATE(ADD32(xi, SHL(mem[0],2)),805306368);
       nyi = -yi;
-      xh = xi>>15; xl=xi&0x00007fff; yh = yi>>15; yl=yi&0x00007fff; 
       for (j=0;j<ord-1;j++)
       {
          mem[j] = MAC16_32_Q15(MAC16_32_Q15(mem[j+1], num[j+1],xi), den[j+1],nyi);
@@ -222,11 +220,9 @@
 
    for (i=0;i<N;i++)
    {
-      int yh,yl;
       xi=SATURATE(x[i],805306368);
       yi = SATURATE(xi + (mem[0]<<2),805306368);
       nyi = -yi;
-      yh = yi>>15; yl=yi&0x00007fff; 
       for (j=0;j<ord-1;j++)
       {
          mem[j] = MAC16_32_Q15(mem[j+1],den[j+1],nyi);
@@ -247,10 +243,8 @@
 
    for (i=0;i<N;i++)
    {
-      int xh,xl;
       xi=SATURATE(x[i],805306368);
       yi = xi + (mem[0]<<2);
-      xh = xi>>15; xl=xi&0x00007fff;
       for (j=0;j<ord-1;j++)
       {
          mem[j] = MAC16_32_Q15(mem[j+1], num[j+1],xi);
@@ -258,7 +252,6 @@
       mem[ord-1] = MULT16_32_Q15(num[ord],xi);
       y[i] = SATURATE(yi,805306368);
    }
-
 }
 
 #else
@@ -384,11 +377,11 @@
       y2[k]=0;
       for (j=0;j<M2;j++)
       {
-         y1[k]+=SHR(MULT16_16(a[j],ADD16(x[i+j],x2[i-j])),1);
-         y2[k]-=SHR(MULT16_16(a[j],SUB16(x[i+j],x2[i-j])),1);
+         y1[k]=ADD32(y1[k],SHR(MULT16_16(a[j],ADD16(x[i+j],x2[i-j])),1));
+         y2[k]=SUB32(y2[k],SHR(MULT16_16(a[j],SUB16(x[i+j],x2[i-j])),1));
          j++;
-         y1[k]+=SHR(MULT16_16(a[j],ADD16(x[i+j],x2[i-j])),1);
-         y2[k]+=SHR(MULT16_16(a[j],SUB16(x[i+j],x2[i-j])),1);
+         y1[k]=ADD32(y1[k],SHR(MULT16_16(a[j],ADD16(x[i+j],x2[i-j])),1));
+         y2[k]=ADD32(y2[k],SHR(MULT16_16(a[j],SUB16(x[i+j],x2[i-j])),1));
       }
    }
    for (i=0;i<M-1;i++)
@@ -427,19 +420,19 @@
          a1 = a[j+1];
          x1 = xx[N-2+j-i];
 
-         y0 += SHR(MULT16_16(a0, x1),1);
-         y1 += SHR(MULT16_16(a1, x1),1);
-         y2 += SHR(MULT16_16(a0, x0),1);
-         y3 += SHR(MULT16_16(a1, x0),1);
+         y0 = ADD32(y0,SHR(MULT16_16(a0, x1),1));
+         y1 = ADD32(y1,SHR(MULT16_16(a1, x1),1));
+         y2 = ADD32(y2,SHR(MULT16_16(a0, x0),1));
+         y3 = ADD32(y3,SHR(MULT16_16(a1, x0),1));
 
          a0 = a[j+2];
          a1 = a[j+3];
          x0 = xx[N+j-i];
 
-         y0 += SHR(MULT16_16(a0, x0),1);
-         y1 += SHR(MULT16_16(a1, x0),1);
-         y2 += SHR(MULT16_16(a0, x1),1);
-         y3 += SHR(MULT16_16(a1, x1),1);
+         y0 = ADD32(y0,SHR(MULT16_16(a0, x0),1));
+         y1 = ADD32(y1,SHR(MULT16_16(a1, x0),1));
+         y2 = ADD32(y2,SHR(MULT16_16(a0, x1),1));
+         y3 = ADD32(y3,SHR(MULT16_16(a1, x1),1));
       }
       y[i] = y0;
       y[i+1] = y1;
@@ -516,7 +509,7 @@
    {
       spx_word32_t exc1, exc2;
 
-      fact += step;
+      fact = ADD16(fact,step);
       
       exc1 = SHL(MULT16_32_Q15(SHL(pitch_gain[0],7),exc[i-pitch+1]) +
                  MULT16_32_Q15(SHL(pitch_gain[1],7),exc[i-pitch]) +

Modified: trunk/speex/libspeex/filters.h
===================================================================
--- trunk/speex/libspeex/filters.h	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/filters.h	2005-03-15 05:18:02 UTC (rev 9076)
@@ -41,7 +41,7 @@
 
 #ifdef FIXED_POINT
 
-int normalize16(const spx_sig_t *x, spx_word16_t *y, int max_scale, int len);
+int normalize16(const spx_sig_t *x, spx_word16_t *y, spx_sig_t max_scale, int len);
 
 #endif
 

Modified: trunk/speex/libspeex/fixed_arm4.h
===================================================================
--- trunk/speex/libspeex/fixed_arm4.h	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/fixed_arm4.h	2005-03-15 05:18:02 UTC (rev 9076)
@@ -92,6 +92,7 @@
 
 
 #define MAC16_16_Q11(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),11)))
+#define MAC16_16_Q13(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),13)))
 
 #define MULT16_16_Q11(a,b) (SHR(MULT16_16((a),(b)),11))
 #define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13))

Modified: trunk/speex/libspeex/fixed_arm5e.h
===================================================================
--- trunk/speex/libspeex/fixed_arm5e.h	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/fixed_arm5e.h	2005-03-15 05:18:02 UTC (rev 9076)
@@ -102,6 +102,7 @@
 }
 
 #define MAC16_16_Q11(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),11)))
+#define MAC16_16_Q13(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),13)))
 
 #define MULT16_16_Q11(a,b) (SHR(MULT16_16((a),(b)),11))
 #define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13))

Modified: trunk/speex/libspeex/fixed_debug.h
===================================================================
--- trunk/speex/libspeex/fixed_debug.h	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/fixed_debug.h	2005-03-15 05:18:02 UTC (rev 9076)
@@ -137,6 +137,7 @@
 
 #define MAC16_16(c,a,b)     (ADD32((c),MULT16_16((a),(b))))
 #define MAC16_16_Q11(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),11)))
+#define MAC16_16_Q13(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),13)))
 
 #define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12))
 #define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))

Modified: trunk/speex/libspeex/fixed_generic.h
===================================================================
--- trunk/speex/libspeex/fixed_generic.h	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/fixed_generic.h	2005-03-15 05:18:02 UTC (rev 9076)
@@ -36,27 +36,30 @@
 #define FIXED_GENERIC_H
 
 #define SHR(a,shift) ((a) >> (shift))
-#define SHL(a,shift) ((a) << (shift))
+#define SHL(a,shift) ((spx_word32_t)(a) << (shift))
 
-#define SATURATE(x,a) ((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))
+#define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
 
-#define ADD16(a,b) ((short)((short)(a)+(short)(b)))
-#define SUB16(a,b) ((a)-(b))
-#define ADD32(a,b) ((a)+(b))
-#define SUB32(a,b) ((a)-(b))
-#define ADD64(a,b) ((a)+(b))
+static inline spx_word32_t slow_saturate(spx_word32_t x, spx_word16_t a)
+{
+  return (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)));
+}
 
+#define ADD16(a,b) ((spx_word16_t)((spx_word16_t)(a)+(spx_word16_t)(b)))
+#define SUB16(a,b) ((spx_word16_t)(a)-(spx_word16_t)(b))
+#define ADD32(a,b) ((spx_word32_t)(a)+(spx_word32_t)(b))
+#define SUB32(a,b) ((spx_word32_t)(a)-(spx_word32_t)(b))
+#define ADD64(a,b) ((spx_word64_t)(a)+(spx_word64_t)(b))
+
 #define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift))
 
 /* result fits in 16 bits */
-#define MULT16_16_16(a,b)     ((((short)(a))*((short)(b))))
+#define MULT16_16_16(a,b)     ((((spx_word16_t)(a))*((spx_word16_t)(b))))
 
-#define MULT16_16(a,b)     (((short)(a))*((short)(b)))
+/* (spx_word32_t)(spx_word16_t) gives TI compiler a hint that it's 16x16->32 multiply */
+#define MULT16_16(a,b)     (((spx_word32_t)(spx_word16_t)(a))*((spx_word32_t)(spx_word16_t)(b)))
 
-
-
-
-#define MAC16_16(c,a,b)     (ADD32((c),MULT16_16((a),(b))))
+#define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b))))
 #define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12))
 #define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))
 #define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14))
@@ -69,6 +72,7 @@
 
 
 #define MAC16_16_Q11(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),11)))
+#define MAC16_16_Q13(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),13)))
 
 #define MULT16_16_Q11(a,b) (SHR(MULT16_16((a),(b)),11))
 #define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13))
@@ -81,11 +85,7 @@
 
 #define MUL_16_32_R15(a,bh,bl) ADD32(MULT16_16((a),(bh)), SHR(MULT16_16((a),(bl)),15))
 
+#define DIV32_16(a,b) ((spx_word16_t)(((spx_word32_t)(a))/((spx_word16_t)(b))))
+#define DIV32(a,b) (((spx_word32_t)(a))/((spx_word32_t)(b)))
 
-
-#define DIV32_16(a,b) ((short)(((signed int)(a))/((short)(b))))
-#define DIV32(a,b) (((signed int)(a))/((signed int)(b)))
-
-
-
 #endif

Modified: trunk/speex/libspeex/jitter.c
===================================================================
--- trunk/speex/libspeex/jitter.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/jitter.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -40,6 +40,7 @@
 #define NULL 0
 #endif
 
+#include "misc.h"
 #include <speex/speex.h>
 #include <speex/speex_bits.h>
 #include <speex/speex_jitter.h>
@@ -139,7 +140,7 @@
    /* Copy packet in buffer */
    if (len>SPEEX_JITTER_MAX_PACKET_SIZE)
       len=SPEEX_JITTER_MAX_PACKET_SIZE;
-   for (j=0;j<len;j++)
+   for (j=0;j<len/BYTES_PER_CHAR;j++)
       jitter->buf[i][j]=packet[j];
    jitter->timestamp[i]=timestamp;
    jitter->len[i]=len;

Modified: trunk/speex/libspeex/lpc.c
===================================================================
--- trunk/speex/libspeex/lpc.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/lpc.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -90,9 +90,9 @@
       /* Sum up this iteration's reflection coefficient */
       spx_word32_t rr = -SHL(ac[i + 1],13);
       for (j = 0; j < i; j++) 
-         rr -= MULT16_16(lpc[j],ac[i - j]);
+         rr = SUB32(rr,MULT16_16(lpc[j],ac[i - j]));
 #ifdef FIXED_POINT
-      r = DIV32_16(rr,error+16);
+      r = DIV32_16(rr,ADD16(error,16));
 #else
       r = rr/(error+.003*ac[0]);
 #endif
@@ -101,13 +101,13 @@
       for (j = 0; j < i>>1; j++) 
       {
          spx_word16_t tmp  = lpc[j];
-         lpc[j]     += MULT16_16_Q13(r,lpc[i-1-j]);
-         lpc[i-1-j] += MULT16_16_Q13(r,tmp);
+         lpc[j]     = MAC16_16_Q13(lpc[j],r,lpc[i-1-j]);
+         lpc[i-1-j] = MAC16_16_Q13(lpc[i-1-j],r,tmp);
       }
       if (i & 1) 
-         lpc[j] += MULT16_16_Q13(lpc[j],r);
+         lpc[j] = MAC16_16_Q13(lpc[j],lpc[j],r);
 
-      error -= MULT16_16_Q13(r,MULT16_16_Q13(error,r));
+      error = SUB16(error,MULT16_16_Q13(r,MULT16_16_Q13(error,r)));
    }
    return error;
 }
@@ -135,8 +135,8 @@
    int shift, ac_shift;
    
    for (j=0;j<n;j++)
-      ac0 += SHR(MULT16_16(x[j],x[j]),8);
-   ac0 += n;
+      ac0 = ADD32(ac0,SHR(MULT16_16(x[j],x[j]),8));
+   ac0 = ADD32(ac0,n);
    shift = 8;
    while (shift && ac0<0x40000000)
    {
@@ -156,10 +156,10 @@
       d=0;
       for (j=i;j<n;j++)
       {
-         d += MULT16_16(x[j],x[j-i]) >> shift;
+         d = ADD32(d,SHR(MULT16_16(x[j],x[j-i]), shift));
       }
       
-      ac[i] = d >> ac_shift;
+      ac[i] = SHR(d, ac_shift);
    }
 }
 

Modified: trunk/speex/libspeex/lsp.c
===================================================================
--- trunk/speex/libspeex/lsp.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/lsp.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -6,7 +6,8 @@
 	AUTHOR......: David Rowe
 	DATE CREATED: 24/2/93
 
-Modified by Jean-Marc Valin
+Heavily modified by Jean-Marc Valin (fixed-point, optimizations, 
+                                     additional functions, ...)
 
    This file contains functions for converting Linear Prediction
    Coefficients (LPC) to Line Spectral Pair (LSP) and back. Note that the
@@ -98,10 +99,10 @@
 #define C2 -0.49558072
 #define C3 0.03679168*/
 
-#define C1 0.9999932946
-#define C2 -0.4999124376
-#define C3 0.0414877472
-#define C4 -0.0012712095
+#define C1 0.9999932946f
+#define C2 -0.4999124376f
+#define C3 0.0414877472f
+#define C4 -0.0012712095f
 
 
 #define SPX_PI_2 1.5707963268
@@ -465,10 +466,11 @@
 	xout1 = xin1 + *(n4+1);
 	xout2 = xin2 - *(n4+2);
         /* FIXME: perhaps apply bandwidth expansion in case of overflow? */
-        if (xout1 + xout2>256*32766)
+        /*FIXME: Is it OK to have a long constant? */
+        if (xout1 + xout2>SHL(32766,8))
            ak[j] = 32767;
-        else if (xout1 + xout2 < -256*32767)
-           ak[j] = -32768;
+        else if (xout1 + xout2 < -SHL(32766,8))
+           ak[j] = -32767;
         else
            ak[j] = PSHR(ADD32(xout1,xout2),8);
 	*(n4+1) = xin1;

Modified: trunk/speex/libspeex/ltp.c
===================================================================
--- trunk/speex/libspeex/ltp.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/ltp.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -272,19 +272,19 @@
 
 /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
 static spx_word64_t pitch_gain_search_3tap(
-spx_sig_t target[],                 /* Target vector */
-spx_coef_t ak[],                     /* LPCs for this subframe */
-spx_coef_t awk1[],                   /* Weighted LPCs #1 for this subframe */
-spx_coef_t awk2[],                   /* Weighted LPCs #2 for this subframe */
-spx_sig_t exc[],                    /* Excitation */
+const spx_sig_t target[],       /* Target vector */
+const spx_coef_t ak[],          /* LPCs for this subframe */
+const spx_coef_t awk1[],        /* Weighted LPCs #1 for this subframe */
+const spx_coef_t awk2[],        /* Weighted LPCs #2 for this subframe */
+spx_sig_t exc[],                /* Excitation */
 const void *par,
 int   pitch,                    /* Pitch value */
 int   p,                        /* Number of LPC coeffs */
 int   nsf,                      /* Number of samples in subframe */
 SpeexBits *bits,
 char *stack,
-spx_sig_t *exc2,
-spx_sig_t *r,
+const spx_sig_t *exc2,
+const spx_sig_t *r,
 spx_sig_t *new_target,
 int  *cdbk_index,
 int cdbk_offset
@@ -487,8 +487,8 @@
    {
       spx_word16_t perr2;
       spx_sig_t tmp = SHL((MULT16_32_Q15(SHL(gain[0],7),x[2][i])+MULT16_32_Q15(SHL(gain[1],7),x[1][i])+MULT16_32_Q15(SHL(gain[2],7),x[0][i])),2);
-      spx_sig_t perr=target[i]-tmp;
-      new_target[i] = target[i] - tmp;
+      spx_sig_t perr=SUB32(target[i],tmp);
+      new_target[i] = SUB32(target[i], tmp);
       perr2 = PSHR(perr,15);
       err = ADD64(err,MULT16_16(perr2,perr2));
       

Modified: trunk/speex/libspeex/misc.c
===================================================================
--- trunk/speex/libspeex/misc.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/misc.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -55,9 +55,9 @@
 #endif
 
 
-unsigned int be_int(unsigned int i)
+spx_uint32_t be_int(spx_uint32_t i)
 {
-   unsigned int ret=i;
+   spx_uint32_t ret=i;
 #ifndef WORDS_BIGENDIAN
    ret =  i>>24;
    ret += (i>>8)&0x0000ff00;
@@ -67,9 +67,9 @@
    return ret;
 }
 
-unsigned int le_int(unsigned int i)
+spx_uint32_t le_int(spx_uint32_t i)
 {
-   unsigned int ret=i;
+   spx_uint32_t ret=i;
 #ifdef WORDS_BIGENDIAN
    ret =  i>>24;
    ret += (i>>8)&0x0000ff00;
@@ -99,6 +99,50 @@
    return ret;
 }
 
+#if BYTES_PER_CHAR == 2
+void speex_memcpy_bytes(char *dst, char *src, int nbytes)
+{
+  int i;
+  int nchars = nbytes/BYTES_PER_CHAR;
+  for (i=0;i<nchars;i++)
+    dst[i]=src[i];
+  if (nbytes & 1) {
+    /* copy in the last byte */
+    int last_i = nchars;
+    char last_dst_char = dst[last_i];
+    char last_src_char = src[last_i];
+    last_dst_char &= 0xff00;
+    last_dst_char |= (last_src_char & 0x00ff);
+    dst[last_i] = last_dst_char;
+  }
+}
+void speex_memset_bytes(char *dst, char c, int nbytes)
+{
+  int i;
+  short cc = ((c << 8) | c);
+  int nchars = nbytes/BYTES_PER_CHAR;
+  for (i=0;i<nchars;i++)
+    dst[i]=cc;
+  if (nbytes & 1) {
+    /* copy in the last byte */
+    int last_i = nchars;
+    char last_dst_char = dst[last_i];
+    last_dst_char &= 0xff00;
+    last_dst_char |= (c & 0x00ff);
+    dst[last_i] = last_dst_char;
+  }
+}
+#else
+void speex_memcpy_bytes(char *dst, char *src, int nbytes)
+{
+  memcpy(dst, src, nbytes);
+}
+void speex_memset_bytes(char *dst, char src, int nbytes)
+{
+  memset(dst, src, nbytes);
+}
+#endif
+
 void *speex_alloc (int size)
 {
    return calloc(size,1);
@@ -150,5 +194,5 @@
 void _speex_putc(int ch, void *file)
 {
    FILE *f = (FILE *)file;
-   fputc(ch, f);
+   fprintf(f, "%c", ch);
 }

Modified: trunk/speex/libspeex/misc.h
===================================================================
--- trunk/speex/libspeex/misc.h	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/misc.h	2005-03-15 05:18:02 UTC (rev 9076)
@@ -49,8 +49,8 @@
 void print_vec(float *vec, int len, char *name);
 #endif
 
-unsigned int be_int(unsigned int i);
-unsigned int le_int(unsigned int i);
+spx_uint32_t be_int(spx_uint32_t i);
+spx_uint32_t le_int(spx_uint32_t i);
 
 
 unsigned short be_short(unsigned short s);
@@ -68,6 +68,9 @@
 /** Speex wrapper for mem_move */
 void *speex_move (void *dest, void *src, int n);
 
+void speex_memcpy_bytes(char *dst, char *src, int nbytes);
+void speex_memset_bytes(char *dst, char src, int nbytes);
+
 void speex_error(char *str);
 
 void speex_warning(char *str);

Modified: trunk/speex/libspeex/modes.c
===================================================================
--- trunk/speex/libspeex/modes.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/modes.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -150,6 +150,8 @@
    0,
 };
 
+#ifndef DISABLE_WIDEBAND
+
 /* Split-VQ innovation for high-band wideband */
 static const split_cb_params split_cb_high = {
    8,               /*subvect_size*/
@@ -169,6 +171,8 @@
    0,
 };
 
+#endif
+
 /* 2150 bps "vocoder-like" mode for comfort noise */
 static const SpeexSubmode nb_submode1 = {
    0,
@@ -454,7 +458,11 @@
    /*Innovation quantization*/
    split_cb_search_shape_sign,
    split_cb_shape_sign_unquant,
+#ifdef DISABLE_WIDEBAND
+   NULL,
+#else
    &split_cb_high_lbr,
+#endif
 #ifdef FIXED_POINT
    27853, 19661, 8192, -1,
 #else
@@ -479,7 +487,11 @@
    /*Innovation quantization*/
    split_cb_search_shape_sign,
    split_cb_shape_sign_unquant,
+#ifdef DISABLE_WIDEBAND
+   NULL,
+#else
    &split_cb_high,
+#endif
 
 #ifdef FIXED_POINT
    24576, 22938, 1638, -1,
@@ -504,7 +516,11 @@
    /*Innovation quantization*/
    split_cb_search_shape_sign,
    split_cb_shape_sign_unquant,
+#ifdef DISABLE_WIDEBAND
+   NULL,
+#else
    &split_cb_high,
+#endif
 #ifdef FIXED_POINT
    24576, 24576, 0, -1,
 #else

Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/nb_celp.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -667,7 +667,8 @@
          spx_word32_t pi_g=st->interp_qlpc[0];
          for (i=1;i<=st->lpcSize;i+=2)
          {
-            pi_g += -st->interp_qlpc[i] +  st->interp_qlpc[i+1];
+            /*pi_g += -st->interp_qlpc[i] +  st->interp_qlpc[i+1];*/
+            pi_g = ADD32(pi_g, SUB32(st->interp_qlpc[i+1],st->interp_qlpc[i]));
          }
          st->pi_gain[sub] = pi_g;
       }
@@ -851,7 +852,7 @@
             signal_mul(innov, innov, ener, st->subframeSize);
 
             for (i=0;i<st->subframeSize;i++)
-               exc[i] += innov[i];
+               exc[i] = ADD32(exc[i],innov[i]);
          } else {
             speex_error("No fixed codebook");
          }
@@ -870,7 +871,7 @@
                                       innov2, syn_resp, bits, stack, st->complexity, 0);
             signal_mul(innov2, innov2, (spx_word32_t) (ener*(1/2.2)), st->subframeSize);
             for (i=0;i<st->subframeSize;i++)
-               exc[i] += innov2[i];
+               exc[i] = ADD32(exc[i],innov2[i]);
             stack = tmp_stack;
          }
 
@@ -1415,7 +1416,8 @@
          spx_word32_t pi_g=st->interp_qlpc[0];
          for (i=1;i<=st->lpcSize;i+=2)
          {
-            pi_g += -st->interp_qlpc[i] +  st->interp_qlpc[i+1];
+            /*pi_g += -st->interp_qlpc[i] +  st->interp_qlpc[i+1];*/
+            pi_g = ADD32(pi_g, SUB32(st->interp_qlpc[i+1],st->interp_qlpc[i]));
          }
          st->pi_gain[sub] = pi_g;
       }
@@ -1565,7 +1567,7 @@
             }
          } else {
             for (i=0;i<st->subframeSize;i++)
-               exc[i]+=innov[i];
+               exc[i]=ADD32(exc[i],innov[i]);
             /*print_vec(exc, 40, "innov");*/
          }
          /* Decode second codebook (only for some modes) */
@@ -1579,7 +1581,7 @@
             SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack);
             signal_mul(innov2, innov2, (spx_word32_t) (ener*(1/2.2)), st->subframeSize);
             for (i=0;i<st->subframeSize;i++)
-               exc[i] += innov2[i];
+               exc[i] = ADD32(exc[i],innov2[i]);
             stack = tmp_stack;
          }
 

Modified: trunk/speex/libspeex/quant_lsp.c
===================================================================
--- trunk/speex/libspeex/quant_lsp.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/quant_lsp.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -295,6 +295,16 @@
 }
 
 
+#ifdef DISABLE_WIDEBAND
+void lsp_quant_high(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
+{
+   speex_error("Wideband and Ultra-wideband are disabled");
+}
+void lsp_unquant_high(spx_lsp_t *lsp, int order, SpeexBits *bits)
+{
+   speex_error("Wideband and Ultra-wideband are disabled");
+}
+#else
 extern const signed char high_lsp_cdbk[];
 extern const signed char high_lsp_cdbk2[];
 
@@ -364,7 +374,9 @@
       lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
 }
 
+#endif
 
+
 #ifdef EPIC_48K
 
 extern const signed char cdbk_lsp_vlbr[5120];

Modified: trunk/speex/libspeex/sb_celp.c
===================================================================
--- trunk/speex/libspeex/sb_celp.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/sb_celp.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -46,6 +46,48 @@
 #include "ltp.h"
 #include "misc.h"
 
+#ifdef DISABLE_WIDEBAND
+void *sb_encoder_init(const SpeexMode *m)
+{
+   speex_error("Wideband and Ultra-wideband are disabled");
+   return NULL;
+}
+void sb_encoder_destroy(void *state)
+{
+   speex_error("Wideband and Ultra-wideband are disabled");
+}
+int sb_encode(void *state, void *vin, SpeexBits *bits)
+{
+   speex_error("Wideband and Ultra-wideband are disabled");
+   return -2;
+}
+void *sb_decoder_init(const SpeexMode *m)
+{
+   speex_error("Wideband and Ultra-wideband are disabled");
+   return NULL;
+}
+void sb_decoder_destroy(void *state)
+{
+   speex_error("Wideband and Ultra-wideband are disabled");
+}
+int sb_decode(void *state, SpeexBits *bits, void *vout)
+{
+   speex_error("Wideband and Ultra-wideband are disabled");
+   return -2;
+}
+int sb_encoder_ctl(void *state, int request, void *ptr)
+{
+   speex_error("Wideband and Ultra-wideband are disabled");
+   return -2;
+}
+int sb_decoder_ctl(void *state, int request, void *ptr)
+{
+   speex_error("Wideband and Ultra-wideband are disabled");
+   return -2;
+}
+#else
+
+
 #ifndef M_PI
 #define M_PI           3.14159265358979323846  /* pi */
 #endif
@@ -307,7 +349,7 @@
       qmf_decomp(in, h0, st->x0d, st->x1d, st->full_frame_size, QMF_ORDER, st->h0_mem, stack);
       
       for (i=0;i<st->frame_size;i++)
-         low[i] = PSHR(st->x0d[i],SIG_SHIFT);
+         low[i] = SATURATE(PSHR(st->x0d[i],SIG_SHIFT),32767);
       
       /* Encode the narrowband part*/
       speex_encode_native(st->st_low, low, bits);
@@ -679,7 +721,7 @@
          signal_mul(innov, innov, scale, st->subframeSize);
 
          for (i=0;i<st->subframeSize;i++)
-            exc[i] += innov[i];
+            exc[i] = ADD32(exc[i], innov[i]);
 
          if (SUBMODE(double_codebook)) {
             char *tmp_stack=stack;
@@ -695,7 +737,7 @@
             for (i=0;i<st->subframeSize;i++)
                innov2[i]*=scale*(1/2.5)/SIG_SCALING;
             for (i=0;i<st->subframeSize;i++)
-               exc[i] += innov2[i];
+               exc[i] = ADD32(exc[i],innov2[i]);
             stack = tmp_stack;
          }
 
@@ -1106,7 +1148,7 @@
             for (i=0;i<st->subframeSize;i++)
                innov2[i]*=scale/(float)SIG_SCALING*(1/2.5);
             for (i=0;i<st->subframeSize;i++)
-               exc[i] += innov2[i];
+               exc[i] = ADD32(exc[i],innov2[i]);
             stack = tmp_stack;
          }
 
@@ -1462,3 +1504,6 @@
    }
    return 0;
 }
+
+#endif
+

Modified: trunk/speex/libspeex/speex.c
===================================================================
--- trunk/speex/libspeex/speex.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/speex.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -103,7 +103,9 @@
 
 int speex_encode_int(void *state, short *in, SpeexBits *bits)
 {
-   return (*((SpeexMode**)state))->enc(state, in, bits);
+   SpeexMode *mode;
+   mode = *(SpeexMode**)state;
+   return (mode)->enc(state, in, bits);
 }
 
 int speex_decode(void *state, SpeexBits *bits, float *out)
@@ -120,7 +122,8 @@
 
 int speex_decode_int(void *state, SpeexBits *bits, short *out)
 {
-   return (*((SpeexMode**)state))->dec(state, bits, out);
+   SpeexMode *mode = *(SpeexMode**)state;
+   return (mode)->dec(state, bits, out);
 }
 
 #else
@@ -260,7 +263,6 @@
       default:
          speex_warning_int("Unknown wb_mode_query request: ", request);
          return -1;
-         break;
    }
    return 0;
 }

Modified: trunk/speex/libspeex/speex_callbacks.c
===================================================================
--- trunk/speex/libspeex/speex_callbacks.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/speex_callbacks.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -125,6 +125,7 @@
    unsigned char ch;
    ch = speex_bits_unpack_unsigned(bits, 8);
    _speex_putc(ch, data);
+   /*printf("speex_std_char_handler ch=%x\n", ch);*/
    return 0;
 }
 

Modified: trunk/speex/libspeex/speex_header.c
===================================================================
--- trunk/speex/libspeex/speex_header.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/speex_header.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -35,8 +35,8 @@
 #include "config.h"
 #endif
 
+#include "misc.h"
 #include <speex/speex_header.h>
-#include "misc.h"
 #include <speex/speex.h>
 
 #ifndef NULL

Modified: trunk/speex/libspeex/testenc.c
===================================================================
--- trunk/speex/libspeex/testenc.c	2005-03-14 23:41:11 UTC (rev 9075)
+++ trunk/speex/libspeex/testenc.c	2005-03-15 05:18:02 UTC (rev 9076)
@@ -55,7 +55,7 @@
    speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp);
    tmp=4;
    speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp);
-   tmp=5;
+   tmp=1;
    speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp);
 
    speex_mode_query(&speex_nb_mode, SPEEX_MODE_FRAME_SIZE, &tmp);



More information about the commits mailing list