shithub: sox

Download patch

ref: 6fa889fc437b8b255663c8292cc8346b9be8be88
parent: b2e9f7d7c45c83bdb435063943b0496f1003f084
author: robs <robs>
date: Sat Apr 11 01:42:11 EDT 2009

tidy/doc the examples a little

--- a/src/example0.c
+++ b/src/example0.c
@@ -17,11 +17,12 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#ifdef NDEBUG /* N.B. assert used with active statements so enable always. */
+#undef NDEBUG /* Must undef above assert.h or other that might include it. */
+#endif
+
 #include "sox.h"
 #include <stdio.h>
-#ifdef NDEBUG /* N.B. assert used with active statements so enable always */
-#undef NDEBUG
-#endif
 #include <assert.h>
 
 /*
--- a/src/example1.c
+++ b/src/example1.c
@@ -17,11 +17,12 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#ifdef NDEBUG /* N.B. assert used with active statements so enable always. */
+#undef NDEBUG /* Must undef above assert.h or other that might include it. */
+#endif
+
 #include "sox.h"
 #include <stdio.h>
-#ifdef NDEBUG /* N.B. assert used with active statements so enable always */
-#undef NDEBUG
-#endif
 #include <assert.h>
 
 static sox_format_t * in, * out; /* input and output files */
--- a/src/example2.c
+++ b/src/example2.c
@@ -17,13 +17,14 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#ifdef NDEBUG /* N.B. assert used with active statements so enable always. */
+#undef NDEBUG /* Must undef above assert.h or other that might include it. */
+#endif
+
 #include "sox.h"
 #include "util.h"
 #include <stdio.h>
 #include <math.h>
-#ifdef NDEBUG /* N.B. assert used with active statements so enable always */
-#undef NDEBUG
-#endif
 #include <assert.h>
 
 /*
@@ -76,10 +77,10 @@
   /* Allocate a block of memory to store the block of audio samples: */
   assert(buf = malloc(sizeof(sox_sample_t) * block_size));
 
-  /* This application requires that the audio has precisely 2 channels */
+  /* This example program requires that the audio has precisely 2 channels: */
   assert(in->signal.channels == 2);
 
-  /* Read in and process blocks of audio for the selected period or until EOF: */
+  /* Read and process blocks of audio for the selected period or until EOF: */
   for (blocks = 0; sox_read(in, buf, block_size) == block_size && blocks * block_period < period; ++blocks) {
     double left = 0, right = 0;
     size_t i;
--- a/src/example3.c
+++ b/src/example3.c
@@ -17,18 +17,15 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#ifdef NDEBUG /* N.B. assert used with active statements so enable always. */
+#undef NDEBUG /* Must undef above assert.h or other that might include it. */
+#endif
+
 #include "sox.h"
+#include "util.h"
 #include <stdio.h>
-#ifdef NDEBUG /* N.B. assert used with active statements so enable always */
-#undef NDEBUG
-#endif
 #include <assert.h>
 
-#ifdef min
-#undef min
-#endif
-#define min(a, b) ((a) <= (b) ? (a) : (b))
-
 /*
  * Example of a custom output message handler.
  */
@@ -45,6 +42,9 @@
 /*
  * On an alsa capable system, plays an audio file starting 10 seconds in.
  * Copes with sample-rate change if necessary.  E.g. example3 song2.ogg
+ *
+ * Can easily be changed to work with other audio device drivers supported
+ * by libSoX; e.g. "oss", "ao", etc.  See the soxformat(7) manual page.
  */
 int main(int argc, char * argv[])
 {
@@ -59,6 +59,7 @@
 
   assert(sox_init() == SOX_SUCCESS);
   assert(in = sox_open_read(argv[1], NULL, NULL, NULL));
+  /* Change "alsa" in this line to use an alternative audio device driver: */
   assert(out= sox_open_write("default", &in->signal, NULL, "alsa", NULL, NULL));
 
   chain = sox_create_effects_chain(&in->encoding, &out->encoding);
--- a/src/util.h
+++ b/src/util.h
@@ -67,11 +67,11 @@
 #endif
 
 #ifdef WORDS_BIGENDIAN
-#define MACHINE_IS_BIGENDIAN 1
-#define MACHINE_IS_LITTLEENDIAN 0
+  #define MACHINE_IS_BIGENDIAN 1
+  #define MACHINE_IS_LITTLEENDIAN 0
 #else
-#define MACHINE_IS_BIGENDIAN 0
-#define MACHINE_IS_LITTLEENDIAN 1
+  #define MACHINE_IS_BIGENDIAN 0
+  #define MACHINE_IS_LITTLEENDIAN 1
 #endif
 
 /*--------------------------- Language extensions ----------------------------*/