ayttm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Ayttm-commits] CVS: ayttm/src sound.c,1.4,1.5


From: Andy Maloney <address@hidden>
Subject: [Ayttm-commits] CVS: ayttm/src sound.c,1.4,1.5
Date: Fri, 10 Jan 2003 07:37:48 -0500

Update of /cvsroot/ayttm/ayttm/src
In directory subversions:/tmp/cvs-serv7598/src

Modified Files:
        sound.c 
Log Message:
Use pref functions to access prefs
Format, header, and static cleanups


Index: sound.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/sound.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- sound.c     4 Jan 2003 13:59:27 -0000       1.4
+++ sound.c     10 Jan 2003 12:37:46 -0000      1.5
@@ -30,8 +30,6 @@
 
 #include "intl.h"
 #include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -43,21 +41,22 @@
 #else
 #include <sys/wait.h>
 #include <sys/signal.h>
-#endif
+#endif /* __MINGW32__ */
 
 #include "globals.h"
 #include "util.h"
-#include "dialog.h"
 #include "sound.h"
 #include "prefs.h"
 
 #ifdef ESD_SOUND
 #include <esd.h>
-#endif
+#endif /* ARTS_SOUND */
 
 #ifdef ARTS_SOUND
+#include <string.h>
 #include <artsc.h>
 #include <audiofile.h>
+
 #define BUFFERED_FRAME_COUNT 20000
 
 /* This is for when arts_init(); arts_free(); arts_init(); does not work
@@ -67,7 +66,7 @@
  */
 #define ARTS_FREE_IS_BROKEN
 
-#endif
+#endif /* ARTS_SOUND */
 
 static int (*play_soundfile)(gchar *soundfile);
 static void (*shutdown_sounddrv)();
@@ -220,7 +219,7 @@
 ** Output: signed 16 bit linear sample
 ** Z-note -- this is from libaudiofile.  Thanks guys!
 */
-int _af_ulaw2linear (unsigned char ulawbyte)
+static int _af_ulaw2linear (unsigned char ulawbyte)
 {
   static int exp_lut[8] = {0,132,396,924,1980,4092,8316,16764};
   int sign, exponent, mantissa, sample;
@@ -236,7 +235,7 @@
   }
 }
 
-#endif
+#endif /* HAVE_LIBAUDIOFILE */
 
 #ifdef ESD_SOUND
 
@@ -275,7 +274,7 @@
     return FALSE;
 }
 
-#endif
+#endif /* ESD_SOUND */
 
 // *** ARTS Support ***
 // Comments/Questions -> address@hidden
@@ -406,136 +405,144 @@
 {
     return FALSE;
 }
-#endif
+#endif /* ARTS_SOUND */
 
 char* auscale(char* infile, char*outfile, float scaling)
 {
 #ifndef __MINGW32__
-    FILE *fd_in, *fd_out; 
-    int bytes_read, x;
-    guint32 header_size;
-    size_t io_bytes;
-  
-    typedef struct
-    {
-       /* NOTE: THE GUINT32 VALUES BELOW ARE IN THE FILE AS BIG-ENDIAN
-        * FORMAT !!!! */
-       guchar  magic[4];  /* magic number '.snd' */
-       guint32 dataloc;    /* offset to start of data */
-       guint32 datasize;   /* num bytes of data */
-       guint32 dataformat; /* data format code */
-       guint32 samplerate; /* sampling rate */
-       guint32 channelcount; /* num of channels */
-       guchar  info;         /* null terminated id string
-                              * (variable length) */
-    } SNDStruct;
-
-    SNDStruct auheader; /* first 28 bytes of .au header */
-    guchar buf,   buf2[256];
-    guchar map[256]; /* 8-bit mapping */
-
-    if (scaling == 0.0) return(infile);  /* save time */
+       FILE *fd_in = NULL;
+       FILE *fd_out = NULL;
+       guint32 header_size = 0;
+       size_t bytes_read = 0;
+       size_t io_bytes = 0;
 
-    if ((fd_in = fopen(infile, "rb")) == NULL)
-    {
-       fprintf(stderr,"Failed opening infile %s, errno=%d\n",infile, errno);
-       return(infile);
-    }
-    /* see if this is .au file, if not then get out */
-    if ((io_bytes = fread((guchar *)&auheader, sizeof(guchar), 
sizeof(auheader), fd_in)) != 28)
-    {
-       fclose(fd_in);
-       fprintf(stderr,"Auscale - header read failed\n");
-       return(infile);
-    }
-    if (strncmp(auheader.magic,".snd",4))
-    {
-       eb_debug(DBG_CORE, "Not .au file,file 
type=%X%X%X%X\n",auheader.magic[0],auheader.magic[1],auheader.magic[2],auheader.magic[3]);
-       fclose(fd_in);
-       return(infile);
-    }
-    x = GUINT32_FROM_BE(auheader.dataformat);
-    if (x!=1) /* only want ulaw-8 format files */
-    {
-       eb_debug(DBG_CORE, "Not .au file,file 
type=%X%X%X%X\n",auheader.magic[0],auheader.magic[1],auheader.magic[2],auheader.magic[3]);
-       fclose(fd_in);
-       return(infile);
-    }
-    header_size= GUINT32_FROM_BE(auheader.dataloc); /* get offset to start of
-                                         * data */
-    /* file is right type, reset to start */
-    rewind(fd_in);
+       typedef struct
+       {
+               /* NOTE: THE GUINT32 VALUES BELOW ARE IN THE FILE AS BIG-ENDIAN 
FORMAT !!!! */
+               guchar  magic[4];  /* magic number '.snd' */
+               guint32 dataloc;    /* offset to start of data */
+               guint32 datasize;   /* num bytes of data */
+               guint32 dataformat; /* data format code */
+               guint32 samplerate; /* sampling rate */
+               guint32 channelcount; /* num of channels */
+               guchar  info;         /* null terminated id string (variable 
length) */
+       } SNDStruct;
+
+       SNDStruct auheader; /* first 28 bytes of .au header */
+       const unsigned int      mapLen = 256;
+       unsigned int            x = 0;
+       guchar  buf;
+       guchar  buf2[mapLen];
+       guchar  map[mapLen]; /* 8-bit mapping */
 
-    if ((fd_out = fopen(outfile, "w+b")) == NULL)
-    {
-       fprintf(stderr,"Failed opening outfile %s, errno=%d\n",outfile,
-               errno);
-       fclose(fd_in);
-       return(infile);
-    }
 
-    eb_debug(DBG_CORE, "Scaling = %f dB\n",scaling);
-    scaling = pow(10.0,scaling/20.0);
+       if (scaling == 0.0)
+               return(infile);  /* save time */
+
+       if ((fd_in = fopen(infile, "rb")) == NULL)
+       {
+               fprintf(stderr,"Failed opening infile %s, errno=%d\n",infile, 
errno);
+               return(infile);
+       }
+
+       /* see if this is .au file, if not then get out */
+       if ((io_bytes = fread((guchar *)&auheader, sizeof(guchar), 
sizeof(auheader), fd_in)) != 28)
+       {
+               fclose(fd_in);
+               fprintf(stderr,"Auscale - header read failed\n");
+               return(infile);
+       }
+
+       if (strncmp(auheader.magic,".snd",4))
+       {
+               eb_debug(DBG_CORE, "Not .au file,file 
type=%X%X%X%X\n",auheader.magic[0],auheader.magic[1],auheader.magic[2],auheader.magic[3]);
+               fclose(fd_in);
+               return(infile);
+       }
+
+       x = GUINT32_FROM_BE(auheader.dataformat);
+
+       if (x!=1) /* only want ulaw-8 format files */
+       {
+               eb_debug(DBG_CORE, "Not .au file,file 
type=%X%X%X%X\n",auheader.magic[0],auheader.magic[1],auheader.magic[2],auheader.magic[3]);
+               fclose(fd_in);
+               return(infile);
+       }
+
+       header_size= GUINT32_FROM_BE(auheader.dataloc); /* get offset to start 
of data */
+       /* file is right type, reset to start */
+       rewind(fd_in);
+
+       if ((fd_out = fopen(outfile, "w+b")) == NULL)
+       {
+               fprintf(stderr,"Failed opening outfile %s, errno=%d\n",outfile, 
errno);
+               fclose(fd_in);
+               return(infile);
+       }
+
+       eb_debug(DBG_CORE, "Scaling = %f dB\n",scaling);
+       scaling = pow(10.0,scaling/20.0);
 
            /* Build mapping */
-    for (x=0; x<256 ; x++) map[x]=linear2ulaw(scaling*_af_ulaw2linear(x));
+    for (x=0; x<mapLen ; x++)
+               map[x]=linear2ulaw(scaling*_af_ulaw2linear(x));
   
     /* Shift the .au header */
     /* copy the .au header */
     /* Note: There are unusual situations when the 'info' field is VERY
      * large and the start of data can therefore be larger than buf2.
      * The following 'while' statement takes care of that problem. */
-    while(header_size >= (guint32)sizeof(buf2))
-    {
-       if ((io_bytes = fread(buf2, sizeof(guchar), sizeof(buf2), fd_in)) == 
sizeof(buf2))
+       while(header_size >= (guint32)sizeof(buf2))
        {
-           if ((io_bytes = fwrite(buf2, sizeof(guchar), sizeof(buf2), fd_out)) 
!=
-                sizeof(buf2))
-           {
-               eb_debug(DBG_CORE, "error copy au file");
-               fclose(fd_out);
-               fclose(fd_in);
-               return (infile);
-           }
+               if ((io_bytes = fread(buf2, sizeof(guchar), sizeof(buf2), 
fd_in)) == sizeof(buf2))
+               {
+                       if ((io_bytes = fwrite(buf2, sizeof(guchar), 
sizeof(buf2), fd_out)) != sizeof(buf2))
+                       {
+                               eb_debug(DBG_CORE, "error copying au file");
+                               fclose(fd_out);
+                               fclose(fd_in);
+                               return (infile);
+                       }
+               }
+               else
+               {
+                       eb_debug(DBG_CORE, "error copying au file");
+                       fclose(fd_in);
+                       fclose(fd_out);
+                       return (infile);
+               }
+
+               /* calc remaining amount of header */
+               header_size -= (guint32)sizeof(buf2);
+       }
+
+       /* copy rest of header (or in most cases - all of it) */
+       if ((io_bytes = fread(buf2, sizeof(guchar), header_size, fd_in)) == 
header_size)
+       {
+               if ((io_bytes = fwrite(buf2, sizeof(guchar), header_size, 
fd_out)) != header_size)
+               {
+                       eb_debug(DBG_CORE, "error copying au file");
+                       fclose(fd_out);
+                       fclose(fd_in);
+                       return (infile);
+               }
        }
        else
        {
-           eb_debug(DBG_CORE, "error copying au file");
-           fclose(fd_in);
-           fclose(fd_out);
-           return (infile);
+               eb_debug(DBG_CORE, "error copying au file");
+               fclose(fd_in);
+               fclose(fd_out);
+               return(infile);
        }
-       /* calc remaining amount of header */
-       header_size -= (guint32)sizeof(buf2);
-    }
-    /* copy rest of header (or in most cases - all of it) */
-    if ((io_bytes = fread(buf2, sizeof(guchar), header_size, fd_in)) ==
-       header_size)
-    {
-       if ((io_bytes = fwrite(buf2, sizeof(guchar), header_size, fd_out))
-           != header_size)
+
+    /* Write the mapped data out */
+       while((bytes_read = fread( &buf, sizeof(guchar), 1, fd_in)) > 0)
        {
-           eb_debug(DBG_CORE, "error copying au file");
-           fclose(fd_out);
-           fclose(fd_in);
-           return (infile);
+               fwrite(map+buf, sizeof(guchar), 1, fd_out);
        }
-    }
-    else
-    {
-       eb_debug(DBG_CORE, "error copying au file");
+
        fclose(fd_in);
        fclose(fd_out);
-       return(infile);
-    }
-
-    /* Write the mapped data out */
-    while((bytes_read = fread( &buf, sizeof(guchar), 1, fd_in)) > 0)
-    {
-       fwrite(map+buf, sizeof(guchar), 1, fd_out);
-    }
-    fclose(fd_in);
-    fclose(fd_out);
 #endif
 
     return outfile;
@@ -657,8 +664,9 @@
 
 void play_sound(int sound)
 {
-       if (do_no_sound_when_away && is_away)
+       if ( iGetLocalPref("do_no_sound_when_away") && is_away )
            return;
+               
        switch(sound) 
        {
                case BUDDY_AWAY:





reply via email to

[Prev in Thread] Current Thread [Next in Thread]