changeset 53:f6887767487c trunk

[svn] - import latest xmms-jack version 0.17 (mostly bio2jack fixes)
author giacomo
date Mon, 25 Sep 2006 11:23:54 -0700
parents ac74515f80c1
children 81f5de113b23
files ChangeLog src/jack/bio2jack.c src/jack/jack.c
diffstat 3 files changed, 112 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Sep 22 14:25:52 2006 -0700
+++ b/ChangeLog	Mon Sep 25 11:23:54 2006 -0700
@@ -1,3 +1,10 @@
+2006-09-22 21:25:52 +0000  Jonathan Schleifer <js@h3c.de>
+  revision [104]
+  Add +1 to the position so that the position isn't in two tracks anymore
+  trunk/src/cue/cuesheet.c |    3 ++-
+  1 file changed, 2 insertions(+), 1 deletion(-)
+
+
 2006-09-22 21:18:37 +0000  Jonathan Schleifer <js@h3c.de>
   revision [102]
   Fixed a crash in the cue plugin when no plugin is found / the file doesn't exist
--- a/src/jack/bio2jack.c	Fri Sep 22 14:25:52 2006 -0700
+++ b/src/jack/bio2jack.c	Mon Sep 25 11:23:54 2006 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003-2004 Chris Morgan <cmorgan@alum.wpi.edu>
+ * Copyright 2003-2006 Chris Morgan <cmorgan@alum.wpi.edu>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -56,7 +56,7 @@
 
 #define ENABLE_WARNINGS         0
 
-#define DEFAULT_RB_SIZE         16384
+#define DEFAULT_RB_SIZE         4096
 
 #define OUTFILE stderr
 
@@ -299,6 +299,34 @@
   return drv;
 }
 
+#if TRACE_getReleaseDevice
+#define tryGetDriver(x) _tryGetDriver(x,fprintf(OUTFILE, "%s::%s(%d) trying to get driver %d\n", __FILE__, __FUNCTION__, __LINE__,x)); TRACE("got driver %d\n",x);
+jack_driver_t *
+_tryGetDriver(int deviceID, int ignored)
+{
+  fflush(OUTFILE);
+#else
+jack_driver_t *
+tryGetDriver(int deviceID)
+{
+#endif
+  jack_driver_t *drv = &outDev[deviceID];
+
+  int err;
+  if((err = pthread_mutex_trylock(&drv->mutex)) == 0)
+    return drv;
+
+  if(err == EBUSY)
+  {
+    TRACE("driver %d is busy\n",deviceID);
+    return 0;
+  }
+
+  ERR("lock returned an error\n");
+  return 0;
+}
+
+
 /* release a device's mutex */
 /* */
 /* This macro is similar to the one for getDriver above, only simpler since we only
@@ -343,7 +371,7 @@
 
 
 #define SAMPLE_MAX_16BIT  32767.0f
-#define SAMPLE_MAX_8BIT   127.0f
+#define SAMPLE_MAX_8BIT   255.0f
 
 /* floating point volume routine */
 /* volume should be a value between 0.0 and 1.0 */
@@ -413,7 +441,7 @@
 
 /* convert from 8 bit to floating point */
 static inline void
-sample_move_char_float(sample_t * dst, char *src, unsigned long nsamples)
+sample_move_char_float(sample_t * dst, unsigned char *src, unsigned long nsamples)
 {
   /* ALERT: signed sign-extension portability !!! */
   unsigned long i;
@@ -423,7 +451,7 @@
 
 /* convert from floating point to 8 bit */
 static inline void
-sample_move_float_char(char *dst, sample_t * src, unsigned long nsamples)
+sample_move_float_char(unsigned char *dst, sample_t * src, unsigned long nsamples)
 {
   /* ALERT: signed sign-extension portability !!! */
   unsigned long i;
@@ -527,13 +555,13 @@
 #endif
 
       /* make sure our buffer is large enough for the data we are writing */
-      /* ie. callback_buffer1_size < (bytes we already wrote + bytes we are going to write in this loop) */
+      /* ie. callback_buffer2_size < (bytes we already wrote + bytes we are going to write in this loop) */
       if(!ensure_buffer_size
-         (&drv->callback_buffer1, &drv->callback_buffer1_size,
+         (&drv->callback_buffer2, &drv->callback_buffer2_size,
           jackBytesAvailable))
       {
-        ERR("allocated %lu bytes, need %u bytes\n",
-            drv->callback_buffer1_size, jackBytesAvailable);
+        ERR("allocated %lu bytes, need %lu bytes\n",
+            drv->callback_buffer2_size, (unsigned long)jackBytesAvailable);
         return -1;
       }
 
@@ -603,18 +631,6 @@
             jackFramesAvailable -= srcdata.output_frames_gen;   /* take away what was used */
           }
         }
-
-        if(src_error == 0)
-        {
-          /* demux the stream: we skip over the number of samples we have output channels as the channel data */
-          /* is encoded like chan1,chan2,chan3,chan1,chan2,chan3... */
-          for(i = 0; i < drv->num_output_channels; i++)
-          {
-            demux(out_buffer[i],
-                  (sample_t *) drv->callback_buffer2 + i,
-                  (nframes - jackFramesAvailable), drv->num_output_channels);
-          }
-        }
       }
       else                      /* no resampling needed or requested */
       {
@@ -623,20 +639,12 @@
         {
           /* write as many bytes as we have space remaining, or as much as we have data to write */
           numFramesToWrite = min(jackFramesAvailable, inputFramesAvailable);
-          jack_ringbuffer_read(drv->pPlayPtr, drv->callback_buffer1,
+          jack_ringbuffer_read(drv->pPlayPtr, drv->callback_buffer2,
                                jackBytesAvailable);
           /* add on what we wrote */
           read = numFramesToWrite * drv->bytes_per_output_frame;
           jackFramesAvailable -= numFramesToWrite;      /* take away what was written */
         }
-        /* demux the stream: we skip over the number of samples we have output channels as the channel data */
-        /* is encoded like chan1,chan2,chan3,chan1,chan2,chan3... */
-        for(i = 0; i < drv->num_output_channels; i++)
-        {
-          demux(out_buffer[i],
-                (sample_t *) drv->callback_buffer1 + i,
-                (nframes - jackFramesAvailable), drv->num_output_channels);
-        }
       }
 
       drv->written_client_bytes += read;
@@ -654,6 +662,38 @@
                                (nframes - jackFramesAvailable),
                                jackFramesAvailable);
       }
+
+      /* if we aren't converting or we are converting and src_error == 0 then we should */
+      /* apply volume and demux */
+      if(!(drv->output_src && drv->output_sample_rate_ratio != 1.0) || (src_error == 0))
+      {
+          /* apply volume */
+          for(i = 0; i < drv->num_output_channels; i++)
+          {
+              if(drv->volumeEffectType == dbAttenuation)
+              {
+                  /* assume the volume setting is dB of attenuation, a volume of 0 */
+                  /* is 0dB attenuation */
+                  float volume = powf(10.0, -((float) drv->volume[i]) / 20.0);
+                  float_volume_effect((sample_t *) drv->callback_buffer2 + i,
+                                      (nframes - jackFramesAvailable), volume, drv->num_output_channels);
+              } else
+              {
+                  float_volume_effect((sample_t *) drv->callback_buffer2 + i, (nframes - jackFramesAvailable),
+                                      ((float) drv->volume[i] / 100.0),
+                                      drv->num_output_channels);
+              }
+          }
+
+          /* demux the stream: we skip over the number of samples we have output channels as the channel data */
+          /* is encoded like chan1,chan2,chan3,chan1,chan2,chan3... */
+          for(i = 0; i < drv->num_output_channels; i++)
+          {
+              demux(out_buffer[i],
+                    (sample_t *) drv->callback_buffer2 + i,
+                    (nframes - jackFramesAvailable), drv->num_output_channels);
+          }
+      }
     }
 
     /* handle record data, if any */
@@ -721,19 +761,21 @@
             /* the ringbuffer is designed such that only one thread should ever access each pointer.
                since calling read_advance here will be touching the read pointer which is also accessed
                by JACK_Read, we need to lock the mutex first for safety */
-            getDriver(drv->deviceID);
-
-            /* double check the write space after we've gained the lock, just in case JACK_Read was being called
-               before we gained it */
-            write_space = jack_ringbuffer_write_space(drv->pRecPtr);
-            if(write_space < bytes_used)
+            jack_driver_t *d = tryGetDriver(drv->deviceID);
+            if( d )
             {
-              /* hey, we warn about underruns, we might as well warn about overruns as well */
-              WARN("buffer overrun of %ld bytes\n", jack_bytes - write_space);
-              jack_ringbuffer_read_advance(drv->pRecPtr,
-                                           bytes_used - write_space);
+              /* double check the write space after we've gained the lock, just
+                 in case JACK_Read was being called before we gained it */
+              write_space = jack_ringbuffer_write_space(drv->pRecPtr);
+              if(write_space < bytes_used)
+              {
+                /* hey, we warn about underruns, we might as well warn about overruns as well */
+                WARN("buffer overrun of %ld bytes\n", jack_bytes - write_space);
+                jack_ringbuffer_read_advance(drv->pRecPtr, bytes_used - write_space);
+              }
+
+              releaseDriver(drv);
             }
-            releaseDriver(drv);
           }
 
           jack_ringbuffer_write(drv->pRecPtr, drv->callback_buffer2,
@@ -750,18 +792,19 @@
           /* the ringbuffer is designed such that only one thread should ever access each pointer.
              since calling read_advance here will be touching the read pointer which is also accessed
              by JACK_Read, we need to lock the mutex first for safety */
-          getDriver(drv->deviceID);
-
-          /* double check the write space after we've gained the lock, just in case JACK_Read was being called
-             before we gained it */
-          write_space = jack_ringbuffer_write_space(drv->pRecPtr);
-          if(write_space < jack_bytes)
+	        jack_driver_t *d = tryGetDriver(drv->deviceID);
+          if( d )
           {
-            ERR("buffer overrun of %ld bytes\n", jack_bytes - write_space);
-            jack_ringbuffer_read_advance(drv->pRecPtr,
-                                         jack_bytes - write_space);
+            /* double check the write space after we've gained the lock, just
+               in case JACK_Read was being called before we gained it */
+            write_space = jack_ringbuffer_write_space(drv->pRecPtr);
+            if(write_space < jack_bytes)
+            {
+             ERR("buffer overrun of %ld bytes\n", jack_bytes - write_space);
+             jack_ringbuffer_read_advance(drv->pRecPtr, jack_bytes - write_space);
+            }
+	          releaseDriver(drv);
           }
-          releaseDriver(drv);
         }
 
         jack_ringbuffer_write(drv->pRecPtr, drv->callback_buffer1,
@@ -1750,33 +1793,15 @@
   switch (drv->bits_per_channel)
   {
   case 8:
-    sample_move_char_float((sample_t *) drv->rw_buffer1, (char *) data,
+    sample_move_char_float((sample_t *) drv->rw_buffer1, (unsigned char *) data,
                            frames * drv->num_output_channels);
+    break;
   case 16:
     sample_move_short_float((sample_t *) drv->rw_buffer1, (short *) data,
                             frames * drv->num_output_channels);
     break;
   }
 
-  int i;
-  for(i = 0; i < drv->num_output_channels; i++)
-  {
-    /* apply volume to the floating value */
-    if(drv->volumeEffectType == dbAttenuation)
-    {
-      /* assume the volume setting is dB of attenuation, a volume of 0 */
-      /* is 0dB attenuation */
-      float volume = powf(10.0, -((float) drv->volume[i]) / 20.0);
-      float_volume_effect((sample_t *) drv->rw_buffer1 + i,
-                          frames, volume, drv->num_output_channels);
-    } else
-    {
-      float_volume_effect((sample_t *) drv->rw_buffer1 + i, frames,
-                          ((float) drv->volume[i] / 100.0),
-                          drv->num_output_channels);
-    }
-  }
-
   DEBUG("ringbuffer read space = %d, write space = %d\n",
         jack_ringbuffer_read_space(drv->pPlayPtr),
         jack_ringbuffer_write_space(drv->pPlayPtr));
@@ -1878,7 +1903,7 @@
   switch (drv->bits_per_channel)
   {
   case 8:
-    sample_move_float_char((char *) data, (sample_t *) drv->rw_buffer1,
+    sample_move_float_char((unsigned char *) data, (sample_t *) drv->rw_buffer1,
                            frames * drv->num_input_channels);
     break;
   case 16:
--- a/src/jack/jack.c	Fri Sep 22 14:25:52 2006 -0700
+++ b/src/jack/jack.c	Mon Sep 25 11:23:54 2006 -0700
@@ -1,7 +1,7 @@
 /*      xmms - jack output plugin
  *	Copyright 2002 Chris Morgan<cmorgan@alum.wpi.edu>
  *
- *      audacious port (2005) by Giacomo Lozito from develia.org
+ *      audacious port (2005-2006) by Giacomo Lozito from develia.org
  *
  *	This code maps xmms calls into the jack translation library
  */
@@ -70,6 +70,7 @@
 
 static GtkWidget *dialog, *button, *label;
 
+
 void jack_set_volume(int l, int r);
 
 /* Giacomo's note: removed the destructor from the original xmms-jack, cause
@@ -222,6 +223,7 @@
 
   bmp_cfg_db_close(cfgfile);
 
+
   TRACE("initializing\n");
   JACK_Init(); /* initialize the driver */
 
@@ -584,13 +586,13 @@
 
 void jack_about(void)
 {
-	static GtkWidget *aboutbox;
+	static GtkWidget *aboutbox = NULL;
 	
-	if (!aboutbox)
+	if ( aboutbox == NULL )
 	{
 		aboutbox = xmms_show_message(
-			_("About JACK Output Plugin 0.15"),
-			_("XMMS jack Driver 0.15\n\n"
+			_("About JACK Output Plugin 0.17"),
+			_("XMMS jack Driver 0.17\n\n"
 			  "xmms-jack.sf.net\nChris Morgan<cmorgan@alum.wpi.edu>\n\n"
 			  "Audacious port by\nGiacomo Lozito from develia.org"),
 			_("Ok"), FALSE, NULL, NULL);
@@ -611,7 +613,7 @@
 {
 	NULL,
 	NULL,
-	"JACK Output Plugin 0.15",
+	"JACK Output Plugin 0.17",
 	jack_init,
 	jack_cleanup,
 	jack_about,