PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.47k stars 304 forks source link

Add support for Jack under Mac OSX #25

Closed PortAudio-admin closed 12 years ago

PortAudio-admin commented 18 years ago

Issue created by Anonymous on Assembla

[Trac: Originally reported by leland_lucius on 2006-09-24 19:33:15]

The attached patch adds support for using Jack under Mac OSX. It includes a fix for memory overlays in pa_jack.c and fixes building CoreAudio and Jack at the same time.

There was a problem with duplicate symbols due to CoreAudio haveing its own version of pablio/ringbuffer.c and the way pa_jack.c included the same file. So, I took the ringbuffer.c|h files from the hostapi/coreaudio directory, added the Linux memory barriers, and moved it back to the pablio directory.

Now, CoreAudio and Jack use the same ringbuffer code and CoreAudio doesn't have to have its own copy.

diff -wruN orig/audacity/lib-src/portaudio-v19/configure.in audacity/lib-src/portaudio-v19/configure.in
--- orig/audacity/lib-src/portaudio-v19/configure.in    2006-09-23 13:42:43.000000000 -0500
+++ audacity/lib-src/portaudio-v19/configure.in 2006-09-23 22:39:16.000000000 -0500
@@ -136,10 +136,12 @@
    dnl Mac OS X configuration

    AC_DEFINE(PA_USE_COREAUDIO)
-   OTHER_OBJS="src/os/mac_osx/pa_mac_hostapis.o src/os/unix/pa_unix_util.o src/hostapi/coreaudio/pa_mac_core.o";
+   OTHER_OBJS="src/os/mac_osx/pa_mac_hostapis.o src/os/unix/pa_unix_util.o src/hostapi/coreaudio/pa_mac_core.o src/hostapi/coreaudio/pa_mac_core_blocking.o src/hostapi/coreaudio/pa_mac_core_utilities.o pablio/ringbuffer.o";
    LIBS="-framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon";
    PADLL="libportaudio.dylib";
    SHARED_FLAGS="-framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon -dynamiclib";
+   CFLAGS="$CFLAGS -I\$(top_srcdir)/pablio"
+
         if [[ $with_macapi = "asio" ]] ; then
             if [[ $with_asiodir ]] ; then
               ASIODIR="$with_asiodir";
@@ -152,6 +154,14 @@
             CFLAGS="$CFLAGS -I\$(top_srcdir)/pa_asio -I$ASIDIR/host/mac -I$ASIODIR/common";
             CXXFLAGS="$CFLAGS";
         fi
+
+        if [[ $have_jack = "yes" ] && [ $with_jack != "no" ]] ; then
+           DLL_LIBS="$DLL_LIBS $JACK_LIBS"
+           CFLAGS="$CFLAGS $JACK_CFLAGS"
+           OTHER_OBJS="$OTHER_OBJS src/hostapi/jack/pa_jack.o pablio/ringbuffer.o"
+                     AC_DEFINE(PA_USE_JACK)
+        fi
+     
    ;;

   mingw* )
@@ -271,7 +281,7 @@
    if [[ $have_jack = "yes" ] && [ $with_jack != "no" ]] ; then
        DLL_LIBS="$DLL_LIBS $JACK_LIBS"
        CFLAGS="$CFLAGS $JACK_CFLAGS"
-       OTHER_OBJS="$OTHER_OBJS src/hostapi/jack/pa_jack.o"
+       OTHER_OBJS="$OTHER_OBJS src/hostapi/jack/pa_jack.o pablio/ringbuffer.o"
                 AC_DEFINE(PA_USE_JACK)
    fi

diff -wruN orig/audacity/lib-src/portaudio-v19/pablio/ringbuffer.c audacity/lib-src/portaudio-v19/pablio/ringbuffer.c
--- orig/audacity/lib-src/portaudio-v19/pablio/ringbuffer.c 2006-09-23 13:42:46.000000000 -0500
+++ audacity/lib-src/portaudio-v19/pablio/ringbuffer.c  2006-09-24 04:20:24.000000000 -0500
@@ -1,9 +1,14 @@
 /*
- * $Id: ringbuffer.c,v 1.4 2006/09/23 18:42:46 llucius Exp $
+ * $Id: ringbuffer.c,v 1.3 2006/09/23 18:42:49 llucius Exp $
  * ringbuffer.c
  * Ring Buffer utility..
  *
  * Author: Phil Burk, http://www.softsynth.com
+ * modified for SMP safety on Mac OS X by Bjorn Roche
+ * modified for SMP safety on Linux by Leland Lucius
+ * also, allowed for const where possible
+ * Note that this is safe only for a single-thread reader and a
+ * single-thread writer.
  *
  * This program uses the PortAudio Portable Audio Library.
  * For more information see: http://www.portaudio.com
@@ -40,12 +45,53 @@
  * license above.
  */

+/**
+ @file
+ @ingroup hostapi_src
+*/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
 #include "ringbuffer.h"
 #include <string.h>

+/****************
+ * First, we'll define some memory barrier primitives based on the system.
+ * right now only OS X, FreeBSD, and Linux are supported. In addition to providing
+ * memory barriers, these functions should ensure that data cached in registers
+ * is written out to cache where it can be snooped by other CPUs. (ie, the volatile
+ * keyword should not be required)
+ *
+ * the primitives that must be defined are:
+ *
+ * FullMemoryBarrier()
+ * ReadMemoryBarrier()
+ * WriteMemoryBarrier()
+ *
+ ****************/
+
+#if defined(__APPLE__) || defined(__FreeBSD__)
+#   include <libkern/OSAtomic.h>
+    /* Here are the memory barrier functions. Mac OS X and FreeBSD only provide
+       full memory barriers, so the three types of barriers are the same.
+       The asm volatile may be redundant with the memory barrier, but
+       until I have proof of that, I'm leaving it. */
+#   define FullMemoryBarrier()  do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false)
+#   define ReadMemoryBarrier()  do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false)
+#   define WriteMemoryBarrier() do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false)
+#   define MPSAFE
+#elif defined(__linux__)
+#   include <asm/system.h>
+    /* Here are the memory barrier functions. */
+#   define FullMemoryBarrier()  do{ asm volatile("":::"memory"); smp_mb(); }while(false)
+#   define ReadMemoryBarrier()  do{ asm volatile("":::"memory"); smp_rmb(); }while(false)
+#   define WriteMemoryBarrier() do{ asm volatile("":::"memory"); smp_wmb(); }while(false)
+#   define MPSAFE
+#else
+#   warning Memory barriers not defined on this system or system unknown
+#endif
+
 /***************************************************************************
  * Initialize FIFO.
  * numBytes must be power of 2, returns -1 if not.
@@ -64,12 +110,16 @@
 ** Return number of bytes available for reading. */
 long RingBuffer_GetReadAvailable( RingBuffer *rbuf )
 {
+#ifdef MPSAFE
+    ReadMemoryBarrier();
+#endif
     return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask );
 }
 /***************************************************************************
 ** Return number of bytes available for writing. */
 long RingBuffer_GetWriteAvailable( RingBuffer *rbuf )
 {
+    /* Since we are calling RingBuffer_GetReadAvailable, we don't need an aditional MB */
     return ( rbuf->bufferSize - RingBuffer_GetReadAvailable(rbuf));
 }

@@ -119,7 +169,13 @@
 */
 long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes )
 {
+#ifdef MPSAFE
+    /* we need to ensure that previous writes are seen before we update the write index */
+    WriteMemoryBarrier();
     return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
+#else
+    return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
+#endif
 }

 /***************************************************************************
@@ -159,12 +215,18 @@
 */
 long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes )
 {
+#ifdef MPSAFE
+    /* we need to ensure that previous writes are always seen before updating the index. */
+    WriteMemoryBarrier();
+    return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
+#else
     return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
+#endif
 }

 /***************************************************************************
 ** Return bytes written. */
-long RingBuffer_Write( RingBuffer *rbuf, void *data, long numBytes )
+long RingBuffer_Write( RingBuffer *rbuf, const void *data, long numBytes )
 {
     long size1, size2, numWritten;
     void *data1, *data2;
diff -wruN orig/audacity/lib-src/portaudio-v19/pablio/ringbuffer.h audacity/lib-src/portaudio-v19/pablio/ringbuffer.h
--- orig/audacity/lib-src/portaudio-v19/pablio/ringbuffer.h 2006-09-23 13:42:46.000000000 -0500
+++ audacity/lib-src/portaudio-v19/pablio/ringbuffer.h  2006-09-24 04:20:48.000000000 -0500
@@ -6,11 +6,15 @@
 #endif /* __cplusplus */

 /*
- * $Id: ringbuffer.h,v 1.4 2006/09/23 18:42:46 llucius Exp $
+ * $Id: ringbuffer.h,v 1.3 2006/09/23 18:42:49 llucius Exp $
  * ringbuffer.h
  * Ring Buffer utility..
  *
  * Author: Phil Burk, http://www.softsynth.com
+ * modified for SMP safety on OS X by Bjorn Roche.
+ * also allowed for const where possible.
+ * Note that this is safe only for a single-thread reader
+ * and a single-thread writer.
  *
  * This program is distributed with the PortAudio Portable Audio Library.
  * For more information see: http://www.portaudio.com
@@ -47,6 +51,11 @@
  * license above.
  */

+/**
+ @file
+ @ingroup hostapi_src
+*/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
@@ -77,7 +86,7 @@
 /* Return number of bytes available for read. */
 long RingBuffer_GetReadAvailable( RingBuffer *rbuf );
 /* Return bytes written. */
-long RingBuffer_Write( RingBuffer *rbuf, void *data, long numBytes );
+long RingBuffer_Write( RingBuffer *rbuf, const void *data, long numBytes );
 /* Return bytes read. */
 long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes );

diff -wruN orig/audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.c audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.c
--- orig/audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.c  2006-09-23 13:42:49.000000000 -0500
+++ audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.c   1969-12-31 18:00:00.000000000 -0600
@@ -1,266 +0,0 @@
-/*
- * $Id: ringbuffer.c,v 1.3 2006/09/23 18:42:49 llucius Exp $
- * ringbuffer.c
- * Ring Buffer utility..
- *
- * Author: Phil Burk, http://www.softsynth.com
- * modified for SMP safety on Mac OS X by Bjorn Roche
- * also, alowed for const where possible
- * Note that this is safe only for a single-thread reader and a
- * single-thread writer.
- *
- * This program uses the PortAudio Portable Audio Library.
- * For more information see: http://www.portaudio.com
- * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files
- * (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * The text above constitutes the entire PortAudio license; however, 
- * the PortAudio community also makes the following non-binding requests:
- *
- * Any person wishing to distribute modifications to the Software is
- * requested to send the modifications to the original developer so that
- * they can be incorporated into the canonical version. It is also 
- * requested that these non-binding requests be included along with the 
- * license above.
- */
-
-/**
- @file
- @ingroup hostapi_src
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include "ringbuffer.h"
-#include <string.h>
-
-/*
- * We can undefine this, to turn off memory barriers, but that
- * is only useful if we know we don't need to be MP safe or
- * we are interested in doing some kind of tests.
- */
-#define MPSAFE
-
-/****************
- * First, we'll define some memory barrier primitives based on the system.
- * right now only OS X and FreeBSD are supported. In addition to providing
- * memory barriers, these functions should ensure that data cached in registers
- * is written out to cache where it can be snooped by other CPUs. (ie, the volatile
- * keyword should not be required)
- *
- * the primitives that must be defined are:
- *
- * FullMemoryBarrier()
- * ReadMemoryBarrier()
- * WriteMemoryBarrier()
- *
- ****************/
-
-#if defined(__APPLE__) || defined(__FreeBSD__)
-#   include <libkern/OSAtomic.h>
-    /* Here are the memory barrier functions. Mac OS X and FreeBSD only provide
-       full memory barriers, so the three types of barriers are the same.
-       The asm volatile may be redundant with the memory barrier, but
-       until I have proof of that, I'm leaving it. */
-#   define FullMemoryBarrier()  do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false)
-#   define ReadMemoryBarrier()  do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false)
-#   define WriteMemoryBarrier() do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false)
-#else
-#   error Memory Barriers not defined on this system or system unknown
-#endif
-
-/***************************************************************************
- * Initialize FIFO.
- * numBytes must be power of 2, returns -1 if not.
- */
-long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr )
-{
-    if( ((numBytes-1) & numBytes) != 0) return -1; /* Not Power of two. */
-    rbuf->bufferSize = numBytes;
-    rbuf->buffer = (char *)dataPtr;
-    RingBuffer_Flush( rbuf );
-    rbuf->bigMask = (numBytes*2)-1;
-    rbuf->smallMask = (numBytes)-1;
-    return 0;
-}
-/***************************************************************************
-** Return number of bytes available for reading. */
-long RingBuffer_GetReadAvailable( RingBuffer *rbuf )
-{
-#ifdef MPSAFE
-    ReadMemoryBarrier();
-#endif
-    return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask );
-}
-/***************************************************************************
-** Return number of bytes available for writing. */
-long RingBuffer_GetWriteAvailable( RingBuffer *rbuf )
-{
-    /* Since we are calling RingBuffer_GetReadAvailable, we don't need an aditional MB */
-    return ( rbuf->bufferSize - RingBuffer_GetReadAvailable(rbuf));
-}
-
-/***************************************************************************
-** Clear buffer. Should only be called when buffer is NOT being read. */
-void RingBuffer_Flush( RingBuffer *rbuf )
-{
-    rbuf->writeIndex = rbuf->readIndex = 0;
-}
-
-/***************************************************************************
-** Get address of region(s) to which we can write data.
-** If the region is contiguous, size2 will be zero.
-** If non-contiguous, size2 will be the size of second region.
-** Returns room available to be written or numBytes, whichever is smaller.
-*/
-long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes,
-                                 void **dataPtr1, long *sizePtr1,
-                                 void **dataPtr2, long *sizePtr2 )
-{
-    long   index;
-    long   available = RingBuffer_GetWriteAvailable( rbuf );
-    if( numBytes > available ) numBytes = available;
-    /* Check to see if write is not contiguous. */
-    index = rbuf->writeIndex & rbuf->smallMask;
-    if( (index + numBytes) > rbuf->bufferSize )
-    {
-        /* Write data in two blocks that wrap the buffer. */
-        long   firstHalf = rbuf->bufferSize - index;
-        *dataPtr1 = &rbuf->buffer[index];
-        *sizePtr1 = firstHalf;
-        *dataPtr2 = &rbuf->buffer[0];
-        *sizePtr2 = numBytes - firstHalf;
-    }
-    else
-    {
-        *dataPtr1 = &rbuf->buffer[index];
-        *sizePtr1 = numBytes;
-        *dataPtr2 = NULL;
-        *sizePtr2 = 0;
-    }
-    return numBytes;
-}
-
-
-/***************************************************************************
-*/
-long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes )
-{
-#ifdef MPSAFE
-    /* we need to ensure that previous writes are seen before we update the write index */
-    WriteMemoryBarrier();
-    return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
-#else
-    return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
-#endif
-}
-
-/***************************************************************************
-** Get address of region(s) from which we can read data.
-** If the region is contiguous, size2 will be zero.
-** If non-contiguous, size2 will be the size of second region.
-** Returns room available to be written or numBytes, whichever is smaller.
-*/
-long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes,
-                                void **dataPtr1, long *sizePtr1,
-                                void **dataPtr2, long *sizePtr2 )
-{
-    long   index;
-    long   available = RingBuffer_GetReadAvailable( rbuf );
-    if( numBytes > available ) numBytes = available;
-    /* Check to see if read is not contiguous. */
-    index = rbuf->readIndex & rbuf->smallMask;
-    if( (index + numBytes) > rbuf->bufferSize )
-    {
-        /* Write data in two blocks that wrap the buffer. */
-        long firstHalf = rbuf->bufferSize - index;
-        *dataPtr1 = &rbuf->buffer[index];
-        *sizePtr1 = firstHalf;
-        *dataPtr2 = &rbuf->buffer[0];
-        *sizePtr2 = numBytes - firstHalf;
-    }
-    else
-    {
-        *dataPtr1 = &rbuf->buffer[index];
-        *sizePtr1 = numBytes;
-        *dataPtr2 = NULL;
-        *sizePtr2 = 0;
-    }
-    return numBytes;
-}
-/***************************************************************************
-*/
-long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes )
-{
-#ifdef MPSAFE
-    /* we need to ensure that previous writes are always seen before updating the index. */
-    WriteMemoryBarrier();
-    return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
-#else
-    return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
-#endif
-}
-
-/***************************************************************************
-** Return bytes written. */
-long RingBuffer_Write( RingBuffer *rbuf, const void *data, long numBytes )
-{
-    long size1, size2, numWritten;
-    void *data1, *data2;
-    numWritten = RingBuffer_GetWriteRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
-    if( size2 > 0 )
-    {
-
-        memcpy( data1, data, size1 );
-        data = ((char *)data) + size1;
-        memcpy( data2, data, size2 );
-    }
-    else
-    {
-        memcpy( data1, data, size1 );
-    }
-    RingBuffer_AdvanceWriteIndex( rbuf, numWritten );
-    return numWritten;
-}
-
-/***************************************************************************
-** Return bytes read. */
-long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes )
-{
-    long size1, size2, numRead;
-    void *data1, *data2;
-    numRead = RingBuffer_GetReadRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
-    if( size2 > 0 )
-    {
-        memcpy( data, data1, size1 );
-        data = ((char *)data) + size1;
-        memcpy( data, data2, size2 );
-    }
-    else
-    {
-        memcpy( data, data1, size1 );
-    }
-    RingBuffer_AdvanceReadIndex( rbuf, numRead );
-    return numRead;
-}
diff -wruN orig/audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.h audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.h
--- orig/audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.h  2006-09-23 13:42:49.000000000 -0500
+++ audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.h   1969-12-31 18:00:00.000000000 -0600
@@ -1,117 +0,0 @@
-#ifndef _RINGBUFFER_H
-#define _RINGBUFFER_H
-#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-
-/*
- * $Id: ringbuffer.h,v 1.3 2006/09/23 18:42:49 llucius Exp $
- * ringbuffer.h
- * Ring Buffer utility..
- *
- * Author: Phil Burk, http://www.softsynth.com
- * modified for SMP safety on OS X by Bjorn Roche.
- * also allowed for const where possible.
- * Note that this is safe only for a single-thread reader
- * and a single-thread writer.
- *
- * This program is distributed with the PortAudio Portable Audio Library.
- * For more information see: http://www.portaudio.com
- * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files
- * (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * The text above constitutes the entire PortAudio license; however, 
- * the PortAudio community also makes the following non-binding requests:
- *
- * Any person wishing to distribute modifications to the Software is
- * requested to send the modifications to the original developer so that
- * they can be incorporated into the canonical version. It is also 
- * requested that these non-binding requests be included along with the 
- * license above.
- */
-
-/**
- @file
- @ingroup hostapi_src
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include "ringbuffer.h"
-#include <string.h>
-
-typedef struct
-{
-    long   bufferSize; /* Number of bytes in FIFO. Power of 2. Set by RingBuffer_Init. */
-    long   writeIndex; /* Index of next writable byte. Set by RingBuffer_AdvanceWriteIndex. */
-    long   readIndex;  /* Index of next readable byte. Set by RingBuffer_AdvanceReadIndex. */
-    long   bigMask;    /* Used for wrapping indices with extra bit to distinguish full/empty. */
-    long   smallMask;  /* Used for fitting indices to buffer. */
-    char * buffer;
-}
-RingBuffer;
-/*
- * Initialize Ring Buffer.
- * numBytes must be power of 2, returns -1 if not.
- */
-long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr );
-
-/* Clear buffer. Should only be called when buffer is NOT being read. */
-void RingBuffer_Flush( RingBuffer *rbuf );
-
-/* Return number of bytes available for writing. */
-long RingBuffer_GetWriteAvailable( RingBuffer *rbuf );
-/* Return number of bytes available for read. */
-long RingBuffer_GetReadAvailable( RingBuffer *rbuf );
-/* Return bytes written. */
-long RingBuffer_Write( RingBuffer *rbuf, const void *data, long numBytes );
-/* Return bytes read. */
-long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes );
-
-/* Get address of region(s) to which we can write data.
-** If the region is contiguous, size2 will be zero.
-** If non-contiguous, size2 will be the size of second region.
-** Returns room available to be written or numBytes, whichever is smaller.
-*/
-long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes,
-                                 void **dataPtr1, long *sizePtr1,
-                                 void **dataPtr2, long *sizePtr2 );
-long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes );
-
-/* Get address of region(s) from which we can read data.
-** If the region is contiguous, size2 will be zero.
-** If non-contiguous, size2 will be the size of second region.
-** Returns room available to be written or numBytes, whichever is smaller.
-*/
-long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes,
-                                void **dataPtr1, long *sizePtr1,
-                                void **dataPtr2, long *sizePtr2 );
-
-long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes );
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* _RINGBUFFER_H */
diff -wruN orig/audacity/lib-src/portaudio-v19/src/hostapi/jack/pa_jack.c audacity/lib-src/portaudio-v19/src/hostapi/jack/pa_jack.c
--- orig/audacity/lib-src/portaudio-v19/src/hostapi/jack/pa_jack.c  2006-09-23 13:42:50.000000000 -0500
+++ audacity/lib-src/portaudio-v19/src/hostapi/jack/pa_jack.c   2006-09-24 02:23:39.000000000 -0500
@@ -68,7 +68,7 @@
 #include "pa_process.h"
 #include "pa_allocation.h"
 #include "pa_cpuload.h"
-#include "../pablio/ringbuffer.c"
+#include "ringbuffer.h"

 static int aErr_;
 static PaError paErr_;     /* For use with ENSURE_PA */
@@ -466,12 +466,12 @@

     const char **jack_ports = NULL;
     char **client_names = NULL;
-    char *regex_pattern = MALLOC( jack_client_name_size() + 3 );
+    char *regex_pattern = NULL;
     int port_index, client_index, i;
     double globalSampleRate;
     regex_t port_regex;
     unsigned long numClients = 0, numPorts = 0;
-    char *tmp_client_name = MALLOC( jack_client_name_size() );
+    char *tmp_client_name = NULL;

     commonApi->info.defaultInputDevice = paNoDevice;
     commonApi->info.defaultOutputDevice = paNoDevice;
@@ -484,6 +484,9 @@
      * associated with the previous list */
     PaUtil_FreeAllAllocations( jackApi->deviceInfoMemory );

+    regex_pattern = MALLOC( jack_client_name_size() + 3 );
+    tmp_client_name = MALLOC( jack_client_name_size() );
+
     /* We can only retrieve the list of clients indirectly, by first
      * asking for a list of all ports, then parsing the port names
      * according to the client_name:port_name convention (which is
PortAudio-admin commented 18 years ago

Comment by @bejayoharen

According to Stephane Letz, this patch is not required:

From:     letz@grame.fr
Subject:    [Portaudio] PA 19 working with JackOSX
Date:   May 25, 2006 9:50:54 AM EDT
To:       portaudio@techweb.rfa.org

Hi,

Just let you know that PA 19 is working correctly when used with JackOSX (www.jackosx.com) on OSX.

Thus a PortAudio based application using the CoreAudio backend, will became a Jack client (using the JackRouter driver part of the JackOSX package) This was not working with PA 18. I've not tested the direct PortAudio ==> Jack backend on OSX. but this should work also

Best Regards

Stephane Letz


Portaudio mailing list Portaudio@techweb.rfa.org http://techweb.rfa.org/mailman/listinfo/portaudio

PortAudio-admin commented 17 years ago

Comment by @bejayoharen

This patch is no longer valid against the current code, but the core-aduio related changes should be taken care of. This ticket should be reassigned to the Jack Person, but I don;t know who that is.

PortAudio-admin commented 17 years ago

Comment by Anonymous on Assembla

[Trac: Originally commented by leland_lucius on 2006-09-24 19:33:15]

Stephane is correct. As-is, portaudio does indeed work when using the Jack router. But, the patch also adds native (or direct) Jack support. This removes the need to have the router running and is akin to the support in Linux.

Let me break down the patch as suggested by Ross and then let's see what Jack-specific stuff is left. I'll be working on that this evening.

Leland

PortAudio-admin commented 17 years ago

Comment by Anonymous on Assembla

[Trac: Originally commented by leland_lucius on 2006-09-24 19:33:15]

Bjorn,

I've attached a new Jack patch that has all of the ringbuffer stuff stripped out. If you and Ross approve those changes, then this new patch is all that is needed to include native Jack support on OSX.

Leland

diff -ruN orig/v19-devel/configure v19-devel/configure
--- orig/v19-devel/configure    2006-11-25 01:19:53.000000000 -0600
+++ v19-devel/configure 2006-11-25 01:19:24.000000000 -0600
@@ -20528,6 +20528,17 @@
             CFLAGS="$CFLAGS -I\$(top_srcdir)/pa_asio -I$ASIDIR/host/mac -I$ASIODIR/common";
             CXXFLAGS="$CFLAGS";
         fi
+
+        if [ $have_jack = "yes" ] && [ $with_jack != "no" ] ; then
+           DLL_LIBS="$DLL_LIBS $JACK_LIBS"
+           CFLAGS="$CFLAGS $JACK_CFLAGS"
+           OTHER_OBJS="$OTHER_OBJS src/hostapi/jack/pa_jack.o"
+           cat >>confdefs.h <<\_ACEOF
+#define PA_USE_JACK 1
+_ACEOF
+
+        fi
+
    ;;

   mingw* )
diff -ruN orig/v19-devel/configure.in v19-devel/configure.in
--- orig/v19-devel/configure.in 2006-11-25 01:19:53.000000000 -0600
+++ v19-devel/configure.in  2006-11-25 01:19:14.000000000 -0600
@@ -152,6 +152,14 @@
             CFLAGS="$CFLAGS -I\$(top_srcdir)/pa_asio -I$ASIDIR/host/mac -I$ASIODIR/common";
             CXXFLAGS="$CFLAGS";
         fi
+
+        if [[ $have_jack = "yes" ] && [ $with_jack != "no" ]] ; then
+           DLL_LIBS="$DLL_LIBS $JACK_LIBS"
+           CFLAGS="$CFLAGS $JACK_CFLAGS"
+           OTHER_OBJS="$OTHER_OBJS src/hostapi/jack/pa_jack.o"
+           AC_DEFINE(PA_USE_JACK)
+        fi
+     
    ;;

   mingw* )
PortAudio-admin commented 17 years ago

Comment by @bejayoharen

fixed in revision 1191

PortAudio-admin commented 12 years ago

Comment by @RossBencina

TRAC migration: propagating ticket status from TRAC

PortAudio-admin commented 12 years ago

Issue closed by @RossBencina