Move paqa_devs and paqa_errs to qa folder. Clean up tests.
This commit is contained in:
parent
4fd99433f3
commit
d2054b201e
4 changed files with 49 additions and 19 deletions
367
qa/paqa_devs.c
Normal file
367
qa/paqa_devs.c
Normal file
|
|
@ -0,0 +1,367 @@
|
|||
/** @file paqa_devs.c
|
||||
@ingroup qa_src
|
||||
@brief Self Testing Quality Assurance app for PortAudio
|
||||
Try to open each device and run through all the
|
||||
possible configurations. This test does not verify
|
||||
that the configuration works well. It just verifies
|
||||
that it does not crash. It requires a human to listen to
|
||||
the outputs.
|
||||
|
||||
@author Phil Burk http://www.softsynth.com
|
||||
|
||||
Pieter adapted to V19 API. Test now relies heavily on
|
||||
Pa_IsFormatSupported(). Uses same 'standard' sample rates
|
||||
as in test pa_devs.c.
|
||||
*/
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "portaudio.h"
|
||||
#include "pa_trace.h"
|
||||
|
||||
/****************************************** Definitions ***********/
|
||||
#define MODE_INPUT (0)
|
||||
#define MODE_OUTPUT (1)
|
||||
|
||||
typedef struct PaQaData
|
||||
{
|
||||
unsigned long framesLeft;
|
||||
int numChannels;
|
||||
int bytesPerSample;
|
||||
int mode;
|
||||
short sawPhase;
|
||||
PaSampleFormat format;
|
||||
}
|
||||
PaQaData;
|
||||
|
||||
/****************************************** Prototypes ***********/
|
||||
static void TestDevices( int mode );
|
||||
static void TestFormats( int mode, PaDeviceIndex deviceID, double sampleRate,
|
||||
int numChannels );
|
||||
static int TestAdvance( int mode, PaDeviceIndex deviceID, double sampleRate,
|
||||
int numChannels, PaSampleFormat format );
|
||||
static int QaCallback( const void *inputBuffer, void *outputBuffer,
|
||||
unsigned long framesPerBuffer,
|
||||
const PaStreamCallbackTimeInfo* timeInfo,
|
||||
PaStreamCallbackFlags statusFlags,
|
||||
void *userData );
|
||||
|
||||
/****************************************** Globals ***********/
|
||||
static int gNumPassed = 0;
|
||||
static int gNumFailed = 0;
|
||||
|
||||
/****************************************** Macros ***********/
|
||||
/* Print ERROR if it fails. Tally success or failure. */
|
||||
/* Odd do-while wrapper seems to be needed for some compilers. */
|
||||
#define EXPECT(_exp) \
|
||||
do \
|
||||
{ \
|
||||
if ((_exp)) {\
|
||||
/* printf("SUCCESS for %s\n", #_exp ); */ \
|
||||
gNumPassed++; \
|
||||
} \
|
||||
else { \
|
||||
printf("ERROR - 0x%x - %s for %s\n", result, \
|
||||
((result == 0) ? "-" : Pa_GetErrorText(result)), \
|
||||
#_exp ); \
|
||||
gNumFailed++; \
|
||||
goto error; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/*******************************************************************/
|
||||
/* This routine will be called by the PortAudio engine when audio is needed.
|
||||
** It may be called at interrupt level on some machines so don't do anything
|
||||
** that could mess up the system like calling malloc() or free().
|
||||
*/
|
||||
static int QaCallback( const void *inputBuffer, void *outputBuffer,
|
||||
unsigned long framesPerBuffer,
|
||||
const PaStreamCallbackTimeInfo* timeInfo,
|
||||
PaStreamCallbackFlags statusFlags,
|
||||
void *userData )
|
||||
{
|
||||
unsigned long i;
|
||||
short phase;
|
||||
PaQaData *data = (PaQaData *) userData;
|
||||
(void) inputBuffer;
|
||||
|
||||
/* Play simple sawtooth wave. */
|
||||
if( data->mode == MODE_OUTPUT )
|
||||
{
|
||||
phase = data->sawPhase;
|
||||
switch( data->format )
|
||||
{
|
||||
case paFloat32:
|
||||
{
|
||||
float *out = (float *) outputBuffer;
|
||||
for( i=0; i<framesPerBuffer; i++ )
|
||||
{
|
||||
phase += 0x123;
|
||||
*out++ = (float) (phase * (1.0 / 32768.0));
|
||||
if( data->numChannels == 2 )
|
||||
{
|
||||
*out++ = (float) (phase * (1.0 / 32768.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt32:
|
||||
{
|
||||
int *out = (int *) outputBuffer;
|
||||
for( i=0; i<framesPerBuffer; i++ )
|
||||
{
|
||||
phase += 0x123;
|
||||
*out++ = ((int) phase ) << 16;
|
||||
if( data->numChannels == 2 )
|
||||
{
|
||||
*out++ = ((int) phase ) << 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case paInt16:
|
||||
{
|
||||
short *out = (short *) outputBuffer;
|
||||
for( i=0; i<framesPerBuffer; i++ )
|
||||
{
|
||||
phase += 0x123;
|
||||
*out++ = phase;
|
||||
if( data->numChannels == 2 )
|
||||
{
|
||||
*out++ = phase;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
unsigned char *out = (unsigned char *) outputBuffer;
|
||||
unsigned long numBytes = framesPerBuffer * data->numChannels * data->bytesPerSample;
|
||||
for( i=0; i<numBytes; i++ )
|
||||
{
|
||||
*out++ = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
data->sawPhase = phase;
|
||||
}
|
||||
/* Are we through yet? */
|
||||
if( data->framesLeft > framesPerBuffer )
|
||||
{
|
||||
PaUtil_AddTraceMessage("QaCallback: running. framesLeft", data->framesLeft );
|
||||
data->framesLeft -= framesPerBuffer;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
PaUtil_AddTraceMessage("QaCallback: DONE! framesLeft", data->framesLeft );
|
||||
data->framesLeft = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************/
|
||||
int main(void);
|
||||
int main(void)
|
||||
{
|
||||
PaError result;
|
||||
EXPECT( ((result=Pa_Initialize()) == 0) );
|
||||
printf("Test OUTPUT ---------------\n");
|
||||
TestDevices( MODE_OUTPUT );
|
||||
printf("Test INPUT ---------------\n");
|
||||
TestDevices( MODE_INPUT );
|
||||
error:
|
||||
Pa_Terminate();
|
||||
printf("QA Report: %d passed, %d failed.\n", gNumPassed, gNumFailed );
|
||||
return (gNumFailed > 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
* Try each output device, through its full range of capabilities. */
|
||||
static void TestDevices( int mode )
|
||||
{
|
||||
int id, jc, i;
|
||||
int maxChannels;
|
||||
const PaDeviceInfo *pdi;
|
||||
static double standardSampleRates[] = { 8000.0, 9600.0, 11025.0, 12000.0,
|
||||
16000.0, 22050.0, 24000.0,
|
||||
32000.0, 44100.0, 48000.0,
|
||||
88200.0, 96000.0,
|
||||
-1.0 }; /* Negative terminated list. */
|
||||
int numDevices = Pa_GetDeviceCount();
|
||||
for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */
|
||||
{
|
||||
pdi = Pa_GetDeviceInfo( id );
|
||||
/* Try 1 to maxChannels on each device. */
|
||||
maxChannels = (( mode == MODE_INPUT ) ? pdi->maxInputChannels : pdi->maxOutputChannels);
|
||||
|
||||
for( jc=1; jc<=maxChannels; jc++ )
|
||||
{
|
||||
printf("\n========================================================================\n");
|
||||
printf(" Device = %s\n", pdi->name );
|
||||
printf("========================================================================\n");
|
||||
/* Try each standard sample rate. */
|
||||
for( i=0; standardSampleRates[i] > 0; i++ )
|
||||
{
|
||||
TestFormats( mode, (PaDeviceIndex)id, standardSampleRates[i], jc );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************/
|
||||
static void TestFormats( int mode, PaDeviceIndex deviceID, double sampleRate,
|
||||
int numChannels )
|
||||
{
|
||||
TestAdvance( mode, deviceID, sampleRate, numChannels, paFloat32 );
|
||||
TestAdvance( mode, deviceID, sampleRate, numChannels, paInt16 );
|
||||
TestAdvance( mode, deviceID, sampleRate, numChannels, paInt32 );
|
||||
/* TestAdvance( mode, deviceID, sampleRate, numChannels, paInt24 ); */
|
||||
}
|
||||
|
||||
/*******************************************************************/
|
||||
static int TestAdvance( int mode, PaDeviceIndex deviceID, double sampleRate,
|
||||
int numChannels, PaSampleFormat format )
|
||||
{
|
||||
PaStreamParameters inputParameters, outputParameters, *ipp, *opp;
|
||||
PaStream *stream = NULL;
|
||||
PaError result = paNoError;
|
||||
PaQaData myData;
|
||||
#define FRAMES_PER_BUFFER (64)
|
||||
const int kNumSeconds = 100;
|
||||
|
||||
/* Setup data for synthesis thread. */
|
||||
myData.framesLeft = (unsigned long) (sampleRate * kNumSeconds);
|
||||
myData.numChannels = numChannels;
|
||||
myData.mode = mode;
|
||||
myData.format = format;
|
||||
switch( format )
|
||||
{
|
||||
case paFloat32:
|
||||
case paInt32:
|
||||
case paInt24:
|
||||
myData.bytesPerSample = 4;
|
||||
break;
|
||||
/* case paPackedInt24:
|
||||
myData.bytesPerSample = 3;
|
||||
break; */
|
||||
default:
|
||||
myData.bytesPerSample = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
if( mode == MODE_INPUT )
|
||||
{
|
||||
inputParameters.device = deviceID;
|
||||
inputParameters.channelCount = numChannels;
|
||||
inputParameters.sampleFormat = format;
|
||||
inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency;
|
||||
inputParameters.hostApiSpecificStreamInfo = NULL;
|
||||
ipp = &inputParameters;
|
||||
}
|
||||
else
|
||||
{
|
||||
ipp = NULL;
|
||||
}
|
||||
|
||||
if( mode == MODE_OUTPUT )
|
||||
{
|
||||
outputParameters.device = deviceID;
|
||||
outputParameters.channelCount = numChannels;
|
||||
outputParameters.sampleFormat = format;
|
||||
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
|
||||
outputParameters.hostApiSpecificStreamInfo = NULL;
|
||||
opp = &outputParameters;
|
||||
}
|
||||
else
|
||||
{
|
||||
opp = NULL;
|
||||
}
|
||||
|
||||
if(paFormatIsSupported == Pa_IsFormatSupported( ipp, opp, sampleRate ))
|
||||
{
|
||||
printf("------ TestAdvance: %s, device = %d, rate = %g, numChannels = %d, format = %lu -------\n",
|
||||
( mode == MODE_INPUT ) ? "INPUT" : "OUTPUT",
|
||||
deviceID, sampleRate, numChannels, (unsigned long)format);
|
||||
EXPECT( ((result = Pa_OpenStream( &stream,
|
||||
ipp,
|
||||
opp,
|
||||
sampleRate,
|
||||
FRAMES_PER_BUFFER,
|
||||
paClipOff, /* we won't output out of range samples so don't bother clipping them */
|
||||
QaCallback,
|
||||
&myData ) ) == 0) );
|
||||
if( stream )
|
||||
{
|
||||
PaTime oldStamp, newStamp;
|
||||
unsigned long oldFrames;
|
||||
int minDelay = ( mode == MODE_INPUT ) ? 1000 : 400;
|
||||
/* Was:
|
||||
int minNumBuffers = Pa_GetMinNumBuffers( FRAMES_PER_BUFFER, sampleRate );
|
||||
int msec = (int) ((minNumBuffers * 3 * 1000.0 * FRAMES_PER_BUFFER) / sampleRate);
|
||||
*/
|
||||
int msec = (int)( 3.0 *
|
||||
(( mode == MODE_INPUT ) ? inputParameters.suggestedLatency : outputParameters.suggestedLatency ));
|
||||
if( msec < minDelay ) msec = minDelay;
|
||||
printf("msec = %d\n", msec); /**/
|
||||
EXPECT( ((result=Pa_StartStream( stream )) == 0) );
|
||||
/* Check to make sure PortAudio is advancing timeStamp. */
|
||||
oldStamp = Pa_GetStreamTime(stream);
|
||||
Pa_Sleep(msec);
|
||||
newStamp = Pa_GetStreamTime(stream);
|
||||
printf("oldStamp = %g, newStamp = %g\n", oldStamp, newStamp ); /**/
|
||||
EXPECT( (oldStamp < newStamp) );
|
||||
/* Check to make sure callback is decrementing framesLeft. */
|
||||
oldFrames = myData.framesLeft;
|
||||
Pa_Sleep(msec);
|
||||
printf("oldFrames = %lu, myData.framesLeft = %lu\n", oldFrames, myData.framesLeft ); /**/
|
||||
EXPECT( (oldFrames > myData.framesLeft) );
|
||||
EXPECT( ((result=Pa_CloseStream( stream )) == 0) );
|
||||
stream = NULL;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
error:
|
||||
if( stream != NULL ) Pa_CloseStream( stream );
|
||||
return -1;
|
||||
}
|
||||
403
qa/paqa_errs.c
Normal file
403
qa/paqa_errs.c
Normal file
|
|
@ -0,0 +1,403 @@
|
|||
/** @file paqa_errs.c
|
||||
@ingroup qa_src
|
||||
@brief Self Testing Quality Assurance app for PortAudio
|
||||
Do lots of bad things to test error reporting.
|
||||
@author Phil Burk http://www.softsynth.com
|
||||
Pieter Suurmond adapted to V19 API.
|
||||
*/
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "portaudio.h"
|
||||
|
||||
/*--------- Definitions ---------*/
|
||||
#define MODE_INPUT (0)
|
||||
#define MODE_OUTPUT (1)
|
||||
#define FRAMES_PER_BUFFER (64)
|
||||
#define SAMPLE_RATE (44100.0)
|
||||
|
||||
typedef struct PaQaData
|
||||
{
|
||||
unsigned long framesLeft;
|
||||
int numChannels;
|
||||
int bytesPerSample;
|
||||
int mode;
|
||||
}
|
||||
PaQaData;
|
||||
|
||||
static int gNumPassed = 0; /* Two globals */
|
||||
static int gNumFailed = 0;
|
||||
|
||||
/*------------------- Macros ------------------------------*/
|
||||
/* Print ERROR if it fails. Tally success or failure. Odd */
|
||||
/* do-while wrapper seems to be needed for some compilers. */
|
||||
|
||||
#define EXPECT(_exp) \
|
||||
do \
|
||||
{ \
|
||||
if ((_exp)) {\
|
||||
gNumPassed++; \
|
||||
} \
|
||||
else { \
|
||||
printf("\nERROR - 0x%x - %s for %s\n", result, Pa_GetErrorText(result), #_exp ); \
|
||||
gNumFailed++; \
|
||||
goto error; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define HOPEFOR(_exp) \
|
||||
do \
|
||||
{ \
|
||||
if ((_exp)) {\
|
||||
gNumPassed++; \
|
||||
} \
|
||||
else { \
|
||||
printf("\nERROR - 0x%x - %s for %s\n", result, Pa_GetErrorText(result), #_exp ); \
|
||||
gNumFailed++; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
/* This routine will be called by the PortAudio engine when audio is needed.
|
||||
It may be called at interrupt level on some machines so don't do anything
|
||||
that could mess up the system like calling malloc() or free().
|
||||
*/
|
||||
static int QaCallback( const void* inputBuffer,
|
||||
void* outputBuffer,
|
||||
unsigned long framesPerBuffer,
|
||||
const PaStreamCallbackTimeInfo* timeInfo,
|
||||
PaStreamCallbackFlags statusFlags,
|
||||
void* userData )
|
||||
{
|
||||
unsigned long i;
|
||||
unsigned char* out = (unsigned char *) outputBuffer;
|
||||
PaQaData* data = (PaQaData *) userData;
|
||||
|
||||
(void)inputBuffer; /* Prevent "unused variable" warnings. */
|
||||
|
||||
/* Zero out buffer so we don't hear terrible noise. */
|
||||
if( data->mode == MODE_OUTPUT )
|
||||
{
|
||||
unsigned long numBytes = framesPerBuffer * data->numChannels * data->bytesPerSample;
|
||||
for( i=0; i<numBytes; i++ )
|
||||
{
|
||||
*out++ = 0;
|
||||
}
|
||||
}
|
||||
/* Are we through yet? */
|
||||
if( data->framesLeft > framesPerBuffer )
|
||||
{
|
||||
data->framesLeft -= framesPerBuffer;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
data->framesLeft = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static PaDeviceIndex FindInputOnlyDevice(void)
|
||||
{
|
||||
PaDeviceIndex result = Pa_GetDefaultInputDevice();
|
||||
if( result != paNoDevice && Pa_GetDeviceInfo(result)->maxOutputChannels == 0 )
|
||||
return result;
|
||||
|
||||
for( result = 0; result < Pa_GetDeviceCount(); ++result )
|
||||
{
|
||||
if( Pa_GetDeviceInfo(result)->maxOutputChannels == 0 )
|
||||
return result;
|
||||
}
|
||||
|
||||
return paNoDevice;
|
||||
}
|
||||
|
||||
static PaDeviceIndex FindOutputOnlyDevice(void)
|
||||
{
|
||||
PaDeviceIndex result = Pa_GetDefaultOutputDevice();
|
||||
if( result != paNoDevice && Pa_GetDeviceInfo(result)->maxInputChannels == 0 )
|
||||
return result;
|
||||
|
||||
for( result = 0; result < Pa_GetDeviceCount(); ++result )
|
||||
{
|
||||
if( Pa_GetDeviceInfo(result)->maxInputChannels == 0 )
|
||||
return result;
|
||||
}
|
||||
|
||||
return paNoDevice;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*/
|
||||
static int TestBadOpens( void )
|
||||
{
|
||||
PaStream* stream = NULL;
|
||||
PaError result;
|
||||
PaQaData myData;
|
||||
PaStreamParameters ipp, opp;
|
||||
const PaDeviceInfo* info = NULL;
|
||||
|
||||
|
||||
/* Setup data for synthesis thread. */
|
||||
myData.framesLeft = (unsigned long) (SAMPLE_RATE * 100); /* 100 seconds */
|
||||
myData.numChannels = 1;
|
||||
myData.mode = MODE_OUTPUT;
|
||||
|
||||
/*----------------------------- No devices specified: */
|
||||
ipp.device = opp.device = paNoDevice;
|
||||
ipp.channelCount = opp.channelCount = 0; /* Also no channels. */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
/* Take the low latency of the default device for all subsequent tests. */
|
||||
info = Pa_GetDeviceInfo(Pa_GetDefaultInputDevice());
|
||||
ipp.suggestedLatency = info ? info->defaultLowInputLatency : 0.100;
|
||||
info = Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice());
|
||||
opp.suggestedLatency = info ? info->defaultLowOutputLatency : 0.100;
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, &ipp, &opp,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paInvalidDevice));
|
||||
|
||||
/*----------------------------- No devices specified #2: */
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, NULL, NULL,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paInvalidDevice));
|
||||
|
||||
/*----------------------------- Out of range input device specified: */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = Pa_GetDeviceCount(); /* And no output device, and no channels. */
|
||||
opp.channelCount = 0; opp.device = paNoDevice;
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, &ipp, NULL,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paInvalidDevice));
|
||||
|
||||
/*----------------------------- Out of range output device specified: */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = paNoDevice; /* And no input device, and no channels. */
|
||||
opp.channelCount = 0; opp.device = Pa_GetDeviceCount();
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, NULL, &opp,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paInvalidDevice));
|
||||
|
||||
if (Pa_GetDefaultInputDevice() != paNoDevice) {
|
||||
/*----------------------------- Zero input channels: */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = Pa_GetDefaultInputDevice();
|
||||
opp.channelCount = 0; opp.device = paNoDevice; /* And no output device, and no output channels. */
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, &ipp, NULL,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paInvalidChannelCount));
|
||||
}
|
||||
|
||||
if (Pa_GetDefaultOutputDevice() != paNoDevice) {
|
||||
/*----------------------------- Zero output channels: */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = paNoDevice; /* And no input device, and no input channels. */
|
||||
opp.channelCount = 0; opp.device = Pa_GetDefaultOutputDevice();
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, NULL, &opp,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paInvalidChannelCount));
|
||||
}
|
||||
/*----------------------------- Nonzero input and output channels but no output device: */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 2; ipp.device = Pa_GetDefaultInputDevice(); /* Both stereo. */
|
||||
opp.channelCount = 2; opp.device = paNoDevice;
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, &ipp, &opp,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paInvalidDevice));
|
||||
|
||||
/*----------------------------- Nonzero input and output channels but no input device: */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 2; ipp.device = paNoDevice;
|
||||
opp.channelCount = 2; opp.device = Pa_GetDefaultOutputDevice();
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, &ipp, &opp,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paInvalidDevice));
|
||||
|
||||
if (Pa_GetDefaultOutputDevice() != paNoDevice) {
|
||||
/*----------------------------- NULL stream pointer: */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = paNoDevice; /* Output is more likely than input. */
|
||||
opp.channelCount = 2; opp.device = Pa_GetDefaultOutputDevice(); /* Only 2 output channels. */
|
||||
HOPEFOR(((result = Pa_OpenStream(NULL, &ipp, &opp,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paBadStreamPtr));
|
||||
|
||||
/*----------------------------- Low sample rate: */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = paNoDevice;
|
||||
opp.channelCount = 2; opp.device = Pa_GetDefaultOutputDevice();
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, NULL, &opp,
|
||||
1.0, FRAMES_PER_BUFFER, /* 1 cycle per second (1 Hz) is too low. */
|
||||
paClipOff, QaCallback, &myData )) == paInvalidSampleRate));
|
||||
|
||||
/*----------------------------- High sample rate: */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = paNoDevice;
|
||||
opp.channelCount = 2; opp.device = Pa_GetDefaultOutputDevice();
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, NULL, &opp,
|
||||
10000000.0, FRAMES_PER_BUFFER, /* 10^6 cycles per second (10 MHz) is too high. */
|
||||
paClipOff, QaCallback, &myData )) == paInvalidSampleRate));
|
||||
|
||||
/*----------------------------- NULL callback: */
|
||||
/* NULL callback is valid in V19 -- it means use blocking read/write stream
|
||||
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = paNoDevice;
|
||||
opp.channelCount = 2; opp.device = Pa_GetDefaultOutputDevice();
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, NULL, &opp,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff,
|
||||
NULL,
|
||||
&myData )) == paNullCallback));
|
||||
*/
|
||||
|
||||
/*----------------------------- Bad flag: */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = paNoDevice;
|
||||
opp.channelCount = 2; opp.device = Pa_GetDefaultOutputDevice();
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, NULL, &opp,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
255, /* Is 8 maybe legal V19 API? */
|
||||
QaCallback, &myData )) == paInvalidFlag));
|
||||
}
|
||||
|
||||
/*----------------------------- using input device as output device: */
|
||||
if( FindInputOnlyDevice() != paNoDevice )
|
||||
{
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = paNoDevice; /* And no input device, and no channels. */
|
||||
opp.channelCount = 2; opp.device = FindInputOnlyDevice();
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, NULL, &opp,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paInvalidChannelCount));
|
||||
}
|
||||
|
||||
/*----------------------------- using output device as input device: */
|
||||
if( FindOutputOnlyDevice() != paNoDevice )
|
||||
{
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 2; ipp.device = FindOutputOnlyDevice();
|
||||
opp.channelCount = 0; opp.device = paNoDevice; /* And no output device, and no channels. */
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, &ipp, NULL,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paInvalidChannelCount));
|
||||
|
||||
}
|
||||
|
||||
if( stream != NULL ) Pa_CloseStream( stream );
|
||||
return result;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------------*/
|
||||
static int TestBadActions( void )
|
||||
{
|
||||
PaStream* stream = NULL;
|
||||
const PaDeviceInfo* deviceInfo = NULL;
|
||||
PaError result;
|
||||
PaQaData myData;
|
||||
PaStreamParameters opp;
|
||||
const PaDeviceInfo* info = NULL;
|
||||
|
||||
/* Setup data for synthesis thread. */
|
||||
myData.framesLeft = (unsigned long)(SAMPLE_RATE * 100); /* 100 seconds */
|
||||
myData.numChannels = 1;
|
||||
myData.mode = MODE_OUTPUT;
|
||||
|
||||
opp.device = Pa_GetDefaultOutputDevice(); /* Default output. */
|
||||
opp.channelCount = 2; /* Stereo output. */
|
||||
opp.hostApiSpecificStreamInfo = NULL;
|
||||
opp.sampleFormat = paFloat32;
|
||||
info = Pa_GetDeviceInfo(opp.device);
|
||||
opp.suggestedLatency = info ? info->defaultLowOutputLatency : 0.100;
|
||||
|
||||
if (opp.device != paNoDevice) {
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, NULL, /* Take NULL as input parame- */
|
||||
&opp, /* ters, meaning try only output. */
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paNoError));
|
||||
}
|
||||
|
||||
HOPEFOR(((deviceInfo = Pa_GetDeviceInfo(paNoDevice)) == NULL));
|
||||
HOPEFOR(((deviceInfo = Pa_GetDeviceInfo(87654)) == NULL));
|
||||
HOPEFOR(((result = Pa_StartStream(NULL)) == paBadStreamPtr));
|
||||
HOPEFOR(((result = Pa_StopStream(NULL)) == paBadStreamPtr));
|
||||
HOPEFOR(((result = Pa_IsStreamStopped(NULL)) == paBadStreamPtr));
|
||||
HOPEFOR(((result = Pa_IsStreamActive(NULL)) == paBadStreamPtr));
|
||||
HOPEFOR(((result = Pa_CloseStream(NULL)) == paBadStreamPtr));
|
||||
HOPEFOR(((result = Pa_SetStreamFinishedCallback(NULL, NULL)) == paBadStreamPtr));
|
||||
HOPEFOR(((result = !Pa_GetStreamInfo(NULL))));
|
||||
HOPEFOR(((result = Pa_GetStreamTime(NULL)) == 0.0));
|
||||
HOPEFOR(((result = Pa_GetStreamCpuLoad(NULL)) == 0.0));
|
||||
HOPEFOR(((result = Pa_ReadStream(NULL, NULL, 0)) == paBadStreamPtr));
|
||||
HOPEFOR(((result = Pa_WriteStream(NULL, NULL, 0)) == paBadStreamPtr));
|
||||
|
||||
/** @todo test Pa_GetStreamReadAvailable and Pa_GetStreamWriteAvailable */
|
||||
|
||||
if (stream != NULL) Pa_CloseStream(stream);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
int main(void);
|
||||
int main(void)
|
||||
{
|
||||
PaError result;
|
||||
|
||||
EXPECT(((result = Pa_Initialize()) == paNoError));
|
||||
TestBadOpens();
|
||||
TestBadActions();
|
||||
error:
|
||||
Pa_Terminate();
|
||||
printf("QA Report: %d passed, %d failed.\n", gNumPassed, gNumFailed);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/** @file patest_sine.c
|
||||
@ingroup test_src
|
||||
@brief Play a sine wave for several seconds.
|
||||
/** @file paqa_latency.c
|
||||
@ingroup qa_src
|
||||
@brief Test latency estimates.
|
||||
@author Ross Bencina <rossb@audiomulch.com>
|
||||
@author Phil Burk <philburk@softsynth.com>
|
||||
*/
|
||||
|
|
@ -138,7 +138,6 @@ PaError paqaCheckLatency( PaStreamParameters *outputParamsPtr,
|
|||
dataPtr->maxDeltaDacTime = 0.0;
|
||||
dataPtr->callbackCount = 0;
|
||||
|
||||
printf("-------------------------------------\n");
|
||||
printf("Stream parameter: suggestedOutputLatency = %g\n", outputParamsPtr->suggestedLatency );
|
||||
if( framesPerBuffer == paFramesPerBufferUnspecified ){
|
||||
printf("Stream parameter: user framesPerBuffer = paFramesPerBufferUnspecified\n" );
|
||||
|
|
@ -178,10 +177,12 @@ PaError paqaCheckLatency( PaStreamParameters *outputParamsPtr,
|
|||
Pa_Sleep( 1 * 1000 );
|
||||
|
||||
|
||||
printf("-------------------------------------\n");
|
||||
return err;
|
||||
error2:
|
||||
Pa_CloseStream( stream );
|
||||
error1:
|
||||
printf("-------------------------------------\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -225,36 +226,44 @@ int main(void)
|
|||
printf("Device info: defaultHighOutputLatency = %f seconds\n", deviceInfo->defaultHighOutputLatency);
|
||||
outputParameters.hostApiSpecificStreamInfo = NULL;
|
||||
|
||||
|
||||
// Try to use a small buffer that is smaller than we think the device can handle.
|
||||
// Try to force combining multiple user buffers into a host buffer.
|
||||
printf("------------- Try a very small buffer.\n");
|
||||
framesPerBuffer = 9;
|
||||
outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, framesPerBuffer );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
printf("------------- 64 frame buffer with 1.1 * defaultLow latency.\n");
|
||||
framesPerBuffer = 64;
|
||||
outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency * 1.1;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, framesPerBuffer );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
// Try to create a huge buffer that is bigger than the allowed device maximum.
|
||||
printf("------------- Try a huge buffer.\n");
|
||||
framesPerBuffer = 16*1024;
|
||||
outputParameters.suggestedLatency = ((double)framesPerBuffer) / sampleRate; // approximate
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, framesPerBuffer );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
printf("------------- Try suggestedLatency = 0.0\n");
|
||||
outputParameters.suggestedLatency = 0.0;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
printf("------------- Try suggestedLatency = defaultLowOutputLatency\n");
|
||||
outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
printf("------------- Try suggestedLatency = defaultHighOutputLatency\n");
|
||||
outputParameters.suggestedLatency = deviceInfo->defaultHighOutputLatency;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
|
||||
printf("------------- Try suggestedLatency = defaultHighOutputLatency * 4\n");
|
||||
outputParameters.suggestedLatency = deviceInfo->defaultHighOutputLatency * 4;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
|
||||
if( err != paNoError ) goto error;
|
||||
|
|
|
|||
Loading…
Reference in a new issue