From 21c068f1916330e90f814bed461fe0821d1665ec Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sun, 9 Oct 2011 16:36:37 +0000 Subject: checked in pd-0.43-0.src.tar.gz svn path=/trunk/; revision=15557 --- pd/portaudio/src/os/unix/pa_unix_hostapis.c | 29 ++++++++++++++++++- pd/portaudio/src/os/unix/pa_unix_util.c | 45 +++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 10 deletions(-) (limited to 'pd/portaudio/src/os/unix') diff --git a/pd/portaudio/src/os/unix/pa_unix_hostapis.c b/pd/portaudio/src/os/unix/pa_unix_hostapis.c index d695e1b1..339e1b14 100644 --- a/pd/portaudio/src/os/unix/pa_unix_hostapis.c +++ b/pd/portaudio/src/os/unix/pa_unix_hostapis.c @@ -1,5 +1,5 @@ /* - * $Id: pa_unix_hostapis.c 1097 2006-08-26 08:27:53Z rossb $ + * $Id: pa_unix_hostapis.c 1413 2009-05-24 17:00:36Z aknudsen $ * Portable Audio I/O Library UNIX initialization table * * Based on the Open Source API proposed by Ross Bencina @@ -49,10 +49,26 @@ PaError PaOSS_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex PaError PaSGI_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); /* Linux AudioScience HPI */ PaError PaAsiHpi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); +PaError PaMacCore_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); +PaError PaSkeleton_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); +/** Note that on Linux, ALSA is placed before OSS so that the former is preferred over the latter. + */ PaUtilHostApiInitializer *paHostApiInitializers[] = { +#ifdef __linux__ + +#ifdef PA_USE_ALSA + PaAlsa_Initialize, +#endif + +#ifdef PA_USE_OSS + PaOSS_Initialize, +#endif + +#else /* __linux__ */ + #ifdef PA_USE_OSS PaOSS_Initialize, #endif @@ -61,6 +77,8 @@ PaUtilHostApiInitializer *paHostApiInitializers[] = PaAlsa_Initialize, #endif +#endif /* __linux__ */ + #ifdef PA_USE_JACK PaJack_Initialize, #endif @@ -72,6 +90,15 @@ PaUtilHostApiInitializer *paHostApiInitializers[] = #ifdef PA_USE_ASIHPI PaAsiHpi_Initialize, #endif + +#ifdef PA_USE_COREAUDIO + PaMacCore_Initialize, +#endif + +#ifdef PA_USE_SKELETON + PaSkeleton_Initialize, +#endif + 0 /* NULL terminated array */ }; diff --git a/pd/portaudio/src/os/unix/pa_unix_util.c b/pd/portaudio/src/os/unix/pa_unix_util.c index 1cb83875..de54e51d 100644 --- a/pd/portaudio/src/os/unix/pa_unix_util.c +++ b/pd/portaudio/src/os/unix/pa_unix_util.c @@ -1,5 +1,5 @@ /* - * $Id: pa_unix_util.c 1232 2007-06-16 14:49:43Z rossb $ + * $Id: pa_unix_util.c 1419 2009-10-22 17:28:35Z bjornroche $ * Portable Audio I/O Library * UNIX platform-specific support functions * @@ -51,6 +51,13 @@ #include #include +#if defined(__APPLE__) && !defined(HAVE_MACH_ABSOLUTE_TIME) +#define HAVE_MACH_ABSOLUTE_TIME +#endif +#ifdef HAVE_MACH_ABSOLUTE_TIME +#include +#endif + #include "pa_util.h" #include "pa_unix_util.h" #include "pa_debugprint.h" @@ -118,27 +125,47 @@ void Pa_Sleep( long msec ) #endif } -/* *** NOT USED YET: *** -static int usePerformanceCounter_; -static double microsecondsPerTick_; +#ifdef HAVE_MACH_ABSOLUTE_TIME +/* + Discussion on the CoreAudio mailing list suggests that calling + gettimeofday (or anything else in the BSD layer) is not real-time + safe, so we use mach_absolute_time on OSX. This implementation is + based on these two links: + + Technical Q&A QA1398 - Mach Absolute Time Units + http://developer.apple.com/mac/library/qa/qa2004/qa1398.html + + Tutorial: Performance and Time. + http://www.macresearch.org/tutorial_performance_and_time */ +/* Scaler to convert the result of mach_absolute_time to seconds */ +static double machSecondsConversionScaler_ = 0.0; +#endif + void PaUtil_InitializeClock( void ) { - /* TODO */ +#ifdef HAVE_MACH_ABSOLUTE_TIME + mach_timebase_info_data_t info; + kern_return_t err = mach_timebase_info( &info ); + if( err == 0 ) + machSecondsConversionScaler_ = 1e-9 * (double) info.numer / (double) info.denom; +#endif } PaTime PaUtil_GetTime( void ) { -#ifdef HAVE_CLOCK_GETTIME +#ifdef HAVE_MACH_ABSOLUTE_TIME + return mach_absolute_time() * machSecondsConversionScaler_; +#elif defined(HAVE_CLOCK_GETTIME) struct timespec tp; clock_gettime(CLOCK_REALTIME, &tp); - return (PaTime)(tp.tv_sec + tp.tv_nsec / 1.e9); + return (PaTime)(tp.tv_sec + tp.tv_nsec * 1e-9); #else struct timeval tv; gettimeofday( &tv, NULL ); - return (PaTime) tv.tv_usec / 1000000. + tv.tv_sec; + return (PaTime) tv.tv_usec * 1e-6 + tv.tv_sec; #endif } @@ -190,7 +217,7 @@ PaError PaUtil_CancelThreading( PaUtilThreading *threading, int wait, PaError *e /* paUnixMainThread * We have to be a bit careful with defining this global variable, * as explained below. */ -#ifdef __apple__ +#ifdef __APPLE__ /* apple/gcc has a "problem" with global vars and dynamic libs. Initializing it seems to fix the problem. Described a bit in this thread: -- cgit v1.2.1