shithub: opus

Download patch

ref: abe043f0a1a8dd8ce4ae273ea0043e2c057f1aae
parent: 3d3bb6853628791a881a6f53e3def2d04d5bb92a
author: Jean-Marc Valin <[email protected]>
date: Thu Jan 31 09:26:29 EST 2008

Moving everything to the same type abstraction (sort of).

--- a/libcelt/arch.h
+++ b/libcelt/arch.h
@@ -35,41 +35,9 @@
 #ifndef ARCH_H
 #define ARCH_H
 
-/* A couple test to catch stupid option combinations */
-#ifdef FIXED_POINT
+#include "celt_types.h"
 
-#ifdef FLOATING_POINT
-#error You cannot compile as floating point and fixed point at the same time
-#endif
-#ifdef _USE_SSE
-#error SSE is only for floating-point
-#endif
-#if ((defined (ARM4_ASM)||defined (ARM4_ASM)) && defined(BFIN_ASM)) || (defined (ARM4_ASM)&&defined(ARM5E_ASM))
-#error Make up your mind. What CPU do you have?
-#endif
-#ifdef VORBIS_PSYCHO
-#error Vorbis-psy model currently not implemented in fixed-point
-#endif
 
-#else
-
-/*#ifndef FLOATING_POINT
-#error You now need to define either FIXED_POINT or FLOATING_POINT
-#endif
-#if defined (ARM4_ASM) || defined(ARM5E_ASM) || defined(BFIN_ASM)
-#error I suppose you can have a [ARM4/ARM5E/Blackfin] that has float instructions?
-#endif
-#ifdef FIXED_POINT_DEBUG
-#error "Don't you think enabling fixed-point is a good thing to do if you want to debug that?"
-#endif*/
-
-
-#endif
-
-typedef unsigned long long celt_uint64_t;
-typedef int spx_int32_t;
-typedef short spx_int16_t;
-
 #define ABS(x) ((x) < 0 ? (-(x)) : (x))      /**< Absolute integer value. */
 #define ABS16(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 16-bit value.  */
 #define MIN16(a,b) ((a) < (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
@@ -80,12 +48,8 @@
 
 #ifdef FIXED_POINT
 
-typedef spx_int16_t spx_word16_t;
-typedef spx_int32_t   spx_word32_t;
-typedef spx_word32_t spx_mem_t;
-typedef spx_word16_t spx_coef_t;
-typedef spx_word16_t spx_lsp_t;
-typedef spx_word32_t spx_sig_t;
+typedef celt_int16_t celt_word16_t;
+typedef celt_int32_t celt_word32_t;
 
 #define Q15ONE 32767
 
@@ -102,9 +66,9 @@
 #define GAIN_SHIFT   6
 
 #define VERY_SMALL 0
-#define VERY_LARGE32 ((spx_word32_t)2147483647)
-#define VERY_LARGE16 ((spx_word16_t)32767)
-#define Q15_ONE ((spx_word16_t)32767)
+#define VERY_LARGE32 ((celt_word32_t)2147483647)
+#define VERY_LARGE16 ((celt_word16_t)32767)
+#define Q15_ONE ((celt_word16_t)32767)
 
 
 #ifdef FIXED_DEBUG
@@ -126,12 +90,8 @@
 
 #else
 
-typedef float spx_mem_t;
-typedef float spx_coef_t;
-typedef float spx_lsp_t;
-typedef float spx_sig_t;
-typedef float spx_word16_t;
-typedef float spx_word32_t;
+typedef float celt_word16_t;
+typedef float celt_word32_t;
 
 #define Q15ONE 1.0f
 #define LPC_SCALING  1.f
@@ -145,7 +105,7 @@
 #define VERY_SMALL 1e-15f
 #define VERY_LARGE32 1e15f
 #define VERY_LARGE16 1e15f
-#define Q15_ONE ((spx_word16_t)1.f)
+#define Q15_ONE ((celt_word16_t)1.f)
 
 #define QCONST16(x,bits) (x)
 #define QCONST32(x,bits) (x)
@@ -174,8 +134,8 @@
 #define ADD32(a,b) ((a)+(b))
 #define SUB32(a,b) ((a)-(b))
 #define MULT16_16_16(a,b)     ((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_16(a,b)     ((celt_word32_t)(a)*(celt_word32_t)(b))
+#define MAC16_16(c,a,b)     ((c)+(celt_word32_t)(a)*(celt_word32_t)(b))
 
 #define MULT16_32_Q11(a,b)     ((a)*(b))
 #define MULT16_32_Q13(a,b)     ((a)*(b))
@@ -197,10 +157,10 @@
 #define MULT16_16_P13(a,b)     ((a)*(b))
 #define MULT16_16_P14(a,b)     ((a)*(b))
 
-#define DIV32_16(a,b)     (((spx_word32_t)(a))/(spx_word16_t)(b))
-#define PDIV32_16(a,b)     (((spx_word32_t)(a))/(spx_word16_t)(b))
-#define DIV32(a,b)     (((spx_word32_t)(a))/(spx_word32_t)(b))
-#define PDIV32(a,b)     (((spx_word32_t)(a))/(spx_word32_t)(b))
+#define DIV32_16(a,b)     (((celt_word32_t)(a))/(celt_word16_t)(b))
+#define PDIV32_16(a,b)     (((celt_word32_t)(a))/(celt_word16_t)(b))
+#define DIV32(a,b)     (((celt_word32_t)(a))/(celt_word32_t)(b))
+#define PDIV32(a,b)     (((celt_word32_t)(a))/(celt_word32_t)(b))
 
 
 #endif
@@ -221,11 +181,6 @@
 
 #endif
 
-
-
-#ifdef FIXED_DEBUG
-long long spx_mips=0;
-#endif
 
 
 #endif
--- a/libcelt/celt_types.h
+++ b/libcelt/celt_types.h
@@ -22,7 +22,7 @@
 #ifndef _CELT_TYPES_H
 #define _CELT_TYPES_H
 
-/* Taken from Paul Hsieh's stdint.h */
+/* Use the real stdint.h if it's there (taken from Paul Hsieh's pstdint.h) */
 #if (defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) )
 #include <stdint.h>
 
@@ -30,7 +30,8 @@
    typedef uint16_t celt_uint16_t;
    typedef int32_t celt_int32_t;
    typedef uint32_t celt_uint32_t;
-
+   typedef int64_t celt_int64_t;
+   typedef uint64_t celt_uint64_t;
 #elif defined(_WIN32) 
 
 #  if defined(__CYGWIN__)
@@ -39,16 +40,22 @@
      typedef _G_uint32_t celt_uint32_t;
      typedef _G_int16_t celt_int16_t;
      typedef _G_uint16_t celt_uint16_t;
+     typedef _G_int64_t celt_int64_t;
+     typedef _G_uint64_t celt_uint64_t;
 #  elif defined(__MINGW32__)
      typedef short celt_int16_t;
      typedef unsigned short celt_uint16_t;
      typedef int celt_int32_t;
      typedef unsigned int celt_uint32_t;
+     typedef long long celt_int64_t;
+     typedef unsigned long long celt_uint64_t;
 #  elif defined(__MWERKS__)
      typedef int celt_int32_t;
      typedef unsigned int celt_uint32_t;
      typedef short celt_int16_t;
      typedef unsigned short celt_uint16_t;
+     typedef long long celt_int64_t;
+     typedef unsigned long long celt_uint64_t;
 #  else
      /* MSVC/Borland */
      typedef __int32 celt_int32_t;
@@ -55,6 +62,8 @@
      typedef unsigned __int32 celt_uint32_t;
      typedef __int16 celt_int16_t;
      typedef unsigned __int16 celt_uint16_t;
+     typedef __int64 celt_int64_t;
+     typedef unsigned __int64 celt_uint64_t;
 #  endif
 
 #elif defined(__MACOS__)
@@ -64,6 +73,8 @@
    typedef UInt16 celt_uint16_t;
    typedef SInt32 celt_int32_t;
    typedef UInt32 celt_uint32_t;
+   typedef SInt64 celt_int64_t;
+   typedef UInt64 celt_uint64_t;
 
 #elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */
 
@@ -72,6 +83,8 @@
    typedef u_int16_t celt_uint16_t;
    typedef int32_t celt_int32_t;
    typedef u_int32_t celt_uint32_t;
+   typedef int64_t celt_int64_t;
+   typedef u_int64_t celt_uint64_t;
 
 #elif defined(__BEOS__)
 
@@ -81,6 +94,8 @@
    typedef u_int16_t celt_uint16_t;
    typedef int32_t celt_int32_t;
    typedef u_int32_t celt_uint32_t;
+   typedef int64_t celt_int64_t;
+   typedef u_int64_t celt_uint64_t;
 
 #elif defined (__EMX__)
 
@@ -89,6 +104,8 @@
    typedef unsigned short celt_uint16_t;
    typedef int celt_int32_t;
    typedef unsigned int celt_uint32_t;
+   typedef long long celt_int64_t;
+   typedef unsigned long long celt_uint64_t;
 
 #elif defined (DJGPP)
 
@@ -96,6 +113,8 @@
    typedef short celt_int16_t;
    typedef int celt_int32_t;
    typedef unsigned int celt_uint32_t;
+   typedef long long celt_int64_t;
+   typedef unsigned long long celt_uint64_t;
 
 #elif defined(R5900)
 
@@ -103,6 +122,8 @@
    typedef int celt_int32_t;
    typedef unsigned celt_uint32_t;
    typedef short celt_int16_t;
+   typedef long celt_int64_t;
+   typedef unsigned long celt_uint64_t;
 
 #elif defined(__SYMBIAN32__)
 
@@ -111,6 +132,8 @@
    typedef unsigned short celt_uint16_t;
    typedef signed int celt_int32_t;
    typedef unsigned int celt_uint32_t;
+   typedef long long int celt_int64_t;
+   typedef unsigned long long int celt_uint64_t;
 
 #elif defined(CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
 
@@ -118,6 +141,8 @@
    typedef unsigned short celt_uint16_t;
    typedef long celt_int32_t;
    typedef unsigned long celt_uint32_t;
+   typedef long long celt_int64_t;
+   typedef unsigned long long celt_uint64_t;
 
 #elif defined(CONFIG_TI_C6X)
 
@@ -125,6 +150,8 @@
    typedef unsigned short celt_uint16_t;
    typedef int celt_int32_t;
    typedef unsigned int celt_uint32_t;
+   typedef long long int celt_int64_t;
+   typedef unsigned long long int celt_uint64_t;
 
 #else
 
@@ -133,6 +160,8 @@
    typedef unsigned short celt_uint16_t;
    typedef long celt_int32_t;
    typedef unsigned long celt_uint32_t;
+   typedef long long celt_int64_t;
+   typedef unsigned long long celt_uint64_t;
 
 #endif
 
--- a/libcelt/cwrs.c
+++ b/libcelt/cwrs.c
@@ -33,8 +33,8 @@
 /*Returns the numer of ways of choosing _m elements from a set of size _n with
    replacement when a sign bit is needed for each unique element.*/
 #if 0
-static unsigned ncwrs(int _n,int _m){
-  static unsigned c[32][32];
+static celt_uint32_t ncwrs(int _n,int _m){
+  static celt_uint32_t c[32][32];
   if(_n<0||_m<0)return 0;
   if(!c[_n][_m]){
     if(_m<=0)c[_n][_m]=1;
@@ -43,10 +43,10 @@
   return c[_n][_m];
 }
 #else
-unsigned ncwrs(int _n,int _m){
-  unsigned ret;
-  unsigned f;
-  unsigned d;
+celt_uint32_t ncwrs(int _n,int _m){
+  celt_uint32_t ret;
+  celt_uint32_t f;
+  celt_uint32_t d;
   int      i;
   if(_n<0||_m<0)return 0;
   if(_m==0)return 1;
@@ -86,13 +86,13 @@
    with associated sign bits.
   _x:      Returns the combination with elements sorted in ascending order.
   _s:      Returns the associated sign bits.*/
-void cwrsi(int _n,int _m,unsigned _i,int *_x,int *_s){
+void cwrsi(int _n,int _m,celt_uint32_t _i,int *_x,int *_s){
   int j;
   int k;
   for(k=j=0;k<_m;k++){
-    unsigned pn;
-    unsigned p;
-    unsigned t;
+    celt_uint32_t pn;
+    celt_uint32_t p;
+    celt_uint32_t t;
     p=ncwrs(_n-j,_m-k-1);
     pn=ncwrs(_n-j-1,_m-k-1);
     p+=pn;
@@ -118,14 +118,14 @@
    of size _n with associated sign bits.
   _x:      The combination with elements sorted in ascending order.
   _s:      The associated sign bits.*/
-unsigned icwrs(int _n,int _m,const int *_x,const int *_s){
-  unsigned i;
+celt_uint32_t icwrs(int _n,int _m,const int *_x,const int *_s){
+  celt_uint32_t i;
   int      j;
   int      k;
   i=0;
   for(k=j=0;k<_m;k++){
-    unsigned pn;
-    unsigned p;
+    celt_uint32_t pn;
+    celt_uint32_t p;
     p=ncwrs(_n-j,_m-k-1);
     pn=ncwrs(_n-j-1,_m-k-1);
     p+=pn;
@@ -241,95 +241,3 @@
   }
 }
 
-#if 0
-#include <stdio.h>
-#define NMAX (10)
-#define MMAX (9)
-
-int main(int _argc,char **_argv){
-  int n;
-  for(n=0;n<=NMAX;n++){
-    int m;
-    for(m=0;m<=MMAX;m++){
-      unsigned nc;
-      unsigned i;
-      nc=ncwrs(n,m);
-      for(i=0;i<nc;i++){
-        int x[MMAX];
-        int s[MMAX];
-        int x2[MMAX];
-        int s2[MMAX];
-        int y[NMAX];
-        int j;
-        int k;
-        cwrsi(n,m,i,x,s);
-        printf("%6u of %u:",i,nc);
-        for(k=0;k<m;k++){
-          printf(" %c%i",k>0&&x[k]==x[k-1]?' ':s[k]?'-':'+',x[k]);
-        }
-        printf(" ->");
-        if(icwrs(n,m,x,s)!=i){
-          fprintf(stderr,"Combination-index mismatch.\n");
-        }
-        comb2pulse(n,m,y,x,s);
-        for(j=0;j<n;j++)printf(" %c%i",y[j]?y[j]<0?'-':'+':' ',abs(y[j]));
-        printf("\n");
-        pulse2comb(n,m,x2,s2,y);
-        for(k=0;k<m;k++)if(x[k]!=x2[k]||s[k]!=s2[k]){
-          fprintf(stderr,"Pulse-combination mismatch.\n");
-          break;
-        }
-      }
-      printf("\n");
-    }
-  }
-  return -1;
-}
-#endif
-
-#if 0
-#include <stdio.h>
-#define NMAX (32)
-#define MMAX (16)
-
-int main(int _argc,char **_argv){
-  int n;
-  for(n=0;n<=NMAX;n+=3){
-    int m;
-    for(m=0;m<=MMAX;m++){
-      celt_uint64_t nc;
-      celt_uint64_t i;
-      nc=ncwrs64(n,m);
-      printf("%d/%d: %llu",n,m, nc);
-      for(i=0;i<nc;i+=100000){
-        int x[MMAX];
-        int s[MMAX];
-        int x2[MMAX];
-        int s2[MMAX];
-        int y[NMAX];
-        int j;
-        int k;
-        cwrsi64(n,m,i,x,s);
-        /*printf("%llu of %llu:",i,nc);
-        for(k=0;k<m;k++){
-          printf(" %c%i",k>0&&x[k]==x[k-1]?' ':s[k]?'-':'+',x[k]);
-        }
-        printf(" ->");*/
-        if(icwrs64(n,m,x,s)!=i){
-          fprintf(stderr,"Combination-index mismatch.\n");
-        }
-        comb2pulse(n,m,y,x,s);
-        /*for(j=0;j<n;j++)printf(" %c%i",y[j]?y[j]<0?'-':'+':' ',abs(y[j]));
-        printf("\n");*/
-        pulse2comb(n,m,x2,s2,y);
-        for(k=0;k<m;k++)if(x[k]!=x2[k]||s[k]!=s2[k]){
-          fprintf(stderr,"Pulse-combination mismatch.\n");
-          break;
-        }
-      }
-      printf("\n");
-    }
-  }
-  return 0;
-}
-#endif
--- a/libcelt/cwrs.h
+++ b/libcelt/cwrs.h
@@ -34,11 +34,11 @@
 
 #include "arch.h"
 
-unsigned ncwrs(int _n,int _m);
+celt_uint32_t ncwrs(int _n,int _m);
 
-void cwrsi(int _n,int _m,unsigned _i,int *_x,int *_s);
+void cwrsi(int _n,int _m,celt_uint32_t _i,int *_x,int *_s);
 
-unsigned icwrs(int _n,int _m,const int *_x,const int *_s);
+celt_uint32_t icwrs(int _n,int _m,const int *_x,const int *_s);
 
 void comb2pulse(int _n,int _m,int *_y,const int *_x,const int *_s);
 
--- a/libcelt/entcode.h
+++ b/libcelt/entcode.h
@@ -1,3 +1,5 @@
+#include "celt_types.h"
+
 #if !defined(_entcode_H)
 # define _entcode_H (1)
 # include <limits.h>
@@ -5,8 +7,8 @@
 
 
 
-typedef unsigned ec_uint32;
-typedef unsigned long long ec_uint64;
+typedef celt_uint32_t ec_uint32;
+typedef celt_uint64_t ec_uint64;
 typedef struct ec_byte_buffer ec_byte_buffer;
 
 
--- a/libcelt/fftwrap.h
+++ b/libcelt/fftwrap.h
@@ -44,10 +44,10 @@
 void spx_fft_destroy(void *table);
 
 /** Forward (real to half-complex) transform */
-void spx_fft(void *table, spx_word16_t *in, spx_word16_t *out);
+void spx_fft(void *table, celt_word16_t *in, celt_word16_t *out);
 
 /** Backward (half-complex to real) transform */
-void spx_ifft(void *table, spx_word16_t *in, spx_word16_t *out);
+void spx_ifft(void *table, celt_word16_t *in, celt_word16_t *out);
 
 /** Forward (real to half-complex) transform of float data */
 void spx_fft_float(void *table, float *in, float *out);
--- a/tests/cwrs32-test.c
+++ b/tests/cwrs32-test.c
@@ -47,4 +47,4 @@
     }
   }
   return 0;
-}
\ No newline at end of file
+}
--- a/tests/cwrs64-test.c
+++ b/tests/cwrs64-test.c
@@ -48,4 +48,4 @@
     }
   }
   return 0;
-}
\ No newline at end of file
+}