Check for getenv("PA_MIN_LATEWNCY_MSEC") to set latency externally.
Better error checking for invalid channel counts and invalid devices.
3.29.2002 - Phil Burk - Fixed Pa_GetCPULoad() for small buffers.
+ 3.31.2002 - Phil Burk - Use getrusage() instead of gettimeofday() for CPU Load calculation.
TODO:
O- how do mono output?
#include <CoreServices/CoreServices.h>
#include <CoreAudio/CoreAudio.h>
#include <sys/time.h>
+#include <sys/resource.h>
#include <unistd.h>
#include "portaudio.h"
int pahsc_FramesPerHostBuffer;
int pahsc_UserBuffersPerHostBuffer;
/* For measuring CPU utilization. */
- struct timeval pahsc_EntryTime;
+ struct rusage pahsc_EntryRusage;
double pahsc_InverseMicrosPerHostBuffer; /* 1/Microseconds of real-time audio per user buffer. */
}
PaHostSoundControl;
{
PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData;
if( pahsc == NULL ) return;
- /* Query system timer for usage analysis and to prevent overuse of CPU. */
- gettimeofday( &pahsc->pahsc_EntryTime, NULL );
+ /* Query user CPU timer for usage analysis and to prevent overuse of CPU. */
+ getrusage( RUSAGE_SELF, &pahsc->pahsc_EntryRusage );
}
static long SubtractTime_AminusB( struct timeval *timeA, struct timeval *timeB )
*/
static void Pa_EndUsageCalculation( internalPortAudioStream *past )
{
- struct timeval currentTime;
+ struct rusage currentRusage;
long usecsElapsed;
double newUsage;
PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData;
if( pahsc == NULL ) return;
-
- if( gettimeofday( ¤tTime, NULL ) == 0 )
+
+ if( getrusage( RUSAGE_SELF, ¤tRusage ) == 0 )
{
- usecsElapsed = SubtractTime_AminusB( ¤tTime, &pahsc->pahsc_EntryTime );
+ usecsElapsed = SubtractTime_AminusB( ¤tRusage.ru_utime, &pahsc->pahsc_EntryRusage.ru_utime );
+
/* Use inverse because it is faster than the divide. */
newUsage = usecsElapsed * pahsc->pahsc_InverseMicrosPerHostBuffer;