[xiph-commits] r16838 - in trunk/ao: . include/ao src src/plugins/alsa src/plugins/arts src/plugins/esd src/plugins/irix src/plugins/macosx src/plugins/nas src/plugins/oss src/plugins/pulse src/plugins/sun

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Wed Jan 27 22:58:08 PST 2010


Author: xiphmont
Date: 2010-01-27 22:58:08 -0800 (Wed, 27 Jan 2010)
New Revision: 16838

Modified:
   trunk/ao/configure.ac
   trunk/ao/include/ao/ao_private.h
   trunk/ao/src/ao_aixs.c
   trunk/ao/src/ao_au.c
   trunk/ao/src/ao_null.c
   trunk/ao/src/ao_raw.c
   trunk/ao/src/ao_wav.c
   trunk/ao/src/ao_wmm.c
   trunk/ao/src/audio_out.c
   trunk/ao/src/plugins/alsa/ao_alsa.c
   trunk/ao/src/plugins/arts/ao_arts.c
   trunk/ao/src/plugins/esd/ao_esd.c
   trunk/ao/src/plugins/irix/ao_irix.c
   trunk/ao/src/plugins/macosx/ao_macosx.c
   trunk/ao/src/plugins/nas/ao_nas.c
   trunk/ao/src/plugins/oss/ao_oss.c
   trunk/ao/src/plugins/pulse/ao_pulse.c
   trunk/ao/src/plugins/sun/ao_sun.c
Log:
Centralize messaging in the plugins, clean up reporting a bit, make 
messages more consistent, add global 'debug' option



Modified: trunk/ao/configure.ac
===================================================================
--- trunk/ao/configure.ac	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/configure.ac	2010-01-28 06:58:08 UTC (rev 16838)
@@ -191,11 +191,6 @@
 	[include WMM output plugin @<:@default=check@:>@])],
 	[],[enable_wmm="check"]
 )
-AC_ARG_ENABLE([wmm_debug],
-    [AS_HELP_STRING(
-	[--enable-wmm-debug],
-	[enable WMM debugging output @<:@default=no@:>@])]
-)
 AS_IF([test "x$enable_wmm" != "xno"],
 [AC_CHECK_HEADERS([mmsystem.h],
    [
@@ -219,7 +214,6 @@
 ],[],[#include <windows.h>])])
 AM_CONDITIONAL([HAVE_WMM],[test "x$has_wmm" = "xyes"])
 AS_IF([test "x${has_wmm}" = "xyes"],[WMM_LIBS="-lwinmm"],[WMM_LIBS=""])
-AS_IF([test "x${has_wmm}" = "xyes" && test "x$enable_wmm_debug" = "xyes"],[CFLAGS="$CFLAGS -DAO_WMM_DEBUG=1"],[])
 AC_SUBST([WMM_LIBS])
 
 dnl Check for ESD

Modified: trunk/ao/include/ao/ao_private.h
===================================================================
--- trunk/ao/include/ao/ao_private.h	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/include/ao/ao_private.h	2010-01-28 06:58:08 UTC (rev 16838)
@@ -28,7 +28,7 @@
 
 /* --- Operating System Compatibility --- */
 
-/* 
+/*
   OpenBSD systems with a.out binaries require dlsym()ed symbols to be
   prepended with an underscore, so we need the following nasty #ifdef
   hack.
@@ -107,4 +107,52 @@
 void read_config_files (ao_config *config);
 int read_config_file(ao_config *config, const char *config_file);
 
+#define adebug(format, args...) {\
+    if(device->verbose==2){                                             \
+      if(strcmp(format,"\n")){                                          \
+        fprintf(stderr,"ao_%s debug: " format,device->funcs->driver_info()->short_name,## args); \
+      }else{                                                            \
+        fprintf(stderr,"\n");                                           \
+      }                                                                 \
+    }                                                                   \
+  }
+
+#define averbose(format, args...) {\
+    if(device->verbose>0){                                              \
+      if(strcmp(format,"\n")){                                          \
+        fprintf(stderr,"ao_%s info: " format,device->funcs->driver_info()->short_name,## args); \
+      }else{                                                            \
+        fprintf(stderr,"\n");                                           \
+      }                                                                 \
+    }                                                                   \
+  }
+
+#define ainfo(format, args...) {\
+    if(device->verbose>=0){                                             \
+      if(strcmp(format,"\n")){                                          \
+        fprintf(stderr,"ao_%s info: " format,device->funcs->driver_info()->short_name,## args); \
+      }else{                                                            \
+        fprintf(stderr,"\n");                                           \
+      }                                                                 \
+    }                                                                   \
+  }
+
+#define awarn(format, args...) {\
+    if(device->verbose>=0){                                             \
+      if(strcmp(format,"\n")){                                          \
+        fprintf(stderr,"ao_%s WARNING: " format,device->funcs->driver_info()->short_name,## args); \
+      }else{                                                            \
+        fprintf(stderr,"\n");                                           \
+      }                                                                 \
+    }                                                                   \
+  }
+
+#define aerror(format, args...) {                                       \
+    if(strcmp(format,"\n")){                                            \
+      fprintf(stderr,"ao_%s ERROR: " format,device->funcs->driver_info()->short_name,## args); \
+    }else{                                                              \
+      fprintf(stderr,"\n");                                             \
+    }                                                                   \
+  }
+
 #endif /* __AO_PRIVATE_H__ */

Modified: trunk/ao/src/ao_aixs.c
===================================================================
--- trunk/ao/src/ao_aixs.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/ao_aixs.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -52,7 +52,7 @@
 #endif
 
 
-static char *ao_aixs_options[] = {"dev","matrix","verbose","quiet"};
+static char *ao_aixs_options[] = {"dev","matrix","verbose","quiet","debug"};
 ao_info ao_aixs_info = {
 	AO_TYPE_LIVE,
 	"AIX audio driver output",
@@ -62,7 +62,7 @@
 	AO_FMT_NATIVE,
 	20,
 	ao_aixs_options,
-	4
+	5
 };
 
 

Modified: trunk/ao/src/ao_au.c
===================================================================
--- trunk/ao/src/ao_au.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/ao_au.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -68,7 +68,7 @@
 	char info[4]; /* optional text information */
 } Audio_filehdr;
 
-static char *ao_au_options[] = {"matrix","verbose","quiet"};
+static char *ao_au_options[] = {"matrix","verbose","quiet","debug"};
 static ao_info ao_au_info =
 {
 	AO_TYPE_FILE,
@@ -79,7 +79,7 @@
 	AO_FMT_BIG,
 	0,
 	ao_au_options,
-	3
+	4
 };
 
 typedef struct ao_au_internal

Modified: trunk/ao/src/ao_null.c
===================================================================
--- trunk/ao/src/ao_null.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/ao_null.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -33,7 +33,7 @@
 #include <ao/ao.h>
 
 static char *ao_null_options[] = {
-	"debug"
+  "debug","verbose","matrix","quiet"
 };
 static ao_info ao_null_info = {
 	AO_TYPE_LIVE,
@@ -44,13 +44,12 @@
 	AO_FMT_NATIVE,
 	0,
 	ao_null_options,
-	1
+	4
 };
 
 
 typedef struct ao_null_internal {
 	unsigned long byte_counter;
-	int debug_output;
 } ao_null_internal;
 
 
@@ -76,7 +75,6 @@
 		return 0; /* Could not initialize device memory */
 
 	internal->byte_counter = 0;
-	internal->debug_output = 0;
 
 	device->internal = internal;
 
@@ -89,10 +87,6 @@
 {
 	ao_null_internal *internal = (ao_null_internal *) device->internal;
 
-	if (!strcmp(key, "debug")) {
-		internal->debug_output = 1;
-	}
-
 	return 1;
 }
 
@@ -127,10 +121,7 @@
 {
 	ao_null_internal *internal = (ao_null_internal *) device->internal;
 
-	if (internal->debug_output) {
-	  fprintf(stderr, "ao_null: %ld bytes sent to null device.\n",
-		  internal->byte_counter);
-	}
+	adebug("%ld bytes sent to null device.\n");
 
 	return 1;
 }

Modified: trunk/ao/src/ao_raw.c
===================================================================
--- trunk/ao/src/ao_raw.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/ao_raw.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -33,7 +33,7 @@
 #include <ao/ao.h>
 #include <ao/plugin.h>
 
-static char *ao_raw_options[] = {"byteorder","matrix","verbose","quiet"};
+static char *ao_raw_options[] = {"byteorder","matrix","verbose","quiet","debug"};
 static ao_info ao_raw_info =
 {
 	AO_TYPE_FILE,
@@ -44,7 +44,7 @@
 	AO_FMT_NATIVE,
 	0,
 	ao_raw_options,
-	4
+	5
 };
 
 typedef struct ao_raw_internal

Modified: trunk/ao/src/ao_wav.c
===================================================================
--- trunk/ao/src/ao_wav.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/ao_wav.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -90,7 +90,7 @@
 };
 
 
-static char *ao_wav_options[] = {"matrix","verbose","quiet"};
+static char *ao_wav_options[] = {"matrix","verbose","quiet","debug"};
 static ao_info ao_wav_info =
 {
 	AO_TYPE_FILE,
@@ -101,7 +101,7 @@
 	AO_FMT_LITTLE,
 	0,
 	ao_wav_options,
-        3
+        4
 };
 
 typedef struct ao_wav_internal

Modified: trunk/ao/src/ao_wmm.c
===================================================================
--- trunk/ao/src/ao_wmm.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/ao_wmm.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -46,21 +46,6 @@
 #define GALLOC_WVHD_TYPE (GHND)
 #define GALLOC_DATA_TYPE (GHND)
 
-#ifndef AO_WMM_DEBUG
-  #define AO_WMM_DEBUG 0
-#endif
-static int debug_flag = AO_WMM_DEBUG;
-
-static void debug(const char * fmt, ...)
-{
-  if (debug_flag) {
-    va_list list;
-    va_start(list,fmt);
-    vfprintf(stderr,fmt,list);
-    va_end(list);
-  }
-}
-
 static const char * mmerror(MMRESULT mmrError)
 {
   static char mmbuffer[1024];
@@ -72,7 +57,7 @@
   return mmbuffer;
 }
 
-static char * ao_wmm_options[] = {"debug", "dev", "id", "matrix","verbose","quiet"};
+static char * ao_wmm_options[] = {"dev", "id", "matrix","verbose","quiet","debug"};
 static ao_info ao_wmm_info =
   {
     /* type             */ AO_TYPE_LIVE,
@@ -120,13 +105,11 @@
 
 int ao_wmm_test(void)
 {
-  debug("ao_wmm_test() {} => [success]\n");
   return 1; /* This plugin works in default mode */
 }
 
 ao_info *ao_wmm_driver_info(void)
 {
-  debug("ao_wmm_driver_info() {} => [success]\n");
   return &ao_wmm_info;
 }
 
@@ -136,47 +119,28 @@
   ao_wmm_internal *internal = (ao_wmm_internal *) device->internal;
   int res = 0;
 
-  debug("ao_wmm_set_option(%s,%s) {\n", key, value);
-
-  if(!strcmp(key,"debug")) {
-    if(!strcmp(value,"yes")) {
-      debug_flag = 1; res = 1;
-    } else if(!strcmp(value,"no")) {
-      debug_flag = 0; res = 1;
-    } else {
-      res = 0;
-    } goto finish;
-  }
-
   if (!strcmp(key, "dev")) {
     if (!strcmp(value,"default")) {
       key = "id";
       value = "0";
     } else {
       WAVEOUTCAPS caps;
-      int i, max = waveOutGetNumDevs(); 
+      int i, max = waveOutGetNumDevs();
 
-      debug("ao_wmm_set_option: search device %s among %d\n", value, max);
+      adebug("searching for device %s among %d\n", value, max);
       for (i=0; i<max; ++i) {
-        MMRESULT mmres
-          = waveOutGetDevCaps(i, &caps, sizeof(caps));
+        MMRESULT mmres = waveOutGetDevCaps(i, &caps, sizeof(caps));
         if (mmres == MMSYSERR_NOERROR) {
           res = !strcmp(value, caps.szPname);
-          debug("ao_wmm_set_option:\n"
-		"  id   : %d\n"
-		"  name : %s\n"
-		"  ver  : %d.%d\n"
-		"  => [%sfound]\n",i,caps.szPname,
-		caps.vDriverVersion>>8,caps.vDriverVersion&255,
-		res?"":"not ");
+          adebug("checking id=%d, name='%s', ver=%d.%d  => [%s]\n",
+                i,caps.szPname,caps.vDriverVersion>>8,caps.vDriverVersion&255,res?"YES":"no");
           if (res) {
             internal->id   = i;
             internal->caps = caps;
             break;
           }
         } else {
-          debug("ao_wmm_set_option: waveOutGetDevCaps(%d) => [error]\n",i);
-          debug(" => %s\n", mmerror(mmres));
+          aerror("waveOutGetDevCaps(%d) => %s",i,mmerror(mmres));
         }
       }
       goto finish;
@@ -190,32 +154,26 @@
     int id  = strtol(value,0,0);
     int max = waveOutGetNumDevs();
 
-    debug("ao_wmm_set_option: search device %d among %d\n", id, max);
-
     if (id >= 0 &&  id <= max) {
       if (id-- == 0) {
-        debug("ao_wmm_set_option: set default wavemapper\n");
+        adebug("set default wavemapper\n");
         id = WAVE_MAPPER;
       }
       mmres = waveOutGetDevCaps(id, &caps, sizeof(caps));
 
       if (mmres == MMSYSERR_NOERROR) {
         res = 1;
-        debug("ao_wmm_set_option:\n"
-	      "  id   : %d\n"
-	      "  name : %s\n"
-	      "  ver  : %d.%d\n",
-	      id,caps.szPname,caps.vDriverVersion>>8,caps.vDriverVersion&255);
+        adebug("checking id=%d, name='%s', ver=%d.%d  => [YES]\n",
+              i,caps.szPname,caps.vDriverVersion>>8,caps.vDriverVersion&255);
         internal->id   = id;
         internal->caps = caps;
       } else {
-        debug(" waveOutGetDevCaps(%d) => %s\n",id, mmerror(mmres));
+        aerror("waveOutGetDevCaps(%d) => %s",id,mmerror(mmres));
       }
     }
   }
 
  finish:
-  debug("} ao_wmm_set_option() => [%s]\n", res?"success":"error");
   return res;
 }
 
@@ -225,8 +183,6 @@
   ao_wmm_internal *internal;
   int res;
 
-  debug("ao_wmm_device_init() {\n");
-
   internal = (ao_wmm_internal *) malloc(sizeof(ao_wmm_internal));
   device->internal = internal;
   if (internal != NULL) {
@@ -239,7 +195,6 @@
   }
 
   res = internal != NULL;
-  debug("} ao_wmm_device_init() => [%s]\n",res?"success":"error" );
 
   return res;
 }
@@ -247,7 +202,7 @@
 #if 0
 static void CALLBACK
 waveOutProc(HWAVEOUT hwo,
-            UINT uMsg, DWORD_PTR dwInstance,  
+            UINT uMsg, DWORD_PTR dwInstance,
             DWORD_PTR dwParam1, DWORD_PTR dwParam2)
 {
   ao_device *device = (ao_device *) dwInstance;
@@ -257,15 +212,11 @@
 
   case WOM_OPEN:
     /* Sent when the device is opened using the waveOutOpen function. */
-    {
-      debug("WOM_OPEN\n");
-    } break;
+    break;
 
   case WOM_CLOSE:
     /* Sent when the device is closed using the waveOutClose function. */
-    {
-      debug("WOM_CLOSE\n");
-    } break;
+    break;
 
   case WOM_DONE:
     /* Sent when the device driver is finished with a data block sent
@@ -273,14 +224,12 @@
     {
       LPWAVEHDR lpwvhdr = (LPWAVEHDR) dwParam1;
       int me = lpwvhdr - internal->wh;
-      debug("WOM_DONE #%d\n",me);
       lpwvhdr->dwBytesRecorded = 0;
-    } break;
+    }
+    break;
 
   default:
-    {
-      debug("WOM_???\n");
-    } break;
+    break;
   }
 }
 #endif
@@ -291,38 +240,36 @@
   int res;
   MMRESULT mmres;
 
-  debug("_ao_open_device() {\n");
-  mmres = 
-    waveOutOpen(&internal->hwo,     
+  mmres =
+    waveOutOpen(&internal->hwo,
 		internal->id,
 		&internal->wavefmt,
 		(DWORD_PTR)0/* waveOutProc */,
 		(DWORD_PTR)device,
 		CALLBACK_NULL/* |WAVE_FORMAT_DIRECT */|WAVE_ALLOWSYNC);
 
-  debug("_ao_open_device: waveOutOpen\n"
-	" id       : %d\n"
-	" channels : %d\n" 
-	" bits     : %d\n" 
-	" rate     : %d => [%s]\n",
-	internal->id,
-	internal->wavefmt.nChannels,
-	internal->wavefmt.wBitsPerSample,
-	internal->wavefmt.nSamplesPerSec,
-	mmres == MMSYSERR_NOERROR?"success":"error");
+  if(mmres == MMSYSERR_NOERROR){
+    adebug("waveOutOpen id=%d, channels=%d, bits=%d, rate %d => SUCCESS\n",
+          internal->id,
+          internal->wavefmt.nChannels,
+          internal->wavefmt.wBitsPerSample,
+          internal->wavefmt.nSamplesPerSec);
+  }else{
+    aerror("waveOutOpen id=%d, channels=%d, bits=%d, rate %d => FAILED\n",
+          internal->id,
+          internal->wavefmt.nChannels,
+          internal->wavefmt.wBitsPerSample,
+          internal->wavefmt.nSamplesPerSec);
+  }
 
   if (mmres == MMSYSERR_NOERROR) {
     UINT id;
     if (MMSYSERR_NOERROR == waveOutGetID(internal->hwo,&id)) {
-      debug("_ao_open_device: waveOutGetID() => [%d]\n",id);
       internal->id = id;
     }
-  }  else {
-    debug(" waveOutOpen(%d)\n => %s\n", internal->id, mmerror(mmres));
   }
 
   res = (mmres == MMSYSERR_NOERROR);
-  debug("} _ao_open_device() => [%s]\n",res?"success":"error");
   return res;
 }
 
@@ -332,14 +279,13 @@
   int res;
   MMRESULT mmres;
 
-  debug("_ao_close_device() {\n");
-
   mmres = waveOutClose(internal->hwo);
-  if (mmres != MMSYSERR_NOERROR) {
-    debug(" waveOutClose(%d)\n => %s\n", internal->id, mmerror(mmres));
+  if(mmres == MMSYSERR_NOERROR) {
+    adebug("waveOutClose(%d)\n => %s\n", internal->id, mmerror(mmres));
+  }else{
+    aerror("waveOutClose(%d)\n => %s\n", internal->id, mmerror(mmres));
   }
   res = (mmres == MMSYSERR_NOERROR);
-  debug("} _ao_close_device() => [%s]\n",res?"success":"error");
 
   return res;
 }
@@ -353,10 +299,8 @@
   int res;
   MMRESULT mmres;
 
-  debug("_ao_alloc_wave_headers() {\n"
-	"  blocks       : %d\n"
-	"  bytes/blocks : %d\n"
-	"  total        : %d\n",internal->blocks,bytesPerBlock,bytes);
+  adebug("_ao_alloc_wave_headers blocks=%d, bytes/blocks=%d, total=%d\n",
+         internal->blocks,bytesPerBlock,bytes);
 
   internal->bigbuffer = malloc(bytes);
   if (internal->bigbuffer != NULL) {
@@ -375,9 +319,7 @@
       mmres = waveOutPrepareHeader(internal->hwo,
 				   &internal->wh[i].wh,sizeof(WAVEHDR));
       if (MMSYSERR_NOERROR != mmres) {
-        debug("_ao_alloc_wave_headers:"
-	      " waveOutPrepareHeader(%d) => [error]\n",i);
-        debug(" => %s\n", mmerror(mmres));
+        aerror("waveOutPrepareHeader(%d) => %s\n",i, mmerror(mmres));
         break;
       }
     }
@@ -394,11 +336,14 @@
       /* all ok ! */
     }
   } else {
-    debug("_ao_alloc_wave_headers: malloc() => [error]\n");
+    adebug("malloc() => FAILED\n");
   }
 
   res = (internal->bigbuffer != NULL);
-  debug("} _ao_alloc_wave_headers() => [%s]\n", res?"success":"error");
+  if(!res)
+    aerror("_ao_alloc_wave_headers() => FAILED\n");
+  else
+    adebug("_ao_alloc_wave_headers() => success\n");
   return res;
 }
 
@@ -408,8 +353,8 @@
   ao_wmm_internal *internal = (ao_wmm_internal *) device->internal;
   int res = 1;
 
-  debug("_ao_wait_wave_headers: wait for %d blocks (%swait all)\n",
-	internal->sent_blocks,wait_all?"":"not ");
+  adebug("wait for %d blocks (%swait all)\n",
+         internal->sent_blocks,wait_all?"":"not ");
 
   while (internal->sent_blocks > 0) {
     int n;
@@ -418,13 +363,16 @@
     if (n > 0) {
       unsigned int ms = (internal->msPerBlock>>1)+1;
       if (wait_all) ms *= n;
-      debug("_ao_wait_wave_headers: sleep for %ums wait on %d blocks\n",ms, internal->sent_blocks);
+      adebug("sleep for %ums wait on %d blocks\n",ms, internal->sent_blocks);
       Sleep(ms);
     }
   }
 
   res &= !internal->sent_blocks;
-  debug("_ao_wait_wave_headers: => [%s]\n",res?"success":"error");  
+  if(!res)
+    aerror("_ao_wait_wave_headers => FAILED\n");
+  else
+    adebug("_ao_wait_wave_headers => success\n");
   return res;
 }
 
@@ -433,7 +381,6 @@
   ao_wmm_internal *internal = (ao_wmm_internal *) device->internal;
   MMRESULT mmres;
   int res = 1;
-  debug("_ao_free_wave_headers() {\n");
 
   if (internal->wh) {
     int i;
@@ -442,18 +389,15 @@
      * since _ao_wait_wave_headers() has been called once before.
      */
     mmres = waveOutReset(internal->hwo);
-    debug(" waveOutReset(%d) => %s\n", internal->id, mmerror(mmres));
+    adebug("waveOutReset(%d) => %s\n", internal->id, mmerrormmres);
     /* Wait again to be sure reseted waveheaders has been released. */
     _ao_wait_wave_headers(device,0);
 
     for (i=internal->blocks; --i>=0; ) {
       mmres = waveOutUnprepareHeader(internal->hwo,
 				     &internal->wh[i].wh,sizeof(WAVEHDR));
-      if (mmres != MMSYSERR_NOERROR) {
-        debug("_ao_free_wave_headers:"
-	      " waveOutUnprepareHeader(%d)\n",i);
-        debug(" => %s\n", mmerror(mmres));
-      }
+      if (mmres != MMSYSERR_NOERROR)
+        aerror("waveOutUnprepareHeader(%d) => %s\n", i, mmerror(mmres));
 
       res &= mmres == MMSYSERR_NOERROR;
     }
@@ -461,7 +405,11 @@
     internal->spl = 0;
   }
 
-  debug("} _ao_alloc_wave_headers() => [%s]\n", res?"success":"error");
+  if(!res)
+    aerror("_ao_alloc_wave_headers() => FAILED\n");
+  else
+    adebug("_ao_alloc_wave_headers() => success\n");
+
   return res;
 }
 
@@ -475,22 +423,16 @@
   int res = 0;
   WAVEFORMATEX wavefmt;
 
-  debug("ao_wmm_open(%p,%p) {\n",device,format);
+  adebug("open() channels=%d, bits=%d, rate=%d, format %d(%s)\n",
+         format->channels,format->bits,format->rate,format->byte_format,
+         format->byte_format==AO_FMT_LITTLE
+         ?"little"
+         :(format->byte_format==AO_FMT_NATIVE
+           ?"native"
+           :(format->byte_format==AO_FMT_BIG?"big":"unknown")));
 
-  debug("ao_wmm_open:\n"
-	"  channels : %d\n"
-	"  bits     : %d\n"
-	"  rate     : %d\n"
-	"  format   : %d(%s)\n",
-	format->channels,format->bits,format->rate,format->byte_format,
-	format->byte_format==AO_FMT_LITTLE
-	?"little"
-	:(format->byte_format==AO_FMT_NATIVE
-	  ?"native"
-	  :(format->byte_format==AO_FMT_BIG?"big":"unknown")));
-
   if(internal->opened) {
-    debug("ao_wmm_open: already opened\n");
+    aerror("open() => already opened\n");
     goto error_no_close;
   }
 
@@ -498,15 +440,16 @@
   format->byte_format = AO_FMT_LITTLE;
   device->driver_byte_format = AO_FMT_LITTLE;
 
-  if (! (format->channels == 1 || format->channels ==  2) || 
+  if (! (format->channels == 1 || format->channels ==  2) ||
       ! (format->bits     == 8 || format->bits     == 16) ||
       ! (format->rate  >= 6000 && format->rate  <= 50000)
       ) {
-    debug("ao_wmm_open: weird format\n");
+    aerror("open() => unable to handle input format\n");
     goto error;
   }
 
   /* $$$ WMM 8 bit samples are unsigned... Not sure for ao ... */
+  /* Yes, ao 8 bit PCM is unsigned -- Monty */
 
   /* Make sample format */
   memset(&wavefmt,0,sizeof(wavefmt));
@@ -526,17 +469,13 @@
     (internal->splPerBlock * 1000 + format->rate - 1) / format->rate;
 
   /* Open device */
-  if(!_ao_open_device(device)) {
-    debug("ao_wmm_open: _ao_open_device() => [error]\n");
+  if(!_ao_open_device(device))
     goto error;
-  }
   internal->opened = 1;
 
   /* Allocate buffers */
-  if (!_ao_alloc_wave_headers(device)) {
-    debug("ao_wmm_open: _ao_alloc_wave_headers() => [error]\n");
+  if (!_ao_alloc_wave_headers(device))
     goto error;
-  }
   internal->prepared = 1;
 
   res = 1;
@@ -552,8 +491,11 @@
     }
   }
 
- error_no_close: 
-  debug("} ao_wmm_open() => [%s]\n",res?"success":"error");
+ error_no_close:
+  if(res)
+    adebug("open() => success\n");
+  else
+    aerror("open() => FAILED\n");
   return res;
 }
 
@@ -567,11 +509,11 @@
 
   /* Satanity checks */
   if (internal->wh[idx].sent) {
-    debug("_ao_send_block: block %d marked SENT\n",idx);
+    adebug("block %d marked SENT\n",idx);
     return 0;
   }
   if (!!(internal->wh[idx].wh.dwFlags & WHDR_DONE)) {
-    debug("_ao_send_block: block %d marked DONE\n",idx);
+    adebug("block %d marked DONE\n",idx);
     return 0;
   }
 
@@ -591,8 +533,7 @@
   /*&& !(internal->wh[idx].wh.dwFlags & WHDR_DONE);*/
   internal->sent_blocks += internal->wh[idx].sent;
   if (mmres != MMSYSERR_NOERROR) {
-    debug("_ao_send_block:: waveOutWrite(%d)\n",idx);
-    debug(" => %s\n",mmerror(mmres));
+    adebug("waveOutWrite(%d) => %s\n",idx,mmerror(mmres));
   }
   return mmres == MMSYSERR_NOERROR;
 }
@@ -609,16 +550,16 @@
     /*debug("_ao_get_free_block: release block %d\n",ridx);*/
     internal->wh[ridx].sent = 0;
     internal->wh[ridx].wh.dwFlags &= ~WHDR_DONE;
-    
+
     --internal->full_blocks;
     if (internal->full_blocks<0) {
-      debug("_ao_get_free_block: internal error with full block counter\n");
+      adebug("internal error with full block counter\n");
       internal->full_blocks = 0;
     }
 
     --internal->sent_blocks;
     if (internal->sent_blocks<0) {
-      debug("_ao_get_free_block: internal error with sent block counter\n");
+      adebug("internal error with sent block counter\n");
       internal->sent_blocks = 0;
     }
     if (++ridx >= internal->blocks) ridx = 0;
@@ -644,7 +585,6 @@
     const int idx = _ao_get_free_block(device);
 
     if (idx == -1) {
-      /* debug("sleep %dms, rem %d bytes\n",internal->msPerBlock,num_bytes); */
       Sleep(internal->msPerBlock);
       continue;
     }
@@ -653,16 +593,11 @@
     n = internal->wh[idx].wh.dwBufferLength
       - internal->wh[idx].count;
 
-    /*     debug("free in block %d : %d/%d\n", */
-    /* 	  idx,n,internal->wh[idx].dwBufferLength); */
-
     /* Get amount to copy */
     if (n > (int)num_bytes) {
       n = num_bytes;
     }
-    /*     debug("copy = %d\n",n); */
 
-
     /* Do copy */
     CopyMemory((char*)internal->wh[idx].wh.lpData
 	       + internal->wh[idx].count,
@@ -671,14 +606,12 @@
     /* Updates pointers and counters */
     output_samples += n;
     num_bytes -= n;
-    /*     debug("rem = %d\n",num_bytes); */
     internal->wh[idx].count += n;
 
     /* Is this block full ? */
-    if (internal->wh[idx].count 
+    if (internal->wh[idx].count
 	== internal->wh[idx].wh.dwBufferLength) {
       ++internal->full_blocks;
-      /*       debug("blocks %d full, total:%d\n",internal->widx,internal->full_blocks); */
       if (++internal->widx == internal->blocks) {
 	internal->widx = 0;
       }
@@ -686,7 +619,7 @@
     }
   }
 
-  /*   debug("ao_wmm_play => %d rem => [%s]\n",num_bytes,ret?"success":"error"); */
+  adebug("ao_wmm_play => %d rem => [%s]\n",num_bytes,ret?"success":"error");
   return ret;
 
 }
@@ -696,8 +629,6 @@
   ao_wmm_internal *internal = (ao_wmm_internal *) device->internal;
   int ret = 0;
 
-  debug("ao_wmm_close() {\n");
-
   if (internal->opened && internal->prepared) {
     _ao_wait_wave_headers(device, 1);
   }
@@ -712,8 +643,6 @@
     internal->opened = 0;
   }
 
-  debug("} ao_wmm_close() => [%s]\n",ret?"success":"error");
-
   return ret;
 }
 
@@ -721,15 +650,11 @@
 {
   ao_wmm_internal *internal = (ao_wmm_internal *) device->internal;
 
-  debug("ao_wmm_device_clear() {\n");
-
   if (internal->bigbuffer) {
     free(internal->bigbuffer); internal->bigbuffer = NULL;
   }
   free(internal);
 
-  debug("} ao_wmm_device_clear()\n");
-
 }
 
 ao_functions ao_wmm = {

Modified: trunk/ao/src/audio_out.c
===================================================================
--- trunk/ao/src/audio_out.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/audio_out.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -595,7 +595,7 @@
 };
 
 /* Check the requested maxtrix string for syntax and mnemonics */
-static char *_sanitize_matrix(char *matrix,int quiet){
+static char *_sanitize_matrix(char *matrix, ao_device *device){
   if(matrix){
     char *ret = calloc(strlen(matrix)+1,1); /* can only get smaller */
     char *p=matrix;
@@ -626,9 +626,9 @@
       }
       if(!mnemonics[m]){
         /* unrecognized channel mnemonic */
-        if(!quiet){
+        {
           int i;
-          fprintf(stderr,"\nUnrecognized channel name \"");
+          aerror("Unrecognized channel name \"");
           for(i=0;i<t-p;i++)fputc(p[i],stderr);
           fprintf(stderr,"\" in channel matrix \"%s\"\n",matrix);
         }
@@ -720,13 +720,15 @@
           if(!strcmp(options->key,"matrix")){
             /* explicitly set the output matrix to the requested
                string; devices must not override. */
-            device->output_matrix = _sanitize_matrix(options->value, device->verbose==-1);
+            device->output_matrix = _sanitize_matrix(options->value, device);
             if(!device->output_matrix){
               errno = AO_EBADOPTION;
               return NULL;
             }
+          }else if(!strcmp(options->key,"debug")){
+            device->verbose=2;
           }else if(!strcmp(options->key,"verbose")){
-            device->verbose=1;
+            if(device->verbose<1)device->verbose=1;
           }else if(!strcmp(options->key,"quiet")){
             device->verbose=-1;
           }else{
@@ -743,9 +745,9 @@
 
         /* also sanitize the format input channel matrix */
         if(format->matrix){
-          sformat.matrix = _sanitize_matrix(format->matrix, device->verbose==-1);
-          if(!sformat.matrix && device->verbose>=0)
-            fprintf(stderr,"Input channel matrix invalid; ignoring.\n");
+          sformat.matrix = _sanitize_matrix(format->matrix, device);
+          if(!sformat.matrix)
+            awarn("Input channel matrix invalid; ignoring.\n");
         }
 
         /* set up any other housekeeping */
@@ -765,10 +767,9 @@
         /* resolve channel mapping request if any */
         if(sformat.matrix){
           if(!device->output_matrix){
-            if(device->verbose>=0)
-              fprintf(stderr,"\nOutput driver %s does not support channel matrixing;\n"
-                      "continuing without routing channels to specific locations.\n\n",
-                      info_table[device->driver_id]->short_name);
+            awarn("Driver %s does not support channel matrixing;\n"
+                 "continuing without routing channels to specific locations.\n\n",
+                 info_table[device->driver_id]->short_name);
           }else{
 
             /* walk thorugh the output matrix, match outputs to inputs */
@@ -776,8 +777,7 @@
             int count=0;
             device->permute_channels = calloc(device->output_channels,sizeof(int));
 
-            if(device->verbose>0)
-              fprintf(stderr,"\n");
+            averbose("\n");
 
             while(count<device->output_channels){
               int m=1,mm;
@@ -803,22 +803,19 @@
                 device->permute_channels[count] = -1;
 
               /* display resulting mapping for now */
-              if(device->verbose>0){
-                if(device->permute_channels[count]>=0){
-                  fprintf(stderr,"Output %d (%s)\t <- input %d (%s)\n",
-                          count,mnemonics[m],device->permute_channels[count],
-                          mnemonics[mm]);
-                }else{
-                  fprintf(stderr,"Output %d (%s)\t %s\n",
-                          count,mnemonics[m],(m==1?"unmapped":"<- none"));
-                }
+              if(device->permute_channels[count]>=0){
+                averbose("Output %d (%s)\t <- input %d (%s)\n",
+                        count,mnemonics[m],device->permute_channels[count],
+                        mnemonics[mm]);
+              }else{
+                averbose("Output %d (%s)\t %s\n",
+                        count,mnemonics[m],(m==1?"unmapped":"<- none"));
               }
               count++;
               op=h;
               if(*h)op++;
             }
-            if(device->verbose>0)
-              fprintf(stderr,"\n");
+            averbose("\n");
 
           }
         }
@@ -840,15 +837,12 @@
 
 	/* Only create swap buffer if needed */
         if (device->bytewidth>1 &&
-            device->client_byte_format != device->driver_byte_format &&
-            device->verbose>0)
-          fprintf(stderr,
-                  "n\n\n\n-------------------------\n"
-                  "machine endianness: %d\n"
-                  "device->client_byte_format:%d\n"
-                  "device->driver_byte_format:%d\n"
-                  "--------------------------\n",
-                  ao_is_big_endian(),device->client_byte_format,device->driver_byte_format);
+            device->client_byte_format != device->driver_byte_format){
+          adebug("swap buffer required:\n");
+          adebug("  machine endianness: %d\n",ao_is_big_endian());
+          adebug("  device->client_byte_format:%d\n",device->client_byte_format);
+          adebug("  device->driver_byte_format:%d\n",device->driver_byte_format);
+        }
 
 	if ( (device->bytewidth>1 &&
               device->client_byte_format != device->driver_byte_format) ||

Modified: trunk/ao/src/plugins/alsa/ao_alsa.c
===================================================================
--- trunk/ao/src/plugins/alsa/ao_alsa.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/plugins/alsa/ao_alsa.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -70,7 +70,8 @@
 	"use_mmap",
         "matrix",
         "verbose",
-        "quiet"
+        "quiet",
+        "debug"
 };
 
 
@@ -84,7 +85,7 @@
 	AO_FMT_NATIVE,
 	35,
 	ao_alsa_options,
-	7
+	8
 };
 
 
@@ -185,7 +186,7 @@
 
 
 /* determine the alsa bitformat for a given bitwidth and endianness */
-static inline int alsa_get_sample_bitformat(int bitwidth, int bigendian)
+static inline int alsa_get_sample_bitformat(int bitwidth, int bigendian, ao_device *device)
 {
 	int ret;
 
@@ -198,7 +199,7 @@
 		  break;
 	case 32 : ret = SND_PCM_FORMAT_S32;
 		  break;
-	default : fprintf(stderr,"ALSA: invalid bitwidth %d\n", bitwidth);
+	default : aerror("invalid bitwidth %d\n", bitwidth);
 		  return -1;
 	}
 
@@ -208,7 +209,8 @@
 
 /* setup alsa data format and buffer geometry */
 static inline int alsa_set_hwparams(ao_alsa_internal *internal,
-		ao_sample_format *format)
+                                    ao_sample_format *format,
+                                    ao_device *device)
 {
 	snd_pcm_hw_params_t   *params;
 	int err;
@@ -254,8 +256,8 @@
 	if (err < 0)
 		return err;
 	if (rate > 1.05 * format->rate || rate < 0.95 * format->rate) {
-		fprintf(stderr, "warning: sample rate %i not supported "
-			"by the hardware, using %u\n", format->rate, rate);
+          awarn("sample rate %i not supported "
+                "by the hardware, using %u\n", format->rate, rate);
 	}
 
 	/* set the length of the hardware sample buffer in microseconds */
@@ -354,7 +356,7 @@
 
 	/* Get the ALSA bitformat first to make sure it's valid */
 	err = alsa_get_sample_bitformat(format->bits,
-			device->client_byte_format == AO_FMT_BIG);
+                                        device->client_byte_format == AO_FMT_BIG,device);
 	if (err < 0)
 		goto error;
 
@@ -390,8 +392,8 @@
           }
 
           if(err){
-            fprintf(stderr,"ERROR: Unable to open ALSA surround device '%s'\n"
-                           "       trying default device...\n",tmp);
+            awarn("Unable to open ALSA surround device '%s'\n"
+                  "       trying default device...\n",tmp);
             tmp=NULL;
           }
           if(!tmp)
@@ -408,7 +410,7 @@
 	}
 
 	/* Set up the hardware parameters, ie sample and buffer specs */
-	err = alsa_set_hwparams(internal, format);
+	err = alsa_set_hwparams(internal, format, device);
 	if (err < 0)
 		goto error;
 
@@ -427,11 +429,11 @@
         if(!device->output_matrix){
           if(!strncasecmp(internal->dev,"plug:",5))
             if(format->channels>2 && device->verbose>=0)
-              fprintf(stderr,"\nWARNING: No way to determine hardware channel mapping of\n"
-                      "ALSA 'plug:' devices.\n");
+              awarn("No way to determine hardware channel mapping of\n"
+                    "ALSA 'plug:' devices.\n");
           if(!strcasecmp(internal->dev,"default")){
             if(format->channels>2 && device->verbose>=0)
-              fprintf(stderr,"\nWARNING: ALSA 'default' device plays only L,R channels.\n");
+              awarn("ALSA 'default' device plays only L,R channels.\n");
             device->output_matrix=strdup("L,R");
           }else
             device->output_matrix=strdup("L,R,BL,BR,C,LFE,SL,SR");
@@ -440,8 +442,8 @@
 	return 1;
 
 error:
-	fprintf(stderr, "ALSA %s error: %s\n",
-			internal->cmd, snd_strerror(err));
+	aerror("%s => %s\n",
+               internal->cmd, snd_strerror(err));
 	if (internal->pcm_handle) {
 		snd_pcm_close(internal->pcm_handle);
 		internal->pcm_handle = NULL;
@@ -451,11 +453,11 @@
 
 
 /* recover from an alsa exception */
-static inline int alsa_error_recovery(ao_alsa_internal *internal, int err)
+static inline int alsa_error_recovery(ao_alsa_internal *internal, int err, ao_device *device)
 {
 	if (err == -EPIPE) {
 		/* FIXME: underrun length detection */
-		//fprintf(stderr,"ALSA: underrun, at least %dms.\n", 0);
+		adebug("underrun, restarting...\n");
 		/* output buffer underrun */
 		internal->cmd = "underrun recovery: snd_pcm_prepare";
 		err = snd_pcm_prepare(internal->pcm_handle);
@@ -503,10 +505,10 @@
 
 		if (err < 0) {
 			/* this might be an error, or an exception */
-			err = alsa_error_recovery(internal, err);
+                  err = alsa_error_recovery(internal, err, device);
 			if (err < 0) {
-				fprintf(stderr,"ALSA write error: %s\n",
-						snd_strerror(err));
+				aerror("write error: %s\n",
+                                       snd_strerror(err));
 				return 0;
 			}else /* recovered, continue */
                           continue;
@@ -529,17 +531,17 @@
 	ao_alsa_internal *internal;
 
 	if (device) {
-		if ((internal = (ao_alsa_internal *) device->internal)) {
-			if (internal->pcm_handle) {
-				snd_pcm_drain(internal->pcm_handle);
-				snd_pcm_close(internal->pcm_handle);
-				internal->pcm_handle=NULL;
-			} else
-				fprintf(stderr,"ao_plugin_close called with uninitialized ao_device->internal->pcm_handle\n");
-		} else
-			fprintf(stderr,"ao_plugin_close called with uninitialized ao_device->internal\n");
+          if ((internal = (ao_alsa_internal *) device->internal)) {
+            if (internal->pcm_handle) {
+              snd_pcm_drain(internal->pcm_handle);
+              snd_pcm_close(internal->pcm_handle);
+              internal->pcm_handle=NULL;
+            } else
+              awarn("ao_plugin_close called with uninitialized ao_device->internal->pcm_handle\n");
+          } else
+            awarn("ao_plugin_close called with uninitialized ao_device->internal\n");
 	} else
-		fprintf(stderr,"ao_plugin_close called with uninitialized ao_device\n");
+          awarn("ao_plugin_close called with uninitialized ao_device\n");
 
 	return 1;
 }
@@ -551,18 +553,18 @@
 	ao_alsa_internal *internal;
 
 	if (device) {
-		if ((internal = (ao_alsa_internal *) device->internal)) {
-			if (internal->dev)
-				free (internal->dev);
-			else
-				fprintf(stderr,"ao_plugin_device_clear called with uninitialized ao_device->internal->dev\n");
-			if (internal->cmd)
-				internal->cmd = NULL;
+          if ((internal = (ao_alsa_internal *) device->internal)) {
+            if (internal->dev)
+              free (internal->dev);
+            else
+              awarn("ao_plugin_device_clear called with uninitialized ao_device->internal->dev\n");
+            if (internal->cmd)
+              internal->cmd = NULL;
 
-			free(device->internal);
-		} else
-			fprintf(stderr,"ao_plugin_device_clear called with uninitialized ao_device->internal\n");
+            free(device->internal);
+          } else
+            awarn("ao_plugin_device_clear called with uninitialized ao_device->internal\n");
 	} else
-		fprintf(stderr,"ao_plugin_device_clear called with uninitialized ao_device\n");
+          awarn("ao_plugin_device_clear called with uninitialized ao_device\n");
 }
 

Modified: trunk/ao/src/plugins/arts/ao_arts.c
===================================================================
--- trunk/ao/src/plugins/arts/ao_arts.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/plugins/arts/ao_arts.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -35,7 +35,7 @@
 #include <ao/plugin.h>
 
 
-static char *ao_arts_options[] = {"matrix","verbose","quiet"};
+static char *ao_arts_options[] = {"matrix","verbose","quiet","debug"};
 static ao_info ao_arts_info =
 {
 	AO_TYPE_LIVE,
@@ -50,7 +50,7 @@
 	15,
 #endif
 	ao_arts_options,
-        3
+        4
 };
 
 

Modified: trunk/ao/src/plugins/esd/ao_esd.c
===================================================================
--- trunk/ao/src/plugins/esd/ao_esd.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/plugins/esd/ao_esd.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -38,7 +38,7 @@
 #include <ao/ao.h>
 #include <ao/plugin.h>
 
-static char *ao_esd_options[] = {"host","matrix","verbose","quiet"};
+static char *ao_esd_options[] = {"host","matrix","verbose","quiet","debug"};
 static ao_info ao_esd_info =
 {
 	AO_TYPE_LIVE,
@@ -49,7 +49,7 @@
 	AO_FMT_NATIVE,
 	40,
 	ao_esd_options,
-	4
+	5
 };
 
 

Modified: trunk/ao/src/plugins/irix/ao_irix.c
===================================================================
--- trunk/ao/src/plugins/irix/ao_irix.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/plugins/irix/ao_irix.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -49,7 +49,7 @@
 	int channels;
 } ao_irix_internal;
 
-static char *ao_irix_options[] = {"matrix","verbose","quiet"};
+static char *ao_irix_options[] = {"matrix","verbose","quiet","debug"};
 
 static ao_info ao_irix_info =
 {
@@ -61,7 +61,7 @@
 	AO_FMT_NATIVE,
 	20,
 	ao_irix_options,
-	3
+	4
 };
 
 int ao_plugin_test(void)
@@ -119,13 +119,13 @@
 	int  wsize = AL_SAMPLE_16;
 
 	if (alSetQueueSize(internal->alconfig, AO_IRIX_BUFFER_SIZE) < 0) {
-		fprintf(stderr, "alSetQueueSize failed: %s\n",
+		aerror("alSetQueueSize failed: %s\n",
 			alGetErrorString(oserror()));
 		return 0;
 	}
 
 	if (alSetChannels(internal->alconfig, format->channels) < 0) {
-		fprintf(stderr, "alSetChannels(%d) failed: %s\n",
+		aerror("alSetChannels(%d) failed: %s\n",
 			format->channels, alGetErrorString(oserror()));
 		return 0;
 	}
@@ -133,13 +133,13 @@
 	internal->channels = format->channels;
 
 	if (alSetDevice(internal->alconfig, dev) < 0) {
-		fprintf(stderr, "alSetDevice failed: %s\n",
+		aerror("alSetDevice failed: %s\n",
 			alGetErrorString(oserror()));
 		return 0;
 	}
 
 	if (alSetSampFmt(internal->alconfig, AL_SAMPFMT_TWOSCOMP) < 0) {
-		fprintf(stderr, "alSetSampFmt failed: %s\n",
+		aerror("alSetSampFmt failed: %s\n",
 			alGetErrorString(oserror()));
 		return 0;
 	}
@@ -161,13 +161,13 @@
 		break;
 
 	default:
-		fprintf(stderr, "Irix audio: unsupported bit with %d\n",
+		aerror("unsupported bit with %d\n",
 			format->bits);
 		break;
 	}
 
 	if (alSetWidth(internal->alconfig, wsize) < 0) {
-		fprintf(stderr, "alSetWidth failed: %s\n",
+		aerror("alSetWidth failed: %s\n",
 			alGetErrorString(oserror()));
 		alClosePort(internal->alport);
 		return 0;
@@ -176,7 +176,7 @@
 	internal->alport = alOpenPort("libao", "w", internal->alconfig);
 	if (internal->alport == NULL)
 	{
-		fprintf(stderr, "alOpenPort failed: %s\n",
+		aerror("alOpenPort failed: %s\n",
 			alGetErrorString(oserror()));
 		return 0;
 	}
@@ -185,7 +185,7 @@
 	params.value.ll = alDoubleToFixed((double) format->rate);
 	if (alSetParams(dev, &params, 1) < 0)
 	{
-		printf("alSetParams() failed: %s\n", alGetErrorString(oserror()));
+		aerror("alSetParams() failed: %s\n", alGetErrorString(oserror()));
 		alClosePort(internal->alport);
 		return 0;
 	}

Modified: trunk/ao/src/plugins/macosx/ao_macosx.c
===================================================================
--- trunk/ao/src/plugins/macosx/ao_macosx.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/plugins/macosx/ao_macosx.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -52,7 +52,7 @@
 #define true  1
 #define false 0
 
-static char *ao_macosx_options[] = {"matrix","verbose","quiet"};
+static char *ao_macosx_options[] = {"matrix","verbose","quiet","debug"};
 
 static ao_info ao_macosx_info =
 {
@@ -64,7 +64,7 @@
 	AO_FMT_NATIVE,
 	30,
 	ao_macosx_options,
-	3
+	4
 };
 
 
@@ -73,14 +73,14 @@
     // Stuff describing the CoreAudio device
     AudioDeviceID                outputDeviceID;
     AudioStreamBasicDescription  outputStreamBasicDescription;
-    
+
     // The amount of data CoreAudio wants each time it calls our IO function
     UInt32                       outputBufferByteCount;
-    
+
     // Keep track of whether the output stream has actually been started/stopped
     Boolean                      started;
     Boolean                      isStopping;
-    
+
     // Synchronization objects between the CoreAudio thread and the enqueuing thread
     pthread_mutex_t              mutex;
     pthread_cond_t               condition;
@@ -90,10 +90,13 @@
     unsigned int                 bufferByteCount;
     unsigned int                 firstValidByteOffset;
     unsigned int                 validByteCount;
-    
+
     // Temporary debugging state
     unsigned int bytesQueued;
     unsigned int bytesDequeued;
+
+    // Need access in the cllbacks for messaging
+    ao_device                   *device;
 } ao_macosx_internal;
 
 // The function that the CoreAudio thread calls when it wants more data
@@ -101,7 +104,7 @@
 
 int ao_plugin_test()
 {
-	
+
 	if (/* FIXME */ 0 )
 		return 0; /* Cannot use this plugin with default parameters */
 	else {
@@ -121,12 +124,13 @@
 
 	internal = (ao_macosx_internal *) malloc(sizeof(ao_macosx_internal));
 
-	if (internal == NULL)	
+	if (internal == NULL)
 		return 0; /* Could not initialize device memory */
-	
 
-	
+
+
 	device->internal = internal;
+	device->internal->device = device;
 
 	return 1; /* Memory alloc successful */
 }
@@ -148,65 +152,66 @@
     OSStatus status;
     UInt32 propertySize;
     int rc;
-    
+
     if (format->rate != 44100) {
-        fprintf(stderr, "ao_macosx_open: Only support 44.1kHz right now\n");
+        aerror("Only support 44.1kHz right now\n");
         return 0;
     }
-    
+
     if (format->channels != 2) {
-        fprintf(stderr, "ao_macosx_open: Only two channel audio right now\n");
+        aerror("Only two channel audio right now\n");
         return 0;
     }
 
     propertySize = sizeof(internal->outputDeviceID);
     status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &propertySize, &(internal->outputDeviceID));
     if (status) {
-        fprintf(stderr, "ao_macosx_open: AudioHardwareGetProperty returned %d\n", (int)status);
+        aerror("AudioHardwareGetProperty returned %d\n", (int)status);
 	return 0;
     }
-    
+
     if (internal->outputDeviceID == kAudioDeviceUnknown) {
-        fprintf(stderr, "ao_macosx_open: AudioHardwareGetProperty: outputDeviceID is kAudioDeviceUnknown\n");
+        aerror("AudioHardwareGetProperty: outputDeviceID is kAudioDeviceUnknown\n");
 	return 0;
     }
-    
+
     propertySize = sizeof(internal->outputStreamBasicDescription);
     status = AudioDeviceGetProperty(internal->outputDeviceID, 0, false, kAudioDevicePropertyStreamFormat, &propertySize, &internal->outputStreamBasicDescription);
     if (status) {
-        fprintf(stderr, "ao_macosx_open: AudioDeviceGetProperty returned %d when getting kAudioDevicePropertyStreamFormat\n", (int)status);
+        aerror("AudioDeviceGetProperty returned %d when getting kAudioDevicePropertyStreamFormat\n", (int)status);
 	return 0;
     }
 
-    fprintf(stderr, "hardware format...\n");
-    fprintf(stderr, "%f mSampleRate\n", internal->outputStreamBasicDescription.mSampleRate);
-    fprintf(stderr, "%c%c%c%c mFormatID\n", (int)(internal->outputStreamBasicDescription.mFormatID & 0xff000000) >> 24,
-                                            (int)(internal->outputStreamBasicDescription.mFormatID & 0x00ff0000) >> 16,
-                                            (int)(internal->outputStreamBasicDescription.mFormatID & 0x0000ff00) >>  8,
-                                            (int)(internal->outputStreamBasicDescription.mFormatID & 0x000000ff) >>  0);
-    fprintf(stderr, "%5d mBytesPerPacket\n", (int)internal->outputStreamBasicDescription.mBytesPerPacket);
-    fprintf(stderr, "%5d mFramesPerPacket\n", (int)internal->outputStreamBasicDescription.mFramesPerPacket);
-    fprintf(stderr, "%5d mBytesPerFrame\n", (int)internal->outputStreamBasicDescription.mBytesPerFrame);
-    fprintf(stderr, "%5d mChannelsPerFrame\n", (int)internal->outputStreamBasicDescription.mChannelsPerFrame);
+    adebug("hardware format...\n");
+    adebug("%f mSampleRate\n", internal->outputStreamBasicDescription.mSampleRate);
+    adebug("%c%c%c%c mFormatID\n", 
+           (int)(internal->outputStreamBasicDescription.mFormatID & 0xff000000) >> 24,
+           (int)(internal->outputStreamBasicDescription.mFormatID & 0x00ff0000) >> 16,
+           (int)(internal->outputStreamBasicDescription.mFormatID & 0x0000ff00) >>  8,
+           (int)(internal->outputStreamBasicDescription.mFormatID & 0x000000ff) >>  0);
+    adebug("%5d mBytesPerPacket\n", (int)internal->outputStreamBasicDescription.mBytesPerPacket);
+    adebug("%5d mFramesPerPacket\n", (int)internal->outputStreamBasicDescription.mFramesPerPacket);
+    adebug("%5d mBytesPerFrame\n", (int)internal->outputStreamBasicDescription.mBytesPerFrame);
+    adebug("%5d mChannelsPerFrame\n", (int)internal->outputStreamBasicDescription.mChannelsPerFrame);
 
     if (internal->outputStreamBasicDescription.mFormatID != kAudioFormatLinearPCM) {
-        fprintf(stderr, "ao_macosx_open: Default Audio Device doesn't support Linear PCM!\n");
+        aerror("Default Audio Device doesn't support Linear PCM!\n");
 	return 0;
     }
 
     propertySize = sizeof(internal->outputBufferByteCount);
-    
+
     internal->outputBufferByteCount = 8192;
     status = AudioDeviceSetProperty(internal->outputDeviceID, 0, 0, false, kAudioDevicePropertyBufferSize,
         propertySize, &internal->outputBufferByteCount);
-        
+
     status = AudioDeviceGetProperty(internal->outputDeviceID, 0, false, kAudioDevicePropertyBufferSize, &propertySize, &internal->outputBufferByteCount);
     if (status) {
-        fprintf(stderr, "ao_macosx_open: AudioDeviceGetProperty returned %d when getting kAudioDevicePropertyBufferSize\n", (int)status);
-	return 0;
+      aerror("AudioDeviceGetProperty returned %d when getting kAudioDevicePropertyBufferSize\n", (int)status);
+      return 0;
     }
 
-    fprintf(stderr, "%5d outputBufferByteCount\n", (int)internal->outputBufferByteCount);
+    adebug("%5d outputBufferByteCount\n", (int)internal->outputBufferByteCount);
 
     // It appears that AudioDeviceGetProperty lies about this property in DP4
     // Set the actual value
@@ -217,22 +222,22 @@
     internal->started = false;
     status = AudioDeviceAddIOProc(internal->outputDeviceID, audioDeviceIOProc, internal);
     if (status) {
-        fprintf(stderr, "ao_macosx_open: AudioDeviceAddIOProc returned %d\n", (int)status);
+        aerror("AudioDeviceAddIOProc returned %d\n", (int)status);
 	return 0;
     }
 
     rc = pthread_mutex_init(&internal->mutex, NULL);
     if (rc) {
-        fprintf(stderr, "ao_macosx_open: pthread_mutex_init returned %d\n", rc);
+        aerror("pthread_mutex_init returned %d\n", rc);
 	return 0;
     }
-    
+
     rc = pthread_cond_init(&internal->condition, NULL);
     if (rc) {
-        fprintf(stderr, "ao_macosx_open: pthread_cond_init returned %d\n", rc);
+        aerror("pthread_cond_init returned %d\n", rc);
 	return 0;
     }
-    
+
     /* Since we don't know how big to make the buffer until we open the device
        we allocate the buffer here instead of ao_plugin_device_init() */
     internal->bufferByteCount = BUFFER_COUNT * internal->outputBufferByteCount;
@@ -241,14 +246,14 @@
     internal->buffer = malloc(internal->bufferByteCount);
     memset(internal->buffer, 0, internal->bufferByteCount);
     if (!internal->buffer) {
-        fprintf(stderr, "ao_macosx_open: Unable to allocate queue buffer.\n");
+        aerror("Unable to allocate queue buffer.\n");
 	return 0;
     }
 
     /* initialize debugging state */
     internal->bytesQueued = 0;
     internal->bytesDequeued = 0;
-    
+
     device->driver_byte_format = AO_FMT_NATIVE;
 
     /* limited to stereo for now */
@@ -259,20 +264,18 @@
 }
 
 
-int ao_plugin_play(ao_device *device, const char *output_samples, 
+int ao_plugin_play(ao_device *device, const char *output_samples,
 		uint_32 num_bytes)
 {
     ao_macosx_internal *internal = (ao_macosx_internal *) device->internal;
     OSStatus status;
 
-#if DEBUG_PIPE
-    fprintf(stderr, "Enqueue: 0x%08x %d bytes\n", output_samples, num_bytes);
-#endif
+    adebug("Enqueue: 0x%08x %d bytes\n", output_samples, num_bytes);
 
     while (num_bytes) {
         unsigned int bytesToCopy;
         unsigned int firstEmptyByteOffset, emptyByteCount;
-        
+
         // Get a consistent set of data about the available space in the queue,
         // figure out the maximum number of bytes we can copy in this chunk,
         // and claim that amount of space
@@ -295,43 +298,40 @@
             bytesToCopy = MIN(num_bytes, emptyByteCount);
 
         // Copy the bytes and get ready for the next chunk, if any
-#if DEBUG_PIPE
-        fprintf(stderr, "Enqueue:\tdst = 0x%08x src=0x%08x count=%d\n",
-                internal->buffer + firstEmptyByteOffset, output_samples, bytesToCopy);
-#endif
-                
+        adebug("Enqueue:\tdst = 0x%08x src=0x%08x count=%d\n",
+               internal->buffer + firstEmptyByteOffset, output_samples, bytesToCopy);
+
         memcpy(internal->buffer + firstEmptyByteOffset, output_samples, bytesToCopy);
         /*{
             unsigned int i;
             static unsigned char bufferIndex;
-            
+
             bufferIndex++;
             memset(internal->buffer + firstEmptyByteOffset, bufferIndex, bytesToCopy);
         }*/
-        
+
         num_bytes -= bytesToCopy;
         output_samples += bytesToCopy;
         internal->validByteCount += bytesToCopy;
-        
+
         internal->bytesQueued += bytesToCopy;
-        
-        //fprintf(stderr, "Copy: %d bytes, %d bytes left\n", bytesToCopy, internal->availableByteCount);
+
         pthread_mutex_unlock(&internal->mutex);
-        
+
         // We have to wait to start the device until we have some data queued.
         // It might be better to wait until we have some minimum amount of data
         // larger than whatever blob got enqueued here, but if we had a short
         // stream, we'd have to make sure that ao_macosx_close() would start
         // AND stop the stream when it had finished.  Yuck.  If the first
         // blob that is passed to us is large enough (and the caller passes
-        // data quickly enough, this shouldn't be a problem. 
+        // data quickly enough, this shouldn't be a problem.
 #if 1
         if (!internal->started) {
             internal->started = true;
             status = AudioDeviceStart(internal->outputDeviceID, audioDeviceIOProc);
             if (status) {
-                fprintf(stderr, "ao_macosx_open: AudioDeviceStart returned %d\n", (int)status);
-                
+                aerror("AudioDeviceStart returned %d\n", (int)status);
+
                 // Can we do anything useful here?  The library doesn't expect this call
                 // to be able to fail.
 		return 0;
@@ -353,24 +353,24 @@
     if (internal->started) {
 
         internal->isStopping = true;
-        
+
         // Wait for any pending data to get flushed
         pthread_mutex_lock(&internal->mutex);
         while (internal->validByteCount)
             pthread_cond_wait(&internal->condition, &internal->mutex);
         pthread_mutex_unlock(&internal->mutex);
-        
+
         status = AudioDeviceStop(internal->outputDeviceID, audioDeviceIOProc);
         if (status) {
-            fprintf(stderr, "ao_macosx_close: AudioDeviceStop returned %d\n", (int)status);
+            aerror("AudioDeviceStop returned %d\n", (int)status);
             return 0;
         }
     }
-    
+
     status = AudioDeviceRemoveIOProc(internal->outputDeviceID, audioDeviceIOProc);
     if (status) {
-        fprintf(stderr, "ao_macosx_close: AudioDeviceRemoveIOProc returned %d\n", (int)status);
-        return 0;
+      aerror("AudioDeviceRemoveIOProc returned %d\n", (int)status);
+      return 0;
     }
 
     return 1;
@@ -389,6 +389,7 @@
 static OSStatus audioDeviceIOProc(AudioDeviceID inDevice, const AudioTimeStamp *inNow, const AudioBufferList *inInputData, const AudioTimeStamp *inInputTime, AudioBufferList *outOutputData, const AudioTimeStamp *inOutputTime, void *inClientData)
 {
     ao_macosx_internal *internal = (ao_macosx_internal *)inClientData;
+    ao_device *device = internal->device;
     short *sample;
     unsigned int validByteCount;
     float scale = (0.5f / SHRT_MAX), *outBuffer;
@@ -400,7 +401,7 @@
     bytesToCopy = internal->outputBufferByteCount/2;
     validByteCount = internal->validByteCount;
     outBuffer = (float *)outOutputData->mBuffers[0].mData;
-    
+
     if (validByteCount < bytesToCopy && !internal->isStopping) {
         // Not enough data ... let it build up a bit more before we start copying stuff over.
         // If we are stopping, of course, we should just copy whatever we have.
@@ -408,22 +409,22 @@
         pthread_mutex_unlock(&internal->mutex);
         return 0;
     }
-    
+
     bytesToCopy = MIN(bytesToCopy, validByteCount);
     sample = internal->buffer + internal->firstValidByteOffset;
     samplesToCopy = bytesToCopy / sizeof(*sample);
 
     internal->bytesDequeued += bytesToCopy;
 
-#if DEBUG_PIPE
-    fprintf(stderr, "IO: outputTime=%f firstValid=%d valid=%d toCopy=%d queued=%d dequeued=%d sample=0x%08x\n",
-            inOutputTime->mSampleTime,
-            internal->firstValidByteOffset, internal->validByteCount, samplesToCopy, internal->bytesQueued, internal->bytesDequeued, sample);
-#endif
-    
+    adebug("IO: outputTime=%f firstValid=%d valid=%d toCopy=%d queued=%d dequeued=%d sample=0x%08x\n",
+           inOutputTime->mSampleTime,
+           internal->firstValidByteOffset, internal->validByteCount,
+           samplesToCopy, internal->bytesQueued, internal->bytesDequeued, sample);
+
     internal->validByteCount -= bytesToCopy;
-    internal->firstValidByteOffset = (internal->firstValidByteOffset + bytesToCopy) % internal->bufferByteCount;
-    
+    internal->firstValidByteOffset =
+      (internal->firstValidByteOffset + bytesToCopy) % internal->bufferByteCount;
+
     // We don't have to deal with wrapping around in the buffer since the buffer is a
     // multiple of the output buffer size and we only copy on buffer at a time
     // (except on the last buffer when we may copy only a partial output buffer).
@@ -437,11 +438,9 @@
         outBuffer++;
         sample++;
     }
-    
+
     pthread_mutex_unlock(&internal->mutex);
     pthread_cond_signal(&internal->condition);
-    
+
     return 0;
 }
-
-

Modified: trunk/ao/src/plugins/nas/ao_nas.c
===================================================================
--- trunk/ao/src/plugins/nas/ao_nas.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/plugins/nas/ao_nas.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -45,7 +45,8 @@
   "buf_size", /* Buffer size on server */
   "quiet",
   "verbose",
-  "matrix"
+  "matrix",
+  "debug"
 };
 
 static ao_info ao_nas_info =
@@ -58,7 +59,7 @@
 	AO_FMT_NATIVE,
 	10,
 	ao_nas_options,
-	5
+	6
 };
 
 

Modified: trunk/ao/src/plugins/oss/ao_oss.c
===================================================================
--- trunk/ao/src/plugins/oss/ao_oss.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/plugins/oss/ao_oss.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -45,7 +45,7 @@
 #include "ao/plugin.h"
 
 
-static char *ao_oss_options[] = {"dsp","verbose","quiet","matrix"};
+static char *ao_oss_options[] = {"dsp","verbose","quiet","matrix","debug"};
 static ao_info ao_oss_info =
 {
 	AO_TYPE_LIVE,
@@ -56,7 +56,7 @@
 	AO_FMT_NATIVE,
 	20,
 	ao_oss_options,
-	4
+	5
 };
 
 
@@ -123,12 +123,7 @@
 	/* Deal with error cases */
 	if(fd < 0)
 	{
-	  /*			fprintf(stderr,
-				"libao - error: Could not open either default device:\n"
-				"  %s - %s\n"
-				"  %s - %s\n",
-				err, dev,
-				strerror(errno), *dev_path); */
+                /* could not open either default device */
 		free(*dev_path);
 		*dev_path = NULL;
 	}
@@ -212,8 +207,7 @@
 		internal->fd = open(internal->dev, O_WRONLY);
 
 		if(internal->fd < 0) {
-		  /* fprintf(stderr,"libao - %s: Opening audio device %s\n",
-		     strerror(errno), internal->dev); */
+                  aerror("open(%s) => %s",internal->dev,strerror(errno));
 			return 0;  /* Cannot open device */
 		}
 
@@ -231,16 +225,16 @@
 		break;
 	case 2: tmp = 1;
 		break;
-	default:fprintf(stderr,"libao - Unsupported number of channels: %d.",
-			format->channels);
+	default:aerror("Unsupported number of channels: %d.",
+                       format->channels);
 		goto ERR;
 	}
 
 	if (ioctl(internal->fd,SNDCTL_DSP_STEREO,&tmp) < 0 ||
 			tmp+1 != format->channels) {
-		fprintf(stderr, "libao - OSS cannot set channels to %d\n",
-			format->channels);
-		goto ERR;
+          aerror("cannot set channels to %d\n",
+                 format->channels);
+          goto ERR;
 	}
 
 	/* To eliminate the need for a swap buffer, we set the device
@@ -253,13 +247,13 @@
 		   AFMT_S16_BE : AFMT_S16_LE;
 	        device->driver_byte_format = device->client_byte_format;
 	        break;
-	default:fprintf(stderr,"libao - Unsupported number of bits: %d.",
+	default:aerror("Unsupported number of bits: %d.",
 			format->bits);
 		goto ERR;
 	}
 
 	if (ioctl(internal->fd,SNDCTL_DSP_SAMPLESIZE,&tmp) < 0) {
-		fprintf(stderr, "libao - OSS cannot set sample size to %d\n",
+		aerror("cannot set sample size to %d\n",
 			format->bits);
 		goto ERR;
 	}
@@ -270,7 +264,7 @@
 	   of whack. */
 	if (ioctl(internal->fd,SNDCTL_DSP_SPEED, &tmp) < 0
 	    || tmp > 1.02 * format->rate || tmp < 0.98 * format->rate) {
-		fprintf(stderr, "libao - OSS cannot set rate to %d\n",
+		aerror("cannot set rate to %d\n",
 			format->rate);
 		goto ERR;
 	}
@@ -281,8 +275,8 @@
 				&(internal->buf_size)) < 0) ||
 			internal->buf_size<=0 )
 	{
-		fprintf(stderr, "libao - OSS cannot get buffer size for "
-				" device\n");
+		aerror("cannot get buffer size for "
+                        " device\n");
 		goto ERR;
 	}
 

Modified: trunk/ao/src/plugins/pulse/ao_pulse.c
===================================================================
--- trunk/ao/src/plugins/pulse/ao_pulse.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/plugins/pulse/ao_pulse.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -44,7 +44,8 @@
     "sink",
     "verbose",
     "quiet",
-    "matrix"
+    "matrix",
+    "debug"
 };
 
 static ao_info ao_pulse_info = {
@@ -56,7 +57,7 @@
     AO_FMT_NATIVE,
     50,
     ao_pulse_options,
-    5
+    6
 };
 
 typedef struct ao_pulse_internal {

Modified: trunk/ao/src/plugins/sun/ao_sun.c
===================================================================
--- trunk/ao/src/plugins/sun/ao_sun.c	2010-01-28 05:55:38 UTC (rev 16837)
+++ trunk/ao/src/plugins/sun/ao_sun.c	2010-01-28 06:58:08 UTC (rev 16838)
@@ -49,7 +49,7 @@
 #endif
 
 
-static char *ao_sun_options[] = {"dev","verbose","quiet","matrix"};
+static char *ao_sun_options[] = {"dev","verbose","quiet","matrix","debug"};
 ao_info ao_sun_info = {
 	AO_TYPE_LIVE,
 	"Sun audio driver output",
@@ -59,7 +59,7 @@
 	AO_FMT_NATIVE,
 	20,
 	ao_sun_options,
-	4
+	5
 };
 
 



More information about the commits mailing list