Ticket #25: macjack.diff

File macjack.diff, 24.8 KB (added by leland_lucius, 2 years ago)
  • audacity/lib-src/portaudio-v19/configure.in

    diff -wruN orig/audacity/lib-src/portaudio-v19/configure.in audacity/lib-src/portaudio-v19/configure.in
    old new  
    136136        dnl Mac OS X configuration 
    137137 
    138138        AC_DEFINE(PA_USE_COREAUDIO) 
    139         OTHER_OBJS="src/os/mac_osx/pa_mac_hostapis.o src/os/unix/pa_unix_util.o src/hostapi/coreaudio/pa_mac_core.o"; 
     139        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"; 
    140140        LIBS="-framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon"; 
    141141        PADLL="libportaudio.dylib"; 
    142142        SHARED_FLAGS="-framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon -dynamiclib"; 
     143        CFLAGS="$CFLAGS -I\$(top_srcdir)/pablio" 
     144 
    143145        if [[ $with_macapi = "asio" ]] ; then 
    144146            if [[ $with_asiodir ]] ; then 
    145147              ASIODIR="$with_asiodir"; 
     
    152154            CFLAGS="$CFLAGS -I\$(top_srcdir)/pa_asio -I$ASIDIR/host/mac -I$ASIODIR/common"; 
    153155            CXXFLAGS="$CFLAGS"; 
    154156        fi 
     157 
     158        if [[ $have_jack = "yes" ] && [ $with_jack != "no" ]] ; then 
     159           DLL_LIBS="$DLL_LIBS $JACK_LIBS" 
     160           CFLAGS="$CFLAGS $JACK_CFLAGS" 
     161           OTHER_OBJS="$OTHER_OBJS src/hostapi/jack/pa_jack.o pablio/ringbuffer.o" 
     162                     AC_DEFINE(PA_USE_JACK) 
     163        fi 
     164      
    155165        ;; 
    156166 
    157167  mingw* ) 
     
    271281        if [[ $have_jack = "yes" ] && [ $with_jack != "no" ]] ; then 
    272282                DLL_LIBS="$DLL_LIBS $JACK_LIBS" 
    273283                CFLAGS="$CFLAGS $JACK_CFLAGS" 
    274                 OTHER_OBJS="$OTHER_OBJS src/hostapi/jack/pa_jack.o" 
     284                OTHER_OBJS="$OTHER_OBJS src/hostapi/jack/pa_jack.o pablio/ringbuffer.o" 
    275285                AC_DEFINE(PA_USE_JACK) 
    276286        fi 
    277287 
  • audacity/lib-src/portaudio-v19/pablio/ringbuffer.c

    diff -wruN orig/audacity/lib-src/portaudio-v19/pablio/ringbuffer.c audacity/lib-src/portaudio-v19/pablio/ringbuffer.c
    old new  
    11/* 
    2  * $Id: ringbuffer.c,v 1.4 2006/09/23 18:42:46 llucius Exp $ 
     2 * $Id: ringbuffer.c,v 1.3 2006/09/23 18:42:49 llucius Exp $ 
    33 * ringbuffer.c 
    44 * Ring Buffer utility.. 
    55 * 
    66 * Author: Phil Burk, http://www.softsynth.com 
     7 * modified for SMP safety on Mac OS X by Bjorn Roche 
     8 * modified for SMP safety on Linux by Leland Lucius 
     9 * also, allowed for const where possible 
     10 * Note that this is safe only for a single-thread reader and a 
     11 * single-thread writer. 
    712 * 
    813 * This program uses the PortAudio Portable Audio Library. 
    914 * For more information see: http://www.portaudio.com 
     
    4045 * license above. 
    4146 */ 
    4247 
     48/** 
     49 @file 
     50 @ingroup hostapi_src 
     51*/ 
     52 
    4353#include <stdio.h> 
    4454#include <stdlib.h> 
    4555#include <math.h> 
    4656#include "ringbuffer.h" 
    4757#include <string.h> 
    4858 
     59/**************** 
     60 * First, we'll define some memory barrier primitives based on the system. 
     61 * right now only OS X, FreeBSD, and Linux are supported. In addition to providing 
     62 * memory barriers, these functions should ensure that data cached in registers 
     63 * is written out to cache where it can be snooped by other CPUs. (ie, the volatile 
     64 * keyword should not be required) 
     65 * 
     66 * the primitives that must be defined are: 
     67 * 
     68 * FullMemoryBarrier() 
     69 * ReadMemoryBarrier() 
     70 * WriteMemoryBarrier() 
     71 * 
     72 ****************/ 
     73 
     74#if defined(__APPLE__) || defined(__FreeBSD__) 
     75#   include <libkern/OSAtomic.h> 
     76    /* Here are the memory barrier functions. Mac OS X and FreeBSD only provide 
     77       full memory barriers, so the three types of barriers are the same. 
     78       The asm volatile may be redundant with the memory barrier, but 
     79       until I have proof of that, I'm leaving it. */ 
     80#   define FullMemoryBarrier()  do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false) 
     81#   define ReadMemoryBarrier()  do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false) 
     82#   define WriteMemoryBarrier() do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false) 
     83#   define MPSAFE 
     84#elif defined(__linux__) 
     85#   include <asm/system.h> 
     86    /* Here are the memory barrier functions. */ 
     87#   define FullMemoryBarrier()  do{ asm volatile("":::"memory"); smp_mb(); }while(false) 
     88#   define ReadMemoryBarrier()  do{ asm volatile("":::"memory"); smp_rmb(); }while(false) 
     89#   define WriteMemoryBarrier() do{ asm volatile("":::"memory"); smp_wmb(); }while(false) 
     90#   define MPSAFE 
     91#else 
     92#   warning Memory barriers not defined on this system or system unknown 
     93#endif 
     94 
    4995/*************************************************************************** 
    5096 * Initialize FIFO. 
    5197 * numBytes must be power of 2, returns -1 if not. 
     
    64110** Return number of bytes available for reading. */ 
    65111long RingBuffer_GetReadAvailable( RingBuffer *rbuf ) 
    66112{ 
     113#ifdef MPSAFE 
     114    ReadMemoryBarrier(); 
     115#endif 
    67116    return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask ); 
    68117} 
    69118/*************************************************************************** 
    70119** Return number of bytes available for writing. */ 
    71120long RingBuffer_GetWriteAvailable( RingBuffer *rbuf ) 
    72121{ 
     122    /* Since we are calling RingBuffer_GetReadAvailable, we don't need an aditional MB */ 
    73123    return ( rbuf->bufferSize - RingBuffer_GetReadAvailable(rbuf)); 
    74124} 
    75125 
     
    119169*/ 
    120170long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes ) 
    121171{ 
     172#ifdef MPSAFE 
     173    /* we need to ensure that previous writes are seen before we update the write index */ 
     174    WriteMemoryBarrier(); 
    122175    return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask; 
     176#else 
     177    return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask; 
     178#endif 
    123179} 
    124180 
    125181/*************************************************************************** 
     
    159215*/ 
    160216long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes ) 
    161217{ 
     218#ifdef MPSAFE 
     219    /* we need to ensure that previous writes are always seen before updating the index. */ 
     220    WriteMemoryBarrier(); 
     221    return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask; 
     222#else 
    162223    return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask; 
     224#endif 
    163225} 
    164226 
    165227/*************************************************************************** 
    166228** Return bytes written. */ 
    167 long RingBuffer_Write( RingBuffer *rbuf, void *data, long numBytes ) 
     229long RingBuffer_Write( RingBuffer *rbuf, const void *data, long numBytes ) 
    168230{ 
    169231    long size1, size2, numWritten; 
    170232    void *data1, *data2; 
  • audacity/lib-src/portaudio-v19/pablio/ringbuffer.h

    diff -wruN orig/audacity/lib-src/portaudio-v19/pablio/ringbuffer.h audacity/lib-src/portaudio-v19/pablio/ringbuffer.h
    old new  
    66#endif /* __cplusplus */ 
    77 
    88/* 
    9  * $Id: ringbuffer.h,v 1.4 2006/09/23 18:42:46 llucius Exp $ 
     9 * $Id: ringbuffer.h,v 1.3 2006/09/23 18:42:49 llucius Exp $ 
    1010 * ringbuffer.h 
    1111 * Ring Buffer utility.. 
    1212 * 
    1313 * Author: Phil Burk, http://www.softsynth.com 
     14 * modified for SMP safety on OS X by Bjorn Roche. 
     15 * also allowed for const where possible. 
     16 * Note that this is safe only for a single-thread reader 
     17 * and a single-thread writer. 
    1418 * 
    1519 * This program is distributed with the PortAudio Portable Audio Library. 
    1620 * For more information see: http://www.portaudio.com 
     
    4751 * license above. 
    4852 */ 
    4953 
     54/** 
     55 @file 
     56 @ingroup hostapi_src 
     57*/ 
     58 
    5059#include <stdio.h> 
    5160#include <stdlib.h> 
    5261#include <math.h> 
     
    7786/* Return number of bytes available for read. */ 
    7887long RingBuffer_GetReadAvailable( RingBuffer *rbuf ); 
    7988/* Return bytes written. */ 
    80 long RingBuffer_Write( RingBuffer *rbuf, void *data, long numBytes ); 
     89long RingBuffer_Write( RingBuffer *rbuf, const void *data, long numBytes ); 
    8190/* Return bytes read. */ 
    8291long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes ); 
    8392 
  • audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.c

    diff -wruN orig/audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.c audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.c
    old new  
    1 /* 
    2  * $Id: ringbuffer.c,v 1.3 2006/09/23 18:42:49 llucius Exp $ 
    3  * ringbuffer.c 
    4  * Ring Buffer utility.. 
    5  * 
    6  * Author: Phil Burk, http://www.softsynth.com 
    7  * modified for SMP safety on Mac OS X by Bjorn Roche 
    8  * also, alowed for const where possible 
    9  * Note that this is safe only for a single-thread reader and a 
    10  * single-thread writer. 
    11  * 
    12  * This program uses the PortAudio Portable Audio Library. 
    13  * For more information see: http://www.portaudio.com 
    14  * Copyright (c) 1999-2000 Ross Bencina and Phil Burk 
    15  * 
    16  * Permission is hereby granted, free of charge, to any person obtaining 
    17  * a copy of this software and associated documentation files 
    18  * (the "Software"), to deal in the Software without restriction, 
    19  * including without limitation the rights to use, copy, modify, merge, 
    20  * publish, distribute, sublicense, and/or sell copies of the Software, 
    21  * and to permit persons to whom the Software is furnished to do so, 
    22  * subject to the following conditions: 
    23  * 
    24  * The above copyright notice and this permission notice shall be 
    25  * included in all copies or substantial portions of the Software. 
    26  * 
    27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    28  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
    29  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
    30  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 
    31  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
    32  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
    33  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
    34  */ 
    35  
    36 /* 
    37  * The text above constitutes the entire PortAudio license; however,  
    38  * the PortAudio community also makes the following non-binding requests: 
    39  * 
    40  * Any person wishing to distribute modifications to the Software is 
    41  * requested to send the modifications to the original developer so that 
    42  * they can be incorporated into the canonical version. It is also  
    43  * requested that these non-binding requests be included along with the  
    44  * license above. 
    45  */ 
    46  
    47 /** 
    48  @file 
    49  @ingroup hostapi_src 
    50 */ 
    51  
    52 #include <stdio.h> 
    53 #include <stdlib.h> 
    54 #include <math.h> 
    55 #include "ringbuffer.h" 
    56 #include <string.h> 
    57  
    58 /* 
    59  * We can undefine this, to turn off memory barriers, but that 
    60  * is only useful if we know we don't need to be MP safe or 
    61  * we are interested in doing some kind of tests. 
    62  */ 
    63 #define MPSAFE 
    64  
    65 /**************** 
    66  * First, we'll define some memory barrier primitives based on the system. 
    67  * right now only OS X and FreeBSD are supported. In addition to providing 
    68  * memory barriers, these functions should ensure that data cached in registers 
    69  * is written out to cache where it can be snooped by other CPUs. (ie, the volatile 
    70  * keyword should not be required) 
    71  * 
    72  * the primitives that must be defined are: 
    73  * 
    74  * FullMemoryBarrier() 
    75  * ReadMemoryBarrier() 
    76  * WriteMemoryBarrier() 
    77  * 
    78  ****************/ 
    79  
    80 #if defined(__APPLE__) || defined(__FreeBSD__) 
    81 #   include <libkern/OSAtomic.h> 
    82     /* Here are the memory barrier functions. Mac OS X and FreeBSD only provide 
    83        full memory barriers, so the three types of barriers are the same. 
    84        The asm volatile may be redundant with the memory barrier, but 
    85        until I have proof of that, I'm leaving it. */ 
    86 #   define FullMemoryBarrier()  do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false) 
    87 #   define ReadMemoryBarrier()  do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false) 
    88 #   define WriteMemoryBarrier() do{ asm volatile("":::"memory"); OSMemoryBarrier(); }while(false) 
    89 #else 
    90 #   error Memory Barriers not defined on this system or system unknown 
    91 #endif 
    92  
    93 /*************************************************************************** 
    94  * Initialize FIFO. 
    95  * numBytes must be power of 2, returns -1 if not. 
    96  */ 
    97 long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr ) 
    98 { 
    99     if( ((numBytes-1) & numBytes) != 0) return -1; /* Not Power of two. */ 
    100     rbuf->bufferSize = numBytes; 
    101     rbuf->buffer = (char *)dataPtr; 
    102     RingBuffer_Flush( rbuf ); 
    103     rbuf->bigMask = (numBytes*2)-1; 
    104     rbuf->smallMask = (numBytes)-1; 
    105     return 0; 
    106 } 
    107 /*************************************************************************** 
    108 ** Return number of bytes available for reading. */ 
    109 long RingBuffer_GetReadAvailable( RingBuffer *rbuf ) 
    110 { 
    111 #ifdef MPSAFE 
    112     ReadMemoryBarrier(); 
    113 #endif 
    114     return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask ); 
    115 } 
    116 /*************************************************************************** 
    117 ** Return number of bytes available for writing. */ 
    118 long RingBuffer_GetWriteAvailable( RingBuffer *rbuf ) 
    119 { 
    120     /* Since we are calling RingBuffer_GetReadAvailable, we don't need an aditional MB */ 
    121     return ( rbuf->bufferSize - RingBuffer_GetReadAvailable(rbuf)); 
    122 } 
    123  
    124 /*************************************************************************** 
    125 ** Clear buffer. Should only be called when buffer is NOT being read. */ 
    126 void RingBuffer_Flush( RingBuffer *rbuf ) 
    127 { 
    128     rbuf->writeIndex = rbuf->readIndex = 0; 
    129 } 
    130  
    131 /*************************************************************************** 
    132 ** Get address of region(s) to which we can write data. 
    133 ** If the region is contiguous, size2 will be zero. 
    134 ** If non-contiguous, size2 will be the size of second region. 
    135 ** Returns room available to be written or numBytes, whichever is smaller. 
    136 */ 
    137 long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes, 
    138                                  void **dataPtr1, long *sizePtr1, 
    139                                  void **dataPtr2, long *sizePtr2 ) 
    140 { 
    141     long   index; 
    142     long   available = RingBuffer_GetWriteAvailable( rbuf ); 
    143     if( numBytes > available ) numBytes = available; 
    144     /* Check to see if write is not contiguous. */ 
    145     index = rbuf->writeIndex & rbuf->smallMask; 
    146     if( (index + numBytes) > rbuf->bufferSize ) 
    147     { 
    148         /* Write data in two blocks that wrap the buffer. */ 
    149         long   firstHalf = rbuf->bufferSize - index; 
    150         *dataPtr1 = &rbuf->buffer[index]; 
    151         *sizePtr1 = firstHalf; 
    152         *dataPtr2 = &rbuf->buffer[0]; 
    153         *sizePtr2 = numBytes - firstHalf; 
    154     } 
    155     else 
    156     { 
    157         *dataPtr1 = &rbuf->buffer[index]; 
    158         *sizePtr1 = numBytes; 
    159         *dataPtr2 = NULL; 
    160         *sizePtr2 = 0; 
    161     } 
    162     return numBytes; 
    163 } 
    164  
    165  
    166 /*************************************************************************** 
    167 */ 
    168 long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes ) 
    169 { 
    170 #ifdef MPSAFE 
    171     /* we need to ensure that previous writes are seen before we update the write index */ 
    172     WriteMemoryBarrier(); 
    173     return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask; 
    174 #else 
    175     return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask; 
    176 #endif 
    177 } 
    178  
    179 /*************************************************************************** 
    180 ** Get address of region(s) from which we can read data. 
    181 ** If the region is contiguous, size2 will be zero. 
    182 ** If non-contiguous, size2 will be the size of second region. 
    183 ** Returns room available to be written or numBytes, whichever is smaller. 
    184 */ 
    185 long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes, 
    186                                 void **dataPtr1, long *sizePtr1, 
    187                                 void **dataPtr2, long *sizePtr2 ) 
    188 { 
    189     long   index; 
    190     long   available = RingBuffer_GetReadAvailable( rbuf ); 
    191     if( numBytes > available ) numBytes = available; 
    192     /* Check to see if read is not contiguous. */ 
    193     index = rbuf->readIndex & rbuf->smallMask; 
    194     if( (index + numBytes) > rbuf->bufferSize ) 
    195     { 
    196         /* Write data in two blocks that wrap the buffer. */ 
    197         long firstHalf = rbuf->bufferSize - index; 
    198         *dataPtr1 = &rbuf->buffer[index]; 
    199         *sizePtr1 = firstHalf; 
    200         *dataPtr2 = &rbuf->buffer[0]; 
    201         *sizePtr2 = numBytes - firstHalf; 
    202     } 
    203     else 
    204     { 
    205         *dataPtr1 = &rbuf->buffer[index]; 
    206         *sizePtr1 = numBytes; 
    207         *dataPtr2 = NULL; 
    208         *sizePtr2 = 0; 
    209     } 
    210     return numBytes; 
    211 } 
    212 /*************************************************************************** 
    213 */ 
    214 long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes ) 
    215 { 
    216 #ifdef MPSAFE 
    217     /* we need to ensure that previous writes are always seen before updating the index. */ 
    218     WriteMemoryBarrier(); 
    219     return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask; 
    220 #else 
    221     return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask; 
    222 #endif 
    223 } 
    224  
    225 /*************************************************************************** 
    226 ** Return bytes written. */ 
    227 long RingBuffer_Write( RingBuffer *rbuf, const void *data, long numBytes ) 
    228 { 
    229     long size1, size2, numWritten; 
    230     void *data1, *data2; 
    231     numWritten = RingBuffer_GetWriteRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 ); 
    232     if( size2 > 0 ) 
    233     { 
    234  
    235         memcpy( data1, data, size1 ); 
    236         data = ((char *)data) + size1; 
    237         memcpy( data2, data, size2 ); 
    238     } 
    239     else 
    240     { 
    241         memcpy( data1, data, size1 ); 
    242     } 
    243     RingBuffer_AdvanceWriteIndex( rbuf, numWritten ); 
    244     return numWritten; 
    245 } 
    246  
    247 /*************************************************************************** 
    248 ** Return bytes read. */ 
    249 long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes ) 
    250 { 
    251     long size1, size2, numRead; 
    252     void *data1, *data2; 
    253     numRead = RingBuffer_GetReadRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 ); 
    254     if( size2 > 0 ) 
    255     { 
    256         memcpy( data, data1, size1 ); 
    257         data = ((char *)data) + size1; 
    258         memcpy( data, data2, size2 ); 
    259     } 
    260     else 
    261     { 
    262         memcpy( data, data1, size1 ); 
    263     } 
    264     RingBuffer_AdvanceReadIndex( rbuf, numRead ); 
    265     return numRead; 
    266 } 
  • audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.h

    diff -wruN orig/audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.h audacity/lib-src/portaudio-v19/src/hostapi/coreaudio/ringbuffer.h
    old new  
    1 #ifndef _RINGBUFFER_H 
    2 #define _RINGBUFFER_H 
    3 #ifdef __cplusplus 
    4 extern "C" 
    5 { 
    6 #endif /* __cplusplus */ 
    7  
    8 /* 
    9  * $Id: ringbuffer.h,v 1.3 2006/09/23 18:42:49 llucius Exp $ 
    10  * ringbuffer.h 
    11  * Ring Buffer utility.. 
    12  * 
    13  * Author: Phil Burk, http://www.softsynth.com 
    14  * modified for SMP safety on OS X by Bjorn Roche. 
    15  * also allowed for const where possible. 
    16  * Note that this is safe only for a single-thread reader 
    17  * and a single-thread writer. 
    18  * 
    19  * This program is distributed with the PortAudio Portable Audio Library. 
    20  * For more information see: http://www.portaudio.com 
    21  * Copyright (c) 1999-2000 Ross Bencina and Phil Burk 
    22  * 
    23  * Permission is hereby granted, free of charge, to any person obtaining 
    24  * a copy of this software and associated documentation files 
    25  * (the "Software"), to deal in the Software without restriction, 
    26  * including without limitation the rights to use, copy, modify, merge, 
    27  * publish, distribute, sublicense, and/or sell copies of the Software, 
    28  * and to permit persons to whom the Software is furnished to do so, 
    29  * subject to the following conditions: 
    30  * 
    31  * The above copyright notice and this permission notice shall be 
    32  * included in all copies or substantial portions of the Software. 
    33  * 
    34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
    36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
    37  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 
    38  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
    39  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
    40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
    41  */ 
    42  
    43 /* 
    44  * The text above constitutes the entire PortAudio license; however,  
    45  * the PortAudio community also makes the following non-binding requests: 
    46  * 
    47  * Any person wishing to distribute modifications to the Software is 
    48  * requested to send the modifications to the original developer so that 
    49  * they can be incorporated into the canonical version. It is also  
    50  * requested that these non-binding requests be included along with the  
    51  * license above. 
    52  */ 
    53  
    54 /** 
    55  @file 
    56  @ingroup hostapi_src 
    57 */ 
    58  
    59 #include <stdio.h> 
    60 #include <stdlib.h> 
    61 #include <math.h> 
    62 #include "ringbuffer.h" 
    63 #include <string.h> 
    64  
    65 typedef struct 
    66 { 
    67     long   bufferSize; /* Number of bytes in FIFO. Power of 2. Set by RingBuffer_Init. */ 
    68     long   writeIndex; /* Index of next writable byte. Set by RingBuffer_AdvanceWriteIndex. */ 
    69     long   readIndex;  /* Index of next readable byte. Set by RingBuffer_AdvanceReadIndex. */ 
    70     long   bigMask;    /* Used for wrapping indices with extra bit to distinguish full/empty. */ 
    71     long   smallMask;  /* Used for fitting indices to buffer. */ 
    72     char * buffer; 
    73 } 
    74 RingBuffer; 
    75 /* 
    76  * Initialize Ring Buffer. 
    77  * numBytes must be power of 2, returns -1 if not. 
    78  */ 
    79 long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr ); 
    80  
    81 /* Clear buffer. Should only be called when buffer is NOT being read. */ 
    82 void RingBuffer_Flush( RingBuffer *rbuf ); 
    83  
    84 /* Return number of bytes available for writing. */ 
    85 long RingBuffer_GetWriteAvailable( RingBuffer *rbuf ); 
    86 /* Return number of bytes available for read. */ 
    87 long RingBuffer_GetReadAvailable( RingBuffer *rbuf ); 
    88 /* Return bytes written. */ 
    89 long RingBuffer_Write( RingBuffer *rbuf, const void *data, long numBytes ); 
    90 /* Return bytes read. */ 
    91 long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes ); 
    92  
    93 /* Get address of region(s) to which we can write data. 
    94 ** If the region is contiguous, size2 will be zero. 
    95 ** If non-contiguous, size2 will be the size of second region. 
    96 ** Returns room available to be written or numBytes, whichever is smaller. 
    97 */ 
    98 long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes, 
    99                                  void **dataPtr1, long *sizePtr1, 
    100                                  void **dataPtr2, long *sizePtr2 ); 
    101 long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes ); 
    102  
    103 /* Get address of region(s) from which we can read data. 
    104 ** If the region is contiguous, size2 will be zero. 
    105 ** If non-contiguous, size2 will be the size of second region. 
    106 ** Returns room available to be written or numBytes, whichever is smaller. 
    107 */ 
    108 long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes, 
    109                                 void **dataPtr1, long *sizePtr1, 
    110                                 void **dataPtr2, long *sizePtr2 ); 
    111  
    112 long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes ); 
    113  
    114 #ifdef __cplusplus 
    115 } 
    116 #endif /* __cplusplus */ 
    117 #endif /* _RINGBUFFER_H */ 
  • audacity/lib-src/portaudio-v19/src/hostapi/jack/pa_jack.c

    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
    old new  
    6868#include "pa_process.h" 
    6969#include "pa_allocation.h" 
    7070#include "pa_cpuload.h" 
    71 #include "../pablio/ringbuffer.c" 
     71#include "ringbuffer.h" 
    7272 
    7373static int aErr_; 
    7474static PaError paErr_;     /* For use with ENSURE_PA */ 
     
    466466 
    467467    const char **jack_ports = NULL; 
    468468    char **client_names = NULL; 
    469     char *regex_pattern = MALLOC( jack_client_name_size() + 3 ); 
     469    char *regex_pattern = NULL; 
    470470    int port_index, client_index, i; 
    471471    double globalSampleRate; 
    472472    regex_t port_regex; 
    473473    unsigned long numClients = 0, numPorts = 0; 
    474     char *tmp_client_name = MALLOC( jack_client_name_size() ); 
     474    char *tmp_client_name = NULL; 
    475475 
    476476    commonApi->info.defaultInputDevice = paNoDevice; 
    477477    commonApi->info.defaultOutputDevice = paNoDevice; 
     
    484484     * associated with the previous list */ 
    485485    PaUtil_FreeAllAllocations( jackApi->deviceInfoMemory ); 
    486486 
     487    regex_pattern = MALLOC( jack_client_name_size() + 3 ); 
     488    tmp_client_name = MALLOC( jack_client_name_size() ); 
     489 
    487490    /* We can only retrieve the list of clients indirectly, by first 
    488491     * asking for a list of all ports, then parsing the port names 
    489492     * according to the client_name:port_name convention (which is