[PD-cvs] externals/iem16/src iem16_table.c, 1.1.1.1, 1.2 iem16_table.h, 1.1.1.1, 1.2

IOhannes m zmölnig zmoelnig at users.sourceforge.net
Fri Jul 1 14:07:53 CEST 2005


Update of /cvsroot/pure-data/externals/iem16/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25770

Modified Files:
	iem16_table.c iem16_table.h 
Log Message:
added "read16" message for the table16
added some prelaminary tabfudge that should make casting faster (LATER)


Index: iem16_table.h
===================================================================
RCS file: /cvsroot/pure-data/externals/iem16/src/iem16_table.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** iem16_table.h	23 Nov 2004 15:29:47 -0000	1.1.1.1
--- iem16_table.h	1 Jul 2005 12:07:50 -0000	1.2
***************
*** 18,24 ****
    t_symbol *x_tablename;
    long      x_size;
!   t_iem16_16bit    *x_table; // hold the data
  
    int x_usedindsp;
  } t_table16;
  
--- 18,25 ----
    t_symbol *x_tablename;
    long      x_size;
!   t_iem16_16bit    *x_table; /* hold the data */
  
    int x_usedindsp;
+   t_canvas *x_canvas; /* for file i/o */
  } t_table16;
  
***************
*** 26,27 ****
--- 27,93 ----
  EXTERN int table16_getarray16(t_table16*x, int*size,t_iem16_16bit**vec);
  EXTERN void table16_usedindsp(t_table16*x);
+ 
+ 
+ #define UNITBIT32 1572864.  /* 3*2^19; bit 32 has place value 1 */
+ 
+     /* machine-dependent definitions.  These ifdefs really
+     should have been by CPU type and not by operating system! */
+ #ifdef __irix__
+     /* big-endian.  Most significant byte is at low address in memory */
+ #define HIOFFSET 0    /* word offset to find MSB */
+ #define LOWOFFSET 1    /* word offset to find LSB */
+ #define int32 long  /* a data type that has 32 bits */
+ #else
+ #ifdef __win32__
+     /* little-endian; most significant byte is at highest address */
+ #define HIOFFSET 1
+ #define LOWOFFSET 0
+ #define int32 long
+ #else
+ #ifdef __FreeBSD__
+ #include <machine/endian.h>
+ #if BYTE_ORDER == LITTLE_ENDIAN
+ #define HIOFFSET 1
+ #define LOWOFFSET 0
+ #else
+ #define HIOFFSET 0    /* word offset to find MSB */
+ #define LOWOFFSET 1    /* word offset to find LSB */
+ #endif /* BYTE_ORDER */
+ #include <sys/types.h>
+ #define int32 int32_t
+ #endif
+ #ifdef __linux__
+ 
+ #include <endian.h>
+ 
+ #if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN)                         
+ #error No byte order defined                                                    
+ #endif                                                                          
+                                                                                 
+ #if __BYTE_ORDER == __LITTLE_ENDIAN                                             
+ #define HIOFFSET 1                                                              
+ #define LOWOFFSET 0                                                             
+ #else                                                                           
+ #define HIOFFSET 0    /* word offset to find MSB */                             
+ #define LOWOFFSET 1    /* word offset to find LSB */                            
+ #endif /* __BYTE_ORDER */                                                       
+ 
+ #include <sys/types.h>
+ #define int32 int32_t
+ 
+ #else
+ #ifdef __apple__
+ #define HIOFFSET 0    /* word offset to find MSB */
+ #define LOWOFFSET 1    /* word offset to find LSB */
+ #define int32 int  /* a data type that has 32 bits */
+ 
+ #endif /* MACOSX */
+ #endif /* __linux__ */
+ #endif /* MSW */
+ #endif /* SGI */
+ 
+ union tabfudge
+ {
+     double tf_d;
+     int32 tf_i[2];
+ };

Index: iem16_table.c
===================================================================
RCS file: /cvsroot/pure-data/externals/iem16/src/iem16_table.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** iem16_table.c	23 Nov 2004 15:29:47 -0000	1.1.1.1
--- iem16_table.c	1 Jul 2005 12:07:50 -0000	1.2
***************
*** 8,11 ****
--- 8,22 ----
  
  #include "iem16_table.h"
+ 
+ #include <stdio.h>      /* for read/write to files */
+ 
+ static int am_bigendian(void){
+     /* actually this should be in m_pd.h */
+     unsigned short s = 1;
+     unsigned char c = *(char *)(&s);
+     return (c==0);
+ }
+ 
+ 
  static void table16_const(t_table16*x, t_float f);
  
***************
*** 19,22 ****
--- 30,34 ----
    x->x_usedindsp=0;
    pd_bind(&x->x_obj.ob_pd, x->x_tablename);
+   x->x_canvas = canvas_getcurrent();
  
    table16_const(x, 0);
***************
*** 64,68 ****
    t_garray *a=0;
    int npoints;
!   t_float *vec, *src;
    t_iem16_16bit   *dest;
  
--- 76,80 ----
    t_garray *a=0;
    int npoints;
!   t_float *vec=(0), *src=(0);
    t_iem16_16bit   *dest;
  
***************
*** 121,125 ****
    i=length;
    while(i--)*dest++=(*src++)*scale;
!   post("from %s (%d, %d) --> (%d, %d)\tresize=%s", s->s_name, startfrom, endfrom, startto, endto, (resize)?"yes":"no");
  }
  
--- 133,201 ----
    i=length;
    while(i--)*dest++=(*src++)*scale;
!   //post("from %s (%d, %d) --> (%d, %d)\tresize=%s", s->s_name, startfrom, endfrom, startto, endto, (resize)?"yes":"no");
! }
! 
! #define BINREADMODE "rb"
! #define BINWRITEMODE "wb"
! static void table16_read16(t_table16 *x, t_symbol *filename,  t_symbol *endian, t_floatarg fskip)
! {
!     int skip = fskip, filedesc;
!     int i, nelem;
!     t_iem16_16bit *vec;
!     FILE *fd;
!     char buf[MAXPDSTRING], *bufptr;
!     short s;
!     int cpubig = am_bigendian(), swap = 0;
!     char c = endian->s_name[0];
!     if (c == 'b')
!     {
!         if (!cpubig) swap = 1;
!     }
!     else if (c == 'l')
!     {
!         if (cpubig) swap = 1;
!     }
!     else if (c)
!     {
!         error("array_read16: endianness is 'l' (low byte first ala INTEL)");
!         post("... or 'b' (high byte first ala MIPS,DEC,PPC)");
!     }
!     if (!table16_getarray16(x, &nelem, &vec))
!     {
!         error("%s: not a 16bit array", x->x_tablename->s_name);
!         return;
!     }
!     if ((filedesc = open_via_path(
!         canvas_getdir(x->x_canvas)->s_name,
!             filename->s_name, "", buf, &bufptr, MAXPDSTRING, 1)) < 0 
!                 || !(fd = fdopen(filedesc, BINREADMODE)))
!     {
!         error("%s: can't open", filename->s_name);
!         return;
!     }
!     if (skip)
!     {
!         long pos = fseek(fd, (long)skip, SEEK_SET);
!         if (pos < 0)
!         {
!             error("%s: can't seek to byte %d", buf, skip);
!             fclose(fd);
!             return;
!         }
!     }
! 
!     for (i = 0; i < nelem; i++)
!     {
!         if (fread(&s, sizeof(s), 1, fd) < 1)
!         {
!             post("%s: read %d elements into table of size %d",
!                 filename->s_name, i, nelem);
!             break;
!         }
!         if (swap) s = ((s & 0xff) << 8) | ((s & 0xff00) >> 8);
!         vec[i] = s;
!     }
!     while (i < nelem) vec[i++] = 0;
!     fclose(fd);
  }
  
***************
*** 132,135 ****
--- 208,213 ----
    class_addmethod(table16_class, (t_method)table16_const, gensym("const"), A_DEFFLOAT);
    class_addmethod(table16_class, (t_method)table16_from, gensym("from"), A_GIMME);
+   class_addmethod(table16_class, (t_method)table16_read16, gensym("read16"),  A_SYMBOL, 
+                   A_DEFFLOAT, A_DEFSYM, A_NULL);
  }
  





More information about the Pd-cvs mailing list