From ed932acb5860bf8b9296169676499562a55d139e Mon Sep 17 00:00:00 2001 From: Miller Puckette Date: Mon, 6 Sep 2004 20:20:36 +0000 Subject: checking in version 0.38test5. Oops, I realize I forgot some more nice files, will add them and re-commit. svn path=/trunk/; revision=2010 --- pd/portaudio_v18/docs/index.html | 20 ++++- pd/portaudio_v18/docs/pa_tut_mac_osx.html | 28 ++++--- pd/portaudio_v18/docs/portaudio_icmc2001.pdf | Bin 49434 -> 50968 bytes pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf | Bin 49765 -> 50527 bytes pd/portaudio_v18/pa_asio/Pa_ASIO.pdf | Bin 50109 -> 50778 bytes pd/portaudio_v18/pa_asio/pa_asio.cpp | 38 ++++++--- pd/portaudio_v18/pa_mac_core/notes.txt | 2 + pd/portaudio_v18/pa_mac_core/pa_mac_core.c | 95 ++++------------------ 8 files changed, 74 insertions(+), 109 deletions(-) (limited to 'pd/portaudio_v18') diff --git a/pd/portaudio_v18/docs/index.html b/pd/portaudio_v18/docs/index.html index bd94eaa7..f92cd110 100644 --- a/pd/portaudio_v18/docs/index.html +++ b/pd/portaudio_v18/docs/index.html @@ -61,8 +61,24 @@ Feedback welcome.

API Reference for V19

-
Reference documents for the Application Programmer Interface -for V19 generated by doxygen.
+
+

Reference documents for the Application Programmer Interface + for V19 generated by doxygen.

+
+

Paper presented at ACMC2003

+
+

"PortAudio and Media Synchronisation" - Discusses how the V19 API relates to + various synchronisation tasks including MIDI controlled playback, GUI/Audio + sync and MIDI sync. http://www.portaudio.com/docs/portaudio_sync_acmc2003.pdf (PDF)

+
+

Programmer's Guides

+ +

diff --git a/pd/portaudio_v18/docs/pa_tut_mac_osx.html b/pd/portaudio_v18/docs/pa_tut_mac_osx.html index 44b13883..bc33f44a 100644 --- a/pd/portaudio_v18/docs/pa_tut_mac_osx.html +++ b/pd/portaudio_v18/docs/pa_tut_mac_osx.html @@ -30,13 +30,15 @@ Compiling for Macintosh OS X

To compile a Macintosh OS X CoreAudio application with the PortAudio library you will use the following source files: -
pa_mac_core/pa_mac_core.c
-pa_common/pa_lib.c
-pa_common/portaudio.h
-pa_common/pa_host.h
-pa_common/pa_convert.c
-pablio/ringbuffer.c
-pablio/ringbuffer.h
+
pa_mac_core/pa_mac_core.c +
pa_common/pa_lib.c +
pa_common/portaudio.h +
pa_common/pa_host.h +
pa_common/pa_convert.c +
pa_common/pa_trace.c +
pa_common/pa_trace.h +
pablio/ringbuffer.c +
pablio/ringbuffer.h

@@ -53,7 +55,7 @@ the simplest.

Or Using Metrowerks CodeWarrior 8

-
by James Vanlommel
+
by James Van Lommel
Create a new CodeWarrior project using Mac OS C++ Stationery.
Then choose Mac OS X Mach-O > Standard Console > C++ Console Mach-O. @@ -61,19 +63,19 @@ Or Using Metrowerks CodeWarrior 8 files from above to your Project.

Add a test file of your choosing, like
   patests    /patest_sine8.c -
  -
Add the frameworks to the Frameworks tab using Project > Add Files... +

Add the frameworks to the Frameworks tab using Project > Add Files...
   CoreAudio
   AudioToolbox

(The System framework should already be a part of the project.)

Open the current target's settings, and in Language Settings > C/C++ Language, uncheck (disable) the "ANSI Strict" setting. (Do this for both -Debug and Release projects, if necessary.) +Debug and Release projects, if necessary.) You may also choose to disable +RTTI and exceptions; the most important settings are 'Force C++ compilation' +(enabled) and 'ANSI Strict' (disabled)."

Edit pa_mac_core.c:
   On line 1546, cast the PaHost_AllocateFastMemory() result to a (char *) or you will get a compile error. -
  -
Compile and run. (may need to run from a terminal window) +

Compile and run. (may need to run from a terminal window)

I've successfully built patest_sine8.c this way using the CVS .tar version of portaudio (date: 2003-04-27). I get 17 warnings during compilation, all of which deal with unused variables or arguments.

diff --git a/pd/portaudio_v18/docs/portaudio_icmc2001.pdf b/pd/portaudio_v18/docs/portaudio_icmc2001.pdf index 747016e1..dd074b7d 100644 Binary files a/pd/portaudio_v18/docs/portaudio_icmc2001.pdf and b/pd/portaudio_v18/docs/portaudio_icmc2001.pdf differ diff --git a/pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf b/pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf index b1014959..76bf6786 100644 Binary files a/pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf and b/pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf differ diff --git a/pd/portaudio_v18/pa_asio/Pa_ASIO.pdf b/pd/portaudio_v18/pa_asio/Pa_ASIO.pdf index 1b5d668f..ac5ecadb 100644 Binary files a/pd/portaudio_v18/pa_asio/Pa_ASIO.pdf and b/pd/portaudio_v18/pa_asio/Pa_ASIO.pdf differ diff --git a/pd/portaudio_v18/pa_asio/pa_asio.cpp b/pd/portaudio_v18/pa_asio/pa_asio.cpp index cec01134..717ee558 100644 --- a/pd/portaudio_v18/pa_asio/pa_asio.cpp +++ b/pd/portaudio_v18/pa_asio/pa_asio.cpp @@ -1,5 +1,5 @@ /* - * $Id: pa_asio.cpp,v 1.7.4.5 2003/06/30 16:27:10 stephane Exp $ + * $Id: pa_asio.cpp,v 1.7.4.8 2003/08/14 06:44:25 stephane Exp $ * Portable Audio I/O Library for ASIO Drivers * * Author: Stephane Letz @@ -66,8 +66,11 @@ we try again with the preferred size. Fix an old (never detected?) bug in the buffer adapdation code : S Letz 30-06-03 The audio callback was not protected against reentrancy : some drivers (like the Hoontech DSP24) seems to cause this behaviour that corrupted the buffer adapdation state and finally caused crashes. The reentrancy state is now checked in bufferSwitchTimeInfo : S Letz - - TO DO : + 17-07-03 Correct bug in Pa_ASIO_Convert_Inter_Output : parameter past_InputSampleFormat was used instead of past_OutputSampleFormat : J Maillard, S Letz + 25-07-03 Use of atomic operations for reenterCounter management on Windows, need to be implemented on MacOS9 : S Letz + 14-08-03 OutTime value in the audio callback was not updated correctly : S Letz + + TO DO : - Check Pa_StopSteam and Pa_AbortStream - Optimization for Input only or Ouput only (really necessary ??) @@ -158,7 +161,6 @@ typedef struct PaHostSoundControl bool stopped; ASIOCallbacks pahsc_asioCallbacks; - int32 pahsc_userInputBufferFrameOffset; // Position in Input user buffer int32 pahsc_userOutputBufferFrameOffset; // Position in Output user buffer @@ -301,7 +303,6 @@ unsigned long get_sys_reference_time(); #define max(a,b) ((a)>=(b)?(a):(b)) #endif - static bool Pa_ASIO_loadAsioDriver(char *name) { #ifdef WINDOWS @@ -311,7 +312,6 @@ static bool Pa_ASIO_loadAsioDriver(char *name) } - // Utilities for alignement buffer size computation static int PGCD (int a, int b) {return (b == 0) ? a : PGCD (b,a%b);} static int PPCM (int a, int b) {return (a*b) / PGCD (a,b);} @@ -574,8 +574,7 @@ static PaError Pa_ASIO_QueryDeviceInfo( internalPortAudioDevice * ipad ) sNumDevices++; } - - } + } } } @@ -668,6 +667,17 @@ long asioMessages(long selector, long value, void* message, double* opt) return ret; } +//---------------------------------------------------------------------------------- +// Atomic increment and decrement operations +#if MAC + /* need to be implemented on Mac */ + inline long Pa_AtomicIncrement(long* v) {return ++(*v);} + inline long Pa_AtomicDecrement(long* v) {return --(*v);} +#elif WINDOWS + inline long Pa_AtomicIncrement(long* v) {return InterlockedIncrement(v);} + inline long Pa_AtomicDecrement(long* v) {return InterlockedDecrement(v);} +#endif + //---------------------------------------------------------------------------------- // conversion from 64 bit ASIOSample/ASIOTimeStamp to double float @@ -725,9 +735,9 @@ static ASIOTime *bufferSwitchTimeInfo(ASIOTime *timeInfo, long index, ASIOBool p // Keep sample position asioDriverInfo.pahsc_NumFramesDone = timeInfo->timeInfo.samplePosition.lo; - + // Reentrancy control - if( ++asioDriverInfo.reenterCount) { + if(Pa_AtomicIncrement(&asioDriverInfo.reenterCount)) { asioDriverInfo.reenterError++; DBUG(("bufferSwitchTimeInfo : reentrancy detection = %d\n", asioDriverInfo.reenterError)); return 0L; @@ -751,7 +761,7 @@ static ASIOTime *bufferSwitchTimeInfo(ASIOTime *timeInfo, long index, ASIOBool p // Finally if the driver supports the ASIOOutputReady() optimization, do it here, all data are in place if (asioDriverInfo.pahsc_postOutput) ASIOOutputReady(); - }else { + }else{ /* CPU usage */ Pa_StartUsageCalculation(asioDriverInfo.past); @@ -767,7 +777,7 @@ static ASIOTime *bufferSwitchTimeInfo(ASIOTime *timeInfo, long index, ASIOBool p Pa_EndUsageCalculation(asioDriverInfo.past); } - } while(asioDriverInfo.reenterCount--); + } while(Pa_AtomicDecrement(&asioDriverInfo.reenterCount) >= 0); return 0L; } @@ -1789,6 +1799,8 @@ static void Pa_ASIO_Callback_Input(long index) /* Call PortAudio callback */ userResult = asioDriverInfo.past->past_Callback(past->past_InputBuffer, past->past_OutputBuffer, past->past_FramesPerUserBuffer,past->past_FrameCount,past->past_UserData ); + + past->past_FrameCount += (PaTimestamp) past->past_FramesPerUserBuffer; /* User callback has asked us to stop in the middle of the host buffer */ if( userResult != 0) { @@ -1861,7 +1873,7 @@ static void Pa_ASIO_Callback_Output(long index, long framePerBuffer) asioDriverInfo.pahsc_hostOutputBufferFrameOffset, asioDriverInfo.pahsc_userOutputBufferFrameOffset, asioDriverInfo.pahsc_channelInfos[0].type, - past->past_InputSampleFormat, + past->past_OutputSampleFormat, past->past_Flags, index); diff --git a/pd/portaudio_v18/pa_mac_core/notes.txt b/pd/portaudio_v18/pa_mac_core/notes.txt index 3b557d9a..0abdd3db 100644 --- a/pd/portaudio_v18/pa_mac_core/notes.txt +++ b/pd/portaudio_v18/pa_mac_core/notes.txt @@ -32,3 +32,5 @@ input, output or both. When we query devices, we first get a list of CoreAudio devices. Then we scan the list and add a PortAudio device for each CoreAudio device that supports input. Then we make a scan for output devices. + +(minor change to test CVS) diff --git a/pd/portaudio_v18/pa_mac_core/pa_mac_core.c b/pd/portaudio_v18/pa_mac_core/pa_mac_core.c index e0a31374..983d0e4f 100644 --- a/pd/portaudio_v18/pa_mac_core/pa_mac_core.c +++ b/pd/portaudio_v18/pa_mac_core/pa_mac_core.c @@ -1,5 +1,5 @@ /* - * $Id: pa_mac_core.c,v 1.8.4.12 2003/04/16 19:06:01 philburk Exp $ + * $Id: pa_mac_core.c,v 1.8.4.13 2003/12/09 19:04:54 philburk Exp $ * pa_mac_core.c * Implementation of PortAudio for Mac OS X Core Audio * @@ -108,13 +108,17 @@ Overlap creation and deletion of AudioConverters to prevent thread death when device rate changes. 04.16.2003 - Phil Burk - Fixed input channel scrambling when numChannels != 2^N. Caused by alignment error when filling RingBuffer with 2^N zero bytes. + 04.26.2003 - Phil Burk - Removed code to turn up volume and unmute to prevent blown eardrums. + 12.08.2003 - Phil Burk - Move declaration of oldConverter to top of PAOSX_DevicePropertyListener() + 12.08.2003 - Phil Burk - Removed need for #include "pa_trace.h", just for debug + 12.09.2003 - Phil Burk - Only change sampleRate or numChannels if we need to improve over + current setting. */ #include #include #include #include -#include #include #include #include @@ -122,7 +126,6 @@ #include "portaudio.h" #include "pa_host.h" -#include "pa_trace.h" #include "ringbuffer.h" /************************************************* Configuration ********/ @@ -795,7 +798,6 @@ static OSStatus PaOSX_LoadAndProcess( internalPortAudioStream *past, if( outputBuffer ) { /* Clear remainder of audio buffer if we are waiting for stop. */ - AddTraceMessage("PaOSX_LoadAndProcess: zero rest of wave buffer ", i ); memset( outputBuffer, 0, pahsc->output.bytesPerUserNativeBuffer ); } } @@ -1218,11 +1220,13 @@ static PaError PaOSX_SetFormat( AudioDeviceID devID, Boolean isInput, originalRate = formatDesc.mSampleRate; originalChannels = formatDesc.mChannelsPerFrame; - // Is it already set to the correct format? - if( (originalRate != desiredRate) || (originalChannels != desiredNumChannels) ) + // Changing the format can mess up other apps. + // So only change the format if the original format + // has a lower sample rate, or fewer channels, than the desired format. + if( (originalRate < desiredRate) || (originalChannels < desiredNumChannels) ) { - DBUG(("PaOSX_SetFormat: try to change sample rate to %f.\n", desiredRate )); - DBUG(("PaOSX_SetFormat: try to set number of channels to %d\n", desiredNumChannels)); + DBUG(("PaOSX_SetFormat: try to change sample rate from %f to %f.\n", originalRate, desiredRate )); + DBUG(("PaOSX_SetFormat: try to set number of channels %d to %d\n", originalChannels, desiredNumChannels)); formatDesc.mSampleRate = desiredRate; formatDesc.mChannelsPerFrame = desiredNumChannels; @@ -1256,76 +1260,6 @@ static PaError PaOSX_SetFormat( AudioDeviceID devID, Boolean isInput, return result; } -/******************************************************************* - * Check volume level of device. If below threshold, then set to newLevel. - * Using volume instead of decibels because decibel range varies by device. - */ -static void PaOSX_FixVolumeScalars( AudioDeviceID devID, Boolean isInput, - int numChannels, double threshold, double newLevel ) -{ - OSStatus err = noErr; - UInt32 dataSize; - int iChannel; - -/* The master channel is 0. Left and right are channels 1 and 2. */ -/* Fix volume. */ - for( iChannel = 0; iChannel<=numChannels; iChannel++ ) - { - Float32 fdata32; - dataSize = sizeof( fdata32 ); - err = AudioDeviceGetProperty( devID, iChannel, isInput, - kAudioDevicePropertyVolumeScalar, &dataSize, &fdata32 ); - if( err == noErr ) - { - DBUG(("kAudioDevicePropertyVolumeScalar for channel %d = %f\n", iChannel, fdata32)); - if( fdata32 <= (Float32) threshold ) - { - dataSize = sizeof( fdata32 ); - fdata32 = (Float32) newLevel; - err = AudioDeviceSetProperty( devID, 0, iChannel, isInput, - kAudioDevicePropertyVolumeScalar, dataSize, &fdata32 ); - if( err != noErr ) - { - PRINT(("Warning: audio volume is very low and could not be turned up.\n")); - } - else - { - PRINT(("Volume for audio channel %d was <= %4.2f so set to %4.2f by PortAudio!\n", - iChannel, threshold, newLevel )); - } - } - } - } -/* Unmute if muted. */ - for( iChannel = 0; iChannel<=numChannels; iChannel++ ) - { - UInt32 uidata32; - dataSize = sizeof( uidata32 ); - err = AudioDeviceGetProperty( devID, iChannel, isInput, - kAudioDevicePropertyMute, &dataSize, &uidata32 ); - if( err == noErr ) - { - DBUG(("mute for channel %d = %ld\n", iChannel, uidata32)); - if( uidata32 == 1 ) // muted? - { - dataSize = sizeof( uidata32 ); - uidata32 = 0; // unmute - err = AudioDeviceSetProperty( devID, 0, iChannel, isInput, - kAudioDevicePropertyMute, dataSize, &uidata32 ); - if( err != noErr ) - { - PRINT(("Warning: audio is muted and could not be unmuted!\n")); - } - else - { - PRINT(("Audio channel %d was unmuted by PortAudio!\n", iChannel )); - } - } - } - } - -} - #if 0 static void PaOSX_DumpDeviceInfo( AudioDeviceID devID, Boolean isInput ) { @@ -1413,6 +1347,7 @@ static OSStatus PAOSX_DevicePropertyListener (AudioDeviceID inDevice, AudioStreamBasicDescription userStreamFormat, hardwareStreamFormat; PaHostInOut *hostInOut; AudioStreamBasicDescription *destFormatPtr, *srcFormatPtr; + AudioConverterRef oldConverter = NULL; // PLB 20031208 - Declare here for standard 'C'. past = (internalPortAudioStream *) inClientData; pahsc = (PaHostSoundControl *) past->past_DeviceData; @@ -1465,7 +1400,7 @@ static OSStatus PAOSX_DevicePropertyListener (AudioDeviceID inDevice, // Don't delete old converter until we create new one so we don't pull // the rug out from under other audio threads. - AudioConverterRef oldConverter = hostInOut->converter; + oldConverter = hostInOut->converter; // Make converter to change sample rate. err = AudioConverterNew ( @@ -1595,8 +1530,6 @@ static PaError PaOSX_OpenCommonDevice( internalPortAudioStream *past, OSStatus err = noErr; Float64 deviceRate; - PaOSX_FixVolumeScalars( inOut->audioDeviceID, isInput, - inOut->numChannels, 0.1, 0.9 ); // The HW device format changes are asynchronous. // So we don't know when or if the PAOSX_DevicePropertyListener() will -- cgit v1.2.1