shithub: sox

Download patch

ref: a0c901139bb95baee5674c4fd86bba3d4b179a8c
parent: 7de73b76a65b8f4121cea3c1f573e9f0c16f5aa8
author: rrt <rrt>
date: Thu Jan 11 15:51:19 EST 2007

Compile skelform.c and skeleff.c. However, they are not added to the
handlers, so they can't be used. At the moment this is a good thing as
they're almost certainly crash-inducing.

At some point, however, tests should be added so this effect and
format can be run and tested, showing that they not only compile, but
run!

--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,7 +17,7 @@
 	  cdr.c cvsd.c cvsdfilt.h dat.c flac.c g711.c g711.h g721.c \
 	  g723_16.c g723_24.c g723_40.c g72x.c g72x.h gsm.c hcom.c \
 	  ima_rw.c ima_rw.h maud.c mp3.c nulfile.c prc.c \
-	  raw.c sf.c sfircam.h smp.c sndrtool.c sphere.c tx16w.c voc.c \
+	  raw.c sf.c sfircam.h skelform.c smp.c sndrtool.c sphere.c tx16w.c voc.c \
 	  vorbis.c vox.c wav.c wav.h wve.c xa.c
 
 effects = avg.c band.c bandpass.c biquad.c biquad.h breject.c btrworth.c \
@@ -26,11 +26,11 @@
 	  highp.c highpass.c lowp.c lowpass.c luaeff.c luaform.c \
 	  lintlib.c mask.c mcompand.c noiseprof.c noisered.c noisered.h \
 	  pad.c pan.c phaser.c pitch.c polyphas.c rabbit.c rate.c repeat.c \
-	  resample.c reverb.c reverse.c silence.c speed.c stat.c stlua.c \
+	  resample.c reverb.c reverse.c silence.c skeleff.c speed.c stat.c \
 	  stretch.c swap.c synth.c tone.c trim.c vibro.c vol.c
 
 libst_la_SOURCES = $(formats) $(effects) alsa.c oss.c sunaudio.c handlers.c misc.c \
-	  st_i.h stio.c util.c xmalloc.c xmalloc.h getopt.c getopt1.c getopt.h
+	  st_i.h stio.c stlua.c util.c xmalloc.c xmalloc.h getopt.c getopt1.c getopt.h
 
 sox_SOURCES = sox.c
 sox_LDADD = libst.la libgsm/libgsm.la $(LUA_LIBS)
--- a/src/skelform.c
+++ b/src/skelform.c
@@ -20,10 +20,12 @@
 
 #include "st_i.h"
 
+#include <string.h>
+
 /* Private data for SKEL file */
 typedef struct skelform
 {
-  st_size_t samples_remaining;
+  st_size_t remaining_samples;
 } *skelform_t;
 
 assert_static(sizeof(struct skelform) <= ST_MAX_FILE_PRIVSIZE, 
@@ -42,11 +44,12 @@
 static int skel_startread(ft_t ft)
 {
   skelform_t sk = (skelform_t)ft->priv;
+  st_size_t samples_in_file;
 
   /* If you need to seek around the input file. */
   if (!ft->seekable) {
-    st_fail_errno(ft,ST_EVALUE,"SKEL input file must be a file, not a pipe");
-    return (ST_EOF);
+    st_fail_errno(ft, ST_EOF, "skel inputfile must be a file");
+    return ST_EOF;
   }
 
   /*
@@ -56,11 +59,14 @@
    * then you should set it here.
    */
   ft->signal.rate =  44100L;
-  ft->signal.size = ST_SIZE_BYTE or WORD ...;
-  ft->signal.encoding = ST_ENCODING_UNSIGNED or SIGN2 ...;
-  ft->signal.channels = 1 or 2 or 4;
-  ft->comment = xmalloc(size_of_comment);
-  strcpy(ft->comment, "any comment in file header.");
+  ft->signal.size = ST_SIZE_BYTE; /* or WORD ... */
+  ft->signal.encoding = ST_ENCODING_UNSIGNED; /* or SIGN2 ... */
+  ft->signal.channels = 1; /* or 2 or 4 */
+  {
+    char *comment = "any comment in file header.";
+    ft->comment = xmalloc(sizeof(comment));
+    strcpy(ft->comment, comment);
+  }
 
   /* If your format doesn't have a header then samples_in_file
    * can be determined by the file size.
@@ -71,7 +77,7 @@
   ft->length = samples_in_file;
   sk->remaining_samples = samples_in_file;
 
-  return (ST_SUCCESS);
+  return ST_SUCCESS;
 }
 
 /*
@@ -82,7 +88,7 @@
 {
   skelform_t sk = (skelform_t)ft->priv;
   st_size_t done;
-  st_sample_t l;
+  unsigned char sample;
 
   /* Always return a full frame of audio data */
   if (len % ft->signal.size)
@@ -89,18 +95,24 @@
     len -= (len % ft->signal.size);
 
   for (done = 0; done < len; done++) {
-    if no more samples
-            break
-            get a sample
-            switch (ft->signal.size) {
-            case ST_SIZE_BYTE:
-              switch (ft->signal.encoding) {
-                case ST_ENCODING_UNSIGNED;
-                *buf++ = ST_UNSIGNED_BYTE_TO_SAMPLE(sample);
-                break;
-              }
-              break;
-            }
+    if (feof(ft->fp)) /* no more samples */
+      break;
+    sample = fgetc(ft->fp);
+    switch (ft->signal.size) {
+    case ST_SIZE_BYTE:
+      switch (ft->signal.encoding) {
+      case ST_ENCODING_UNSIGNED:
+        *buf++ = ST_UNSIGNED_BYTE_TO_SAMPLE(sample,);
+        break;
+      default:
+        st_fail("Undetected sample encoding in skel_read!");
+        exit(2);
+      }
+      break;
+    default:
+      st_fail("Undetected bad sample size in skel_read!");
+      exit(2);
+    }
   }
 
   return done;
@@ -125,20 +137,20 @@
    * just set the length to max value and not fail.
    */
   if (!ft->seekable) {
-    st_fail_errno(ft, ST_EVALUE, "Output .skel file must be a file, not a pipe");
+    st_fail("Output .skel file must be a file, not a pipe");
     return ST_EOF;
   }
 
   if (ft->signal.rate != 44100L)
-    st_fail_errno(ft, ST_EVALUE, "Output .skel file must have a sample rate of 44100");
+    st_fail("Output .skel file must have a sample rate of 44100Hz");
 
   if (ft->signal.size == -1) {
-    st_fail_errno(ft, ST_EVALUE, "Did not specify a size for .skel output file");
+    st_fail("Did not specify a size for .skel output file");
     return ST_EOF;
   }
 
-  error check ft->signal.encoding;
-  error check ft->signal.channels;
+  /* error check ft->signal.encoding */
+  /* error check ft->signal.channels */
 
   /* Write file header, if any */
   /* Write comment field, if any */
@@ -154,7 +166,6 @@
 static st_size_t skel_write(ft_t ft, const st_sample_t *buf, st_size_t len)
 {
   skelform_t sk = (skelform_t)ft->priv;
-  st_size_t len = 0;
 
   switch (ft->signal.size) {
   case ST_SIZE_BYTE:
@@ -161,13 +172,19 @@
     switch (ft->signal.encoding) {
     case ST_ENCODING_UNSIGNED:
       while (len--) {
-        len = st_writeb(ft, ST_SAMPLE_TO_UNSIGNED_BYTE(*buff++, ft->clippedCount));
-        if (len == ST_EOF)
+        len = st_writeb(ft, ST_SAMPLE_TO_UNSIGNED_BYTE(*buf++, ft->clippedCount));
+        if (len == 0)
           break;
       }
       break;
+    default:
+      st_fail("Undetected bad sample encoding in skel_read!");
+      exit(2);
     }
     break;
+  default:
+    st_fail("Undetected bad sample size in skel_read!");
+    exit(2);
   }
 
   return len;
@@ -207,7 +224,7 @@
   skel_seek
 };
 
-const st_format_t *st_skel_format_fn()
+const st_format_t *st_skel_format_fn(void)
 {
   return &st_skel_format;
 }