*/
/*
- * The text above constitutes the entire PortAudio license; however,
+ * 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
+ * they can be incorporated into the canonical version. It is also
+ * requested that these non-binding requests be included along with the
* license above.
*/
/** @file
@ingroup common_src
- @brief Implements PortAudio API functions defined in portaudio.h, checks
+ @brief Implements PortAudio API functions defined in portaudio.h, checks
some errors, delegates platform-specific behavior to host API implementations.
-
- Implements the functions defined in the PortAudio API (portaudio.h),
- validates some parameters and checks for state inconsistencies before
- forwarding API requests to specific Host API implementations (via the
- interface declared in pa_hostapi.h), and Streams (via the interface
+
+ Implements the functions defined in the PortAudio API (portaudio.h),
+ validates some parameters and checks for state inconsistencies before
+ forwarding API requests to specific Host API implementations (via the
+ interface declared in pa_hostapi.h), and Streams (via the interface
declared in pa_stream.h).
This file manages initialization and termination of Host API
/**
* This is a combination of paVersionMajor, paVersionMinor and paVersionSubMinor.
- * It will always increase so that version numbers can be compared as integers to
+ * It will always increase so that version numbers can be compared as integers to
* see which is later.
*/
#define paVersion paMakeVersionNumber(paVersionMajor, paVersionMinor, paVersionSubMinor)
if( !hostApis_ )
{
result = paInsufficientMemory;
- goto error;
+ goto error;
}
hostApisCount_ = 0;
assert( hostApi->info.defaultInputDevice < hostApi->info.deviceCount );
assert( hostApi->info.defaultOutputDevice < hostApi->info.deviceCount );
- /* the first successfully initialized host API with a default input *or*
+ /* the first successfully initialized host API with a default input *or*
output device is used as the default host API.
*/
if( (defaultHostApiIndex_ == -1) &&
- ( hostApi->info.defaultInputDevice != paNoDevice
+ ( hostApi->info.defaultInputDevice != paNoDevice
|| hostApi->info.defaultOutputDevice != paNoDevice ) )
{
defaultHostApiIndex_ = hostApisCount_;
<device> belongs and returns it. if <hostSpecificDeviceIndex> is
non-null, the host specific device index is returned in it.
returns -1 if <device> is out of range.
-
+
*/
static int FindHostApi( PaDeviceIndex device, int *hostSpecificDeviceIndex )
{
{
PA_VALIDATE_TYPE_SIZES;
PA_VALIDATE_ENDIANNESS;
-
+
PaUtil_InitializeClock();
PaUtil_ResetTraceMessages();
case paCanNotWriteToAnInputOnlyStream: result = "Can't write to an input only stream"; break;
case paIncompatibleStreamHostApi: result = "Incompatible stream host API"; break;
case paBadBufferPtr: result = "Bad buffer pointer"; break;
- default:
+ default:
if( errorCode > 0 )
- result = "Invalid error code (value greater than zero)";
+ result = "Invalid error code (value greater than zero)";
else
- result = "Invalid error code";
+ result = "Invalid error code";
break;
}
return result;
{
PaHostApiIndex result;
int i;
-
+
PA_LOGAPI_ENTER_PARAMS( "Pa_HostApiTypeIdToHostApiIndex" );
PA_LOGAPI(("\tPaHostApiTypeId type: %d\n", type ));
else
{
result = paHostApiNotFound;
-
+
for( i=0; i < hostApisCount_; ++i )
{
if( hostApis_[i]->info.type == type )
{
result = i;
break;
- }
+ }
}
}
{
PaError result;
int i;
-
+
if( !PA_IS_INITIALISED_ )
{
result = paNotInitialized;
else
{
result = paHostApiNotFound;
-
+
for( i=0; i < hostApisCount_; ++i )
{
if( hostApis_[i]->info.type == type )
{
PaError result;
PaDeviceIndex x;
-
+
x = device - hostApi->privatePaFrontInfo.baseDeviceIndex;
if( x < 0 || x >= hostApi->info.deviceCount )
else if( hostApi < 0 || hostApi >= hostApisCount_ )
{
info = NULL;
-
+
PA_LOGAPI(("Pa_GetHostApiInfo returned:\n" ));
PA_LOGAPI(("\tPaHostApiInfo*: NULL [ hostApi out of range ]\n" ));
{
PaHostApiIndex hostApi;
PaDeviceIndex result;
-
+
PA_LOGAPI_ENTER( "Pa_GetDefaultOutputDevice" );
hostApi = Pa_GetDefaultHostApi();
ValidateOpenStreamParameters() checks that parameters to Pa_OpenStream()
conform to the expected values as described below. This function is
also designed to be used with the proposed Pa_IsFormatSupported() function.
-
+
There are basically two types of validation that could be performed:
Generic conformance validation, and device capability mismatch
validation. This function performs only generic conformance validation.
combinations of parameters - for example, even if the sampleRate
seems ok, it might not be for a duplex stream - we have no way of
checking this in an API-neutral way, so we don't try.
-
+
On success the function returns PaNoError and fills in hostApi,
hostApiInputDeviceID, and hostApiOutputDeviceID fields. On failure
the function returns an error code indicating the first encountered
parameter error.
-
-
+
+
If ValidateOpenStreamParameters() returns paNoError, the following
assertions are guaranteed to be true.
-
+
- at least one of inputParameters & outputParmeters is valid (not NULL)
- if inputParameters & outputParameters are both valid, that
inputParameters->device & outputParameters->device both use the same host api
-
+
PaDeviceIndex inputParameters->device
- is within range (0 to Pa_GetDeviceCount-1) Or:
- is paUseHostApiSpecificDeviceSpecification and
int inputParameters->channelCount
- if inputParameters->device is not paUseHostApiSpecificDeviceSpecification, channelCount is > 0
- upper bound is NOT validated against device capabilities
-
+
PaSampleFormat inputParameters->sampleFormat
- is one of the sample formats defined in portaudio.h
void *inputParameters->hostApiSpecificStreamInfo
- if supplied its hostApi field matches the input device's host Api
-
+
PaDeviceIndex outputParmeters->device
- is within range (0 to Pa_GetDeviceCount-1)
-
+
int outputParmeters->channelCount
- if inputDevice is valid, channelCount is > 0
- upper bound is NOT validated against device capabilities
-
+
PaSampleFormat outputParmeters->sampleFormat
- is one of the sample formats defined in portaudio.h
-
+
void *outputParmeters->hostApiSpecificStreamInfo
- if supplied its hostApi field matches the output device's host Api
-
+
double sampleRate
- is not an 'absurd' rate (less than 1000. or greater than 384000.)
- sampleRate is NOT validated against device capabilities
-
+
PaStreamFlags streamFlags
- unused platform neutral flags are zero
- paNeverDropInput is only used for full-duplex callback streams with
!= (*hostApi)->info.type )
return paIncompatibleHostApiSpecificStreamInfo;
}
- }
+ }
if( (inputParameters != NULL) && (outputParameters != NULL) )
{
return paBadIODeviceCombination;
}
}
-
-
+
+
/* Check for absurd sample rates. */
if( (sampleRate < 1000.0) || (sampleRate > 384000.0) )
return paInvalidSampleRate;
if( framesPerBuffer != paFramesPerBufferUnspecified )
return paInvalidFlag;
}
-
+
return paNoError;
}
PA_LOGAPI(("\tPaTime outputParameters->suggestedLatency: %f\n", outputParameters->suggestedLatency ));
PA_LOGAPI(("\tvoid *outputParameters->hostApiSpecificStreamInfo: 0x%p\n", outputParameters->hostApiSpecificStreamInfo ));
}
-
+
PA_LOGAPI(("\tdouble sampleRate: %g\n", sampleRate ));
#endif
PA_LOGAPI_EXIT_PAERROR( "Pa_IsFormatSupported", result );
return result;
}
-
+
if( inputParameters )
{
PA_LOGAPI(("\tPaTime outputParameters->suggestedLatency: %f\n", outputParameters->suggestedLatency ));
PA_LOGAPI(("\tvoid *outputParameters->hostApiSpecificStreamInfo: 0x%p\n", outputParameters->hostApiSpecificStreamInfo ));
}
-
+
PA_LOGAPI(("\tdouble sampleRate: %g\n", sampleRate ));
PA_LOGAPI(("\tunsigned long framesPerBuffer: %d\n", framesPerBuffer ));
PA_LOGAPI(("\tPaStreamFlags streamFlags: 0x%x\n", streamFlags ));
PA_LOGAPI(("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) ));
return result;
}
-
+
if( inputParameters )
{
{
hostApiInputParameters.device = Pa_GetDefaultInputDevice();
if( hostApiInputParameters.device == paNoDevice )
- return paDeviceUnavailable;
-
+ return paDeviceUnavailable;
+
hostApiInputParameters.channelCount = inputChannelCount;
hostApiInputParameters.sampleFormat = sampleFormat;
/* defaultHighInputLatency is used below instead of
stream to work reliably than it is for it to work with the lowest
latency.
*/
- hostApiInputParameters.suggestedLatency =
+ hostApiInputParameters.suggestedLatency =
Pa_GetDeviceInfo( hostApiInputParameters.device )->defaultHighInputLatency;
hostApiInputParameters.hostApiSpecificStreamInfo = NULL;
hostApiInputParametersPtr = &hostApiInputParameters;
{
hostApiOutputParameters.device = Pa_GetDefaultOutputDevice();
if( hostApiOutputParameters.device == paNoDevice )
- return paDeviceUnavailable;
+ return paDeviceUnavailable;
hostApiOutputParameters.channelCount = outputChannelCount;
hostApiOutputParameters.sampleFormat = sampleFormat;
else if( result == 1 )
{
result = paStreamIsStopped;
- }
+ }
}
}