shithub: sox

Download patch

ref: d2db94200b3d454bdd5714b7218bb95e7e0bebb4
parent: 163338036c534ea846d49fac6cdeeaa3923acae9
author: robs <robs>
date: Tue Jun 19 04:01:18 EDT 2007

sox namespace clean-ups

--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -167,7 +167,7 @@
   ima-fmt
   ima_rw
   la-fmt
-  lpc10
+  lpc10.c
   lu-fmt
   maud
   nulfile
--- a/src/adpcms.c
+++ b/src/adpcms.c
@@ -134,8 +134,8 @@
 static int adpcm_start(sox_format_t * ft, adpcm_io_t state, sox_encoding_t type)
 {
   /* setup file info */
-  state->file.buf = (char *) xmalloc(sox_bufsiz);
-  state->file.size = sox_bufsiz;
+  state->file.buf = (char *) xmalloc(sox_globals.bufsiz);
+  state->file.size = sox_globals.bufsiz;
   ft->signal.channels = 1;
 
   sox_adpcm_reset(state, type);
--- a/src/alsa.c
+++ b/src/alsa.c
@@ -289,8 +289,8 @@
         goto open_error;
     }
 
-    /* Have a much larger buffer than sox_bufsiz to avoid underruns */
-    buffer_size = sox_bufsiz * 8 / ft->signal.size / ft->signal.channels;
+    /* Have a much larger buffer than sox_globals.bufsiz to avoid underruns */
+    buffer_size = sox_globals.bufsiz * 8 / ft->signal.size / ft->signal.channels;
 
     if (snd_pcm_hw_params_get_buffer_size_min(hw_params, &buffer_size_min) < 0)
     {
--- a/src/auto.c
+++ b/src/auto.c
@@ -149,18 +149,12 @@
     if (type == NULL)
       type = find_file_extension(ft->filename);
 
-    if (type == NULL) {
-      sox_fail_errno(ft,SOX_EFMT, "Could not determine file type.");
-      return SOX_EOF;
-    }
     free(ft->filetype);
-    ft->filetype = strdup(type);
+    ft->filetype = xstrdup(type);
+    ft->mode = 'r';
     rc = sox_gettype(ft, sox_true); /* Change ft->h to the new format */
-    if(rc != SOX_SUCCESS)
-    {
-        sox_fail_errno(ft,SOX_EFMT,"Do not understand format type: %s",type);
-        return (rc);
-    }
+    if (rc != SOX_SUCCESS)
+      return (rc);
 
     sox_debug("Detected file format type: %s", type);
     set_endianness_if_not_already_set(ft);
--- a/src/biquad.h
+++ b/src/biquad.h
@@ -82,6 +82,6 @@
                         sox_size_t *isamp, sox_size_t *osamp);
 
 #undef sox_fail
-#define sox_fail sox_message_filename=effp->handler.name,sox_fail
+#define sox_fail sox_globals.subsystem=effp->handler.name,sox_fail
 
 #endif
--- a/src/effects.c
+++ b/src/effects.c
@@ -24,10 +24,13 @@
 
 #undef sox_fail
 #undef sox_report
-#define sox_fail sox_message_filename=effp->handler.name,sox_fail
-#define sox_report sox_message_filename=effp->handler.name,sox_report
+#define sox_fail sox_globals.subsystem=effp->handler.name,sox_fail
+#define sox_report sox_globals.subsystem=effp->handler.name,sox_report
 
 
+sox_effects_globals_t sox_effects_globals =
+    {sox_false, 1, &sox_globals};
+
 int sox_usage(sox_effect_t * effp)
 {
   if (effp->handler.usage)
@@ -70,7 +73,7 @@
 {
   assert(eh);
   memset(effp, 0, sizeof(*effp));
-  effp->global_info = &effects_global_info;
+  effp->global_info = &sox_effects_globals;
   effp->handler = *eh;
   if (!effp->handler.getopts) effp->handler.getopts = default_getopts;
   if (!effp->handler.start  ) effp->handler.start   = default_function;
@@ -90,7 +93,7 @@
 /* Effect can call in start() or flow() to set minimum input size to flow() */
 int sox_effect_set_imin(sox_effect_t * effp, sox_size_t imin)
 {
-  if (imin > sox_bufsiz / effp->flows) {
+  if (imin > sox_globals.bufsiz / effp->flows) {
     sox_fail("sox_bufsiz not big enough");
     return SOX_EOF;
   }
@@ -169,7 +172,7 @@
   sox_size_t i, f;
   const sox_ssample_t *ibuf;
   sox_size_t idone = effp1->olen - effp1->odone;
-  sox_size_t odone = sox_bufsiz - effp->olen;
+  sox_size_t odone = sox_globals.bufsiz - effp->olen;
 
   if (effp->flows == 1)       /* Run effect on all channels at once */
     effstatus = effp->handler.flow(effp, &effp1->obuf[effp1->odone],
@@ -226,7 +229,7 @@
   sox_effect_t * effp = &sox_effects[n][0];
   int effstatus = SOX_SUCCESS;
   sox_size_t i, f;
-  sox_size_t odone = sox_bufsiz - effp->olen;
+  sox_size_t odone = sox_globals.bufsiz - effp->olen;
 
   if (effp->flows == 1)   /* Run effect on all channels at once */
     effstatus = effp->handler.drain(effp, &effp->obuf[effp->olen], &odone);
@@ -269,7 +272,7 @@
   sox_bool draining = sox_true;
 
   for (e = 0; e < sox_neffects; ++e) {
-    sox_effects[e][0].obuf = xmalloc(sox_bufsiz * sizeof(sox_effects[e][0].obuf[0]));
+    sox_effects[e][0].obuf = xmalloc(sox_globals.bufsiz * sizeof(sox_effects[e][0].obuf[0]));
     sox_effects[e][0].odone = sox_effects[e][0].olen = 0;
     max_flows = max(max_flows, sox_effects[e][0].flows);
   }
@@ -277,8 +280,8 @@
   ibufc = xcalloc(max_flows, sizeof(*ibufc));
   obufc = xcalloc(max_flows, sizeof(*obufc));
   for (f = 0; f < max_flows; ++f) {
-    ibufc[f] = xcalloc(sox_bufsiz / 2, sizeof(ibufc[f][0]));
-    obufc[f] = xcalloc(sox_bufsiz / 2, sizeof(obufc[f][0]));
+    ibufc[f] = xcalloc(sox_globals.bufsiz / 2, sizeof(ibufc[f][0]));
+    obufc[f] = xcalloc(sox_globals.bufsiz / 2, sizeof(obufc[f][0]));
   }
 
   e = sox_neffects - 1;
--- a/src/flac.c
+++ b/src/flac.c
@@ -313,7 +313,7 @@
     sox_fail_errno(ft, SOX_ENOMEM, "FLAC ERROR creating the encoder instance");
     return SOX_EOF;
   }
-  encoder->decoded_samples = xmalloc(sox_bufsiz * sizeof(FLAC__int32));
+  encoder->decoded_samples = xmalloc(sox_globals.bufsiz * sizeof(FLAC__int32));
 
   {     /* Select and set FLAC encoder options: */
     static struct {
--- a/src/formats.c
+++ b/src/formats.c
@@ -27,3 +27,19 @@
   };
   unsigned sox_formats = array_length(sox_format_fns);
 #endif 
+
+/* Find a named format in the formats library */
+sox_format_handler_t const * sox_find_format(char const * name, sox_bool no_dev)
+{
+  int f, n;
+
+  for (f = 0; f < sox_formats; ++f) {
+    sox_format_handler_t const * fh = sox_format_fns[f].fn();
+
+    if (!(no_dev && (fh->flags & SOX_FILE_DEVICE)))
+      for (n = 0; fh->names[n]; ++n)
+        if (!strcasecmp(fh->names[n], name))
+          return fh;                 /* Found it. */
+  }
+  return NULL;
+}
--- a/src/mcompand.c
+++ b/src/mcompand.c
@@ -300,7 +300,7 @@
       return SOX_SUCCESS;
 }
 
-static int sox_mcompand_getopts(sox_effect_t * effp, int n, char **argv) 
+static int getopts(sox_effect_t * effp, int n, char **argv) 
 {
   char *subargv[6], *cp;
   sox_size_t subargc, i, len;
@@ -348,7 +348,7 @@
  * Prepare processing.
  * Do all initializations.
  */
-static int sox_mcompand_start(sox_effect_t * effp)
+static int start(sox_effect_t * effp)
 {
   compand_t c = (compand_t) effp->priv;
   comp_band_t l;
@@ -477,7 +477,7 @@
  * Processed signed long samples from ibuf to obuf.
  * Return number of samples processed.
  */
-static int sox_mcompand_flow(sox_effect_t * effp, const sox_ssample_t *ibuf, sox_ssample_t *obuf, 
+static int flow(sox_effect_t * effp, const sox_ssample_t *ibuf, sox_ssample_t *obuf, 
                      sox_size_t *isamp, sox_size_t *osamp) {
   compand_t c = (compand_t) effp->priv;
   comp_band_t l;
@@ -553,7 +553,7 @@
 /*
  * Drain out compander delay lines. 
  */
-static int sox_mcompand_drain(sox_effect_t * effp, sox_ssample_t *obuf, sox_size_t *osamp)
+static int drain(sox_effect_t * effp, sox_ssample_t *obuf, sox_size_t *osamp)
 {
   sox_size_t band, drained, mostdrained = 0;
   compand_t c = (compand_t)effp->priv;
@@ -578,7 +578,7 @@
 /*
  * Clean up compander effect.
  */
-static int sox_mcompand_stop(sox_effect_t * effp)
+static int stop(sox_effect_t * effp)
 {
   compand_t c = (compand_t) effp->priv;
   comp_band_t l;
@@ -603,7 +603,7 @@
   return SOX_SUCCESS;
 }
 
-static int sox_mcompand_kill(sox_effect_t * effp)
+static int kill(sox_effect_t * effp)
 {
   compand_t c = (compand_t) effp->priv;
   comp_band_t l;
@@ -622,25 +622,20 @@
   return SOX_SUCCESS;
 }
 
-static sox_effect_handler_t sox_mcompand_effect = {
-  "mcompand",
-  "quoted_compand_args [crossover_frequency quoted_compand_args [...]]\n"
-  "\n"
-  "quoted_compand_args are as for the compand effect:\n"
-  "\n"
-  "  attack1,decay1[,attack2,decay2...]\n"
-  "                 in-dB1,out-dB1[,in-dB2,out-dB2...]\n"
-  "                [ gain [ initial-volume [ delay ] ] ]\n",
-  SOX_EFF_MCHAN,
-  sox_mcompand_getopts,
-  sox_mcompand_start,
-  sox_mcompand_flow,
-  sox_mcompand_drain,
-  sox_mcompand_stop,
-  sox_mcompand_kill
-};
-
 const sox_effect_handler_t *sox_mcompand_effect_fn(void)
 {
-    return &sox_mcompand_effect;
+  static sox_effect_handler_t handler = {
+    "mcompand",
+    "quoted_compand_args [crossover_frequency quoted_compand_args [...]]\n"
+    "\n"
+    "quoted_compand_args are as for the compand effect:\n"
+    "\n"
+    "  attack1,decay1[,attack2,decay2...]\n"
+    "                 in-dB1,out-dB1[,in-dB2,out-dB2...]\n"
+    "                [ gain [ initial-volume [ delay ] ] ]\n",
+    SOX_EFF_MCHAN,
+    getopts, start, flow, drain, stop, kill
+  };
+
+  return &handler;
 }
--- a/src/mp3.c
+++ b/src/mp3.c
@@ -23,7 +23,7 @@
 #include <math.h>
 #endif
 
-#define INPUT_BUFFER_SIZE       (sox_bufsiz)
+#define INPUT_BUFFER_SIZE       (sox_globals.bufsiz)
 
 /* Private data */
 struct mp3priv {
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -231,7 +231,7 @@
       if (c_min>cost) {
         c_min = cost;
         u_min = u;
-        if (sox_output_verbosity_level >= 4) {
+        if (sox_globals.verbosity >= 4) {
           sox_debug("c_min %d, [%d-%d]:",c_min,numer,denom);
           for (j=0; j<u; j++)
             sox_debug(" (%d,%d)",rate->m1[j],rate->m2[j]);
--- a/src/sox.c
+++ b/src/sox.c
@@ -141,7 +141,7 @@
 
 static void output_message(unsigned level, const char *filename, const char *fmt, va_list ap)
 {
-  if (sox_output_verbosity_level >= level) {
+  if (sox_globals.verbosity >= level) {
     fprintf(stderr, "%s ", myname);
     sox_output_message(stderr, filename, fmt, ap);
     fprintf(stderr, "\n");
@@ -503,7 +503,7 @@
 
   myname = argv[0];
   atexit(cleanup);
-  sox_output_message_handler = output_message;
+  sox_globals.output_message_handler = output_message;
 
   if (strends(myname, "play")) {
     play = sox_true;
@@ -764,7 +764,7 @@
         sox_fail("Buffer size `%s' must be > %d", optarg, SOX_BUFMIN);
         exit(1);
         }
-        sox_bufsiz = i;
+        sox_globals.bufsiz = i;
         break;
 
       case 1:
@@ -796,7 +796,7 @@
         break;
 
       case 7:
-        effects_global_info.plot = enum_option(option_index, plot_methods);
+        sox_effects_globals.plot = enum_option(option_index, plot_methods);
         break;
 
       case 8:
@@ -905,14 +905,14 @@
 
     case 'V':
       if (optarg == NULL)
-        ++sox_output_verbosity_level;
+        ++sox_globals.verbosity;
       else {
         if (sscanf(optarg, "%i %c", &i, &dummy) != 1 || i < 0) {
-          sox_output_verbosity_level = 2;
+          sox_globals.verbosity = 2;
           sox_fail("Verbosity value `%s' is not a non-negative integer", optarg);
           exit(1);
         }
-        sox_output_verbosity_level = (unsigned)i;
+        sox_globals.verbosity = (unsigned)i;
       }
       break;
     }
@@ -990,7 +990,7 @@
 
 static void report_file_info(file_t f)
 {
-  if (sox_output_verbosity_level > 2)
+  if (sox_globals.verbosity > 2)
     display_file_info(f, sox_true);
 }
 
@@ -1002,7 +1002,7 @@
   }
   read_wide_samples = 0;
   input_wide_samples = f->ft->length / f->ft->signal.channels;
-  if (show_progress && (sox_output_verbosity_level < 3 ||
+  if (show_progress && (sox_globals.verbosity < 3 ||
                         (combine_method <= sox_concatenate && input_count > 1)))
     display_file_info(f, sox_false);
   if (f->volume == HUGE_VAL)
@@ -1079,7 +1079,7 @@
   else {
     ws = 0;
     for (i = 0; i < input_count; i++) {
-      z->ibuf[i] = (sox_ssample_t *)xmalloc(sox_bufsiz * sizeof(sox_ssample_t));
+      z->ibuf[i] = (sox_ssample_t *)xmalloc(sox_globals.bufsiz * sizeof(sox_ssample_t));
       progress_to_file(files[i]);
       ws = max(ws, input_wide_samples);
     }
@@ -1403,7 +1403,7 @@
   if (ofile->signal.channels == 0)
     ofile->signal.channels = combiner.channels;
 
-  combiner.rate = combiner.rate * effects_global_info.speed;
+  combiner.rate = combiner.rate * sox_effects_globals.speed;
 
   for (i = 0; i < nuser_effects; i++)
     known_length = known_length && !(user_efftab[i].handler.flags & SOX_EFF_LENGTH);
--- a/src/sox.h
+++ b/src/sox.h
@@ -34,8 +34,6 @@
 
 const char *sox_version(void);   /* Returns version number */
 
-extern char const * sox_message_filename;
-
 #define SOX_SUCCESS 0
 #define SOX_EOF (-1)             /* End Of File or other error */
 
@@ -207,19 +205,7 @@
   SOX_ENCODINGS            /* End of list marker */
 } sox_encoding_t;
 
-typedef struct sox_global_info /* Global parameters (for effects & formats) */
-{
-  char const * stdin_in_use_by;
-  char const * stdout_in_use_by;
-} sox_global_info_t;
-
 typedef enum {sox_plot_off, sox_plot_octave, sox_plot_gnuplot} sox_plot_t;
-
-typedef struct sox_formats_global_info /* Global parameters (for formats) */
-{
-  sox_global_info_t * global_info;
-} sox_formats_global_info_t;
-
 typedef enum {SOX_OPTION_NO, SOX_OPTION_YES, SOX_OPTION_DEFAULT} sox_option_t;
 
 /* Signal parameters */
@@ -385,6 +371,7 @@
 #define SOX_SEEK_SET 0
 int sox_seek(sox_format_t * ft, sox_size_t offset, int whence);
 
+sox_format_handler_t const * sox_find_format(char const * name, sox_bool no_dev);
 int sox_gettype(sox_format_t *, sox_bool);
 sox_format_t * sox_initformat(void);
 
@@ -392,13 +379,6 @@
  * Structures for effects.
  */
 
-typedef struct sox_effects_global_info /* Global parameters (for effects) */
-{
-  sox_plot_t plot;         /* To help the user choose effect & options */
-  double speed;            /* Gather up all speed changes here, then resample */
-  sox_global_info_t * global_info;
-} sox_effects_global_info_t;
-
 #define SOX_MAX_EFFECT_PRIVSIZE SOX_MAX_FILE_PRIVSIZE
 
 #define SOX_EFF_CHAN     1           /* Effect can alter # of channels */
@@ -410,6 +390,7 @@
 #define SOX_EFF_DEPRECATED 64        /* Effect is living on borrowed time */
 
 typedef struct sox_effect sox_effect_t;
+typedef struct sox_effects_globals sox_effects_globals_t;
 
 typedef struct {
   char const * name;
@@ -430,7 +411,7 @@
    * in memory in the optimal way for any structure to be cast over it. */
   char priv[SOX_MAX_EFFECT_PRIVSIZE];    /* private area for effect */
 
-  struct sox_effects_global_info * global_info; /* global parameters */
+  sox_effects_globals_t * global_info; /* global parameters */
   struct sox_signalinfo    ininfo;       /* input signal specifications */
   struct sox_signalinfo    outinfo;      /* output signal specifications */
   sox_effect_handler_t     handler;
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -199,8 +199,6 @@
 
 /* util.c */
 typedef void (*sox_output_message_handler_t)(unsigned level, const char *filename, const char *fmt, va_list ap);
-extern sox_output_message_handler_t sox_output_message_handler;
-extern unsigned sox_output_verbosity_level;
 void sox_output_message(FILE *file, const char *filename, const char *fmt, va_list ap);
 
 void sox_fail(const char *, ...);
@@ -210,12 +208,12 @@
 void sox_debug_more(char const * fmt, ...);
 void sox_debug_most(char const * fmt, ...);
 
-#define sox_fail       sox_message_filename=__FILE__,sox_fail
-#define sox_warn       sox_message_filename=__FILE__,sox_warn
-#define sox_report     sox_message_filename=__FILE__,sox_report
-#define sox_debug      sox_message_filename=__FILE__,sox_debug
-#define sox_debug_more sox_message_filename=__FILE__,sox_debug_more
-#define sox_debug_most sox_message_filename=__FILE__,sox_debug_most
+#define sox_fail       sox_globals.subsystem=__FILE__,sox_fail
+#define sox_warn       sox_globals.subsystem=__FILE__,sox_warn
+#define sox_report     sox_globals.subsystem=__FILE__,sox_report
+#define sox_debug      sox_globals.subsystem=__FILE__,sox_debug
+#define sox_debug_more sox_globals.subsystem=__FILE__,sox_debug_more
+#define sox_debug_most sox_globals.subsystem=__FILE__,sox_debug_most
 
 void sox_fail_errno(sox_format_t *, int, const char *, ...);
 
@@ -234,13 +232,36 @@
 #define M_PI_2  1.57079632679489661923  /* pi/2 */
 #endif
 
+typedef struct sox_globals /* Global parameters (for effects & formats) */
+{
+  unsigned     verbosity;
 /* The following is used at times in libsox when alloc()ing buffers
  * to perform file I/O.  It can be useful to pass in similar sized
  * data to get max performance.
  */
-extern sox_size_t sox_bufsiz;
-extern sox_global_info_t sox_global_info;
-extern sox_effects_global_info_t effects_global_info;
+  sox_size_t   bufsiz;
+  char const * stdin_in_use_by;
+  char const * stdout_in_use_by;
+  sox_output_message_handler_t output_message_handler;
+  char const * subsystem;
+
+} sox_globals_t;
+
+struct sox_effects_globals /* Global parameters (for effects) */
+{
+  sox_plot_t plot;         /* To help the user choose effect & options */
+  double speed;            /* Gather up all speed changes here, then resample */
+  sox_globals_t * global_info;
+};
+
+typedef struct sox_formats_globals /* Global parameters (for formats) */
+{
+  sox_globals_t * global_info;
+} sox_formats_globals;
+
+
+extern sox_globals_t sox_globals;
+extern sox_effects_globals_t sox_effects_globals;
 
 extern const char sox_readerr[];
 extern const char sox_writerr[];
--- a/src/soxio.c
+++ b/src/soxio.c
@@ -11,7 +11,24 @@
   #include <io.h>
 #endif
 
+sox_globals_t sox_globals = {2, 8192, NULL, NULL, NULL, NULL};
 
+/*
+ * Check that we have a known format suffix string.
+ */
+int sox_gettype(sox_format_t * ft, sox_bool is_file_extension)
+{
+  if (!ft->filetype)
+    sox_fail_errno(ft, SOX_EFMT, "unknown file type");
+  else {
+    ft->handler = sox_find_format(ft->filetype, is_file_extension);
+    if (ft->handler)
+      return SOX_SUCCESS;
+    sox_fail_errno(ft, SOX_EFMT, "unknown file type `%s'", ft->filetype);
+  }
+  return SOX_EFMT;
+}
+
 void set_endianness_if_not_already_set(sox_format_t * ft)
 {
   if (ft->signal.reverse_bytes == SOX_OPTION_DEFAULT) {
@@ -95,19 +112,16 @@
     else
         ft->filetype = xstrdup(filetype);
 
+    ft->mode = 'r';
     if (sox_gettype(ft, sox_false) != SOX_SUCCESS) {
-        sox_fail("Unknown input file format for `%s': %s",
-                ft->filename,
-                ft->sox_errstr);
-        goto input_error;
+      sox_fail("Failed reading `%s': %s", ft->filename, ft->sox_errstr);
+      goto input_error;
     }
-
     ft->signal.size = -1;
     ft->signal.encoding = SOX_ENCODING_UNKNOWN;
     ft->signal.channels = 0;
     if (info)
         ft->signal = *info;
-    ft->mode = 'r';
 
     if (!(ft->handler->flags & SOX_FILE_NOSTDIO))
     {
@@ -115,11 +129,11 @@
          * if the filename is "-"
          */
         if (!strcmp(ft->filename, "-")) {
-          if (sox_global_info.stdin_in_use_by) {
-            sox_fail("'-' (stdin) already in use by '%s'", sox_global_info.stdin_in_use_by);
+          if (sox_globals.stdin_in_use_by) {
+            sox_fail("'-' (stdin) already in use by '%s'", sox_globals.stdin_in_use_by);
             goto input_error;
           }
-          sox_global_info.stdin_in_use_by = "audio input";
+          sox_globals.stdin_in_use_by = "audio input";
           SET_BINARY_MODE(stdin);
           ft->fp = stdin;
         }
@@ -190,20 +204,16 @@
     } else
       ft->filetype = xstrdup(filetype);
 
-    if (!ft->filetype || sox_gettype(ft, no_filetype_given) != SOX_SUCCESS)
-    {
-        sox_fail("Unknown output file format for '%s':  %s",
-                ft->filename,
-                ft->sox_errstr);
-        goto output_error;
+    ft->mode = 'w';
+    if (sox_gettype(ft, no_filetype_given) != SOX_SUCCESS) {
+      sox_fail("Failed writing `%s': %s", ft->filename, ft->sox_errstr);
+      goto output_error;
     }
-
     ft->signal.size = -1;
     ft->signal.encoding = SOX_ENCODING_UNKNOWN;
     ft->signal.channels = 0;
     if (info)
         ft->signal = *info;
-    ft->mode = 'w';
 
     if (!(ft->handler->flags & SOX_FILE_NOSTDIO))
     {
@@ -211,11 +221,11 @@
          * if the filename is "-"
          */
         if (!strcmp(ft->filename, "-")) {
-          if (sox_global_info.stdout_in_use_by) {
-            sox_fail("'-' (stdout) already in use by '%s'", sox_global_info.stdout_in_use_by);
+          if (sox_globals.stdout_in_use_by) {
+            sox_fail("'-' (stdout) already in use by '%s'", sox_globals.stdout_in_use_by);
             goto output_error;
           }
-          sox_global_info.stdout_in_use_by = "audio output";
+          sox_globals.stdout_in_use_by = "audio output";
             SET_BINARY_MODE(stdout);
             ft->fp = stdout;
         }
@@ -235,7 +245,7 @@
 
         /* stdout tends to be line-buffered.  Override this */
         /* to be Full Buffering. */
-        if (setvbuf (ft->fp, NULL, _IOFBF, sizeof(char)*sox_bufsiz))
+        if (setvbuf (ft->fp, NULL, _IOFBF, sizeof(char) * sox_globals.bufsiz))
         {
             sox_fail("Can't set write buffer");
             goto output_error;
@@ -261,7 +271,7 @@
     /* Read and write starters can change their formats. */
     if (ft->handler->startwrite && (*ft->handler->startwrite)(ft) != SOX_SUCCESS)
     {
-        sox_fail("Failed writing %s: %s", ft->filename, ft->sox_errstr);
+        sox_fail("Failed writing `%s': %s", ft->filename, ft->sox_errstr);
         goto output_error;
     }
 
--- a/src/util.c
+++ b/src/util.c
@@ -18,15 +18,6 @@
 #include <ctype.h>
 #include <stdarg.h>
 
-sox_size_t sox_bufsiz = 8192;
-sox_output_message_handler_t sox_output_message_handler = NULL;
-unsigned sox_output_verbosity_level = 2;
-
-sox_global_info_t sox_global_info;
-
-sox_effects_global_info_t effects_global_info =
-    {sox_false, 1, &sox_global_info};
-
 void sox_output_message(FILE *file, const char *filename, const char *fmt, va_list ap)
 {
   char buffer[10];
@@ -55,25 +46,12 @@
   vfprintf(file, fmt, ap);
 }
 
-
-
-/* This is a bit of a hack.  It's useful to have libSoX
- * report which format or effect handler is outputing
- * the message.  Using the filename for this purpose is only an
- * approximation, but it saves a lot of work. ;)
- */
-char const * sox_message_filename = 0;
-
-
-
 static void sox_emit_message(unsigned level, char const *fmt, va_list ap)
 {
-  if (sox_output_message_handler != NULL)
-    (*sox_output_message_handler)(level, sox_message_filename, fmt, ap);
+  if (sox_globals.output_message_handler != NULL)
+    (*sox_globals.output_message_handler)(level, sox_globals.subsystem, fmt, ap);
 }
 
-
-
 #undef sox_fail
 #undef sox_warn
 #undef sox_report
@@ -114,38 +92,6 @@
 #endif
         va_end(args);
         ft->sox_errstr[255] = '\0';
-}
-
-/*
- * Check that we have a known format suffix string.
- */
-int sox_gettype(sox_format_t * ft, sox_bool is_file_extension)
-{
-    const char * const *list;
-    unsigned i;
-
-    if (!ft->filetype) {
-        sox_fail_errno(ft, SOX_EFMT, "Filetype was not specified");
-        return SOX_EFMT;
-    }
-    for (i = 0; i < sox_formats; i++) {
-      const sox_format_handler_t *f = sox_format_fns[i].fn();
-      if (is_file_extension && (f->flags & SOX_FILE_DEVICE))
-        continue; /* don't match device name in file name extensions */
-      for (list = f->names; *list; list++) {
-        const char *s1 = *list, *s2 = ft->filetype;
-        if (!strcasecmp(s1, s2))
-          break;  /* not a match */
-      }
-      if (!*list)
-        continue;
-      /* Found it! */
-      ft->handler = f;
-      return SOX_SUCCESS;
-    }
-    sox_fail_errno(ft, SOX_EFMT, "File type `%s' is not known",
-                  ft->filetype);
-    return SOX_EFMT;
 }
 
 /*