2
* $Id: pa_front.c 1396 2008-11-03 19:31:30Z philburk $
3
* Portable Audio I/O Library Multi-Host API front end
4
* Validate function parameters and manage multiple host APIs.
6
* Based on the Open Source API proposed by Ross Bencina
7
* Copyright (c) 1999-2008 Ross Bencina, Phil Burk
9
* Permission is hereby granted, free of charge, to any person obtaining
10
* a copy of this software and associated documentation files
11
* (the "Software"), to deal in the Software without restriction,
12
* including without limitation the rights to use, copy, modify, merge,
13
* publish, distribute, sublicense, and/or sell copies of the Software,
14
* and to permit persons to whom the Software is furnished to do so,
15
* subject to the following conditions:
17
* The above copyright notice and this permission notice shall be
18
* included in all copies or substantial portions of the Software.
20
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
24
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
* The text above constitutes the entire PortAudio license; however,
31
* the PortAudio community also makes the following non-binding requests:
33
* Any person wishing to distribute modifications to the Software is
34
* requested to send the modifications to the original developer so that
35
* they can be incorporated into the canonical version. It is also
36
* requested that these non-binding requests be included along with the
43
@brief Implements PortAudio API functions defined in portaudio.h, checks
44
some errors, delegates platform-specific behavior to host API implementations.
46
Implements the functions defined in the PortAudio API (portaudio.h),
47
validates some parameters and checks for state inconsistencies before
48
forwarding API requests to specific Host API implementations (via the
49
interface declared in pa_hostapi.h), and Streams (via the interface
50
declared in pa_stream.h).
52
This file manages initialization and termination of Host API
53
implementations via initializer functions stored in the paHostApiInitializers
54
global array (usually defined in an os-specific pa_[os]_hostapis.c file).
56
This file maintains a list of all open streams and closes them at Pa_Terminate().
58
Some utility functions declared in pa_util.h are implemented in this file.
60
All PortAudio API functions can be conditionally compiled with logging code.
61
To compile with logging, define the PA_LOG_API_CALLS precompiler symbol.
63
@todo Consider adding host API specific error text in Pa_GetErrorText() for
64
paUnanticipatedHostError
66
@todo Consider adding a new error code for when (inputParameters == NULL)
67
&& (outputParameters == NULL)
69
@todo review whether Pa_CloseStream() should call the interface's
70
CloseStream function if aborting the stream returns an error code.
72
@todo Create new error codes if a NULL buffer pointer, or a
73
zero frame count is passed to Pa_ReadStream or Pa_WriteStream.
80
#include <assert.h> /* needed by PA_VALIDATE_ENDIANNESS */
82
#include "portaudio.h"
84
#include "pa_endianness.h"
86
#include "pa_hostapi.h"
87
#include "pa_stream.h"
88
#include "pa_trace.h" /* still usefull?*/
89
#include "pa_debugprint.h"
92
#define PA_VERSION_ 1899
93
#define PA_VERSION_TEXT_ "PortAudio V19-devel (built " __DATE__ " " __TIME__ ")"
98
int Pa_GetVersion( void )
104
const char* Pa_GetVersionText( void )
106
return PA_VERSION_TEXT_;
111
#define PA_LAST_HOST_ERROR_TEXT_LENGTH_ 1024
113
static char lastHostErrorText_[ PA_LAST_HOST_ERROR_TEXT_LENGTH_ + 1 ] = {0};
115
static PaHostErrorInfo lastHostErrorInfo_ = { (PaHostApiTypeId)-1, 0, lastHostErrorText_ };
118
void PaUtil_SetLastHostErrorInfo( PaHostApiTypeId hostApiType, long errorCode,
119
const char *errorText )
121
lastHostErrorInfo_.hostApiType = hostApiType;
122
lastHostErrorInfo_.errorCode = errorCode;
124
strncpy( lastHostErrorText_, errorText, PA_LAST_HOST_ERROR_TEXT_LENGTH_ );
129
static PaUtilHostApiRepresentation **hostApis_ = 0;
130
static int hostApisCount_ = 0;
131
static int initializationCount_ = 0;
132
static int deviceCount_ = 0;
134
PaUtilStreamRepresentation *firstOpenStream_ = NULL;
137
#define PA_IS_INITIALISED_ (initializationCount_ != 0)
140
static int CountHostApiInitializers( void )
144
while( paHostApiInitializers[ result ] != 0 )
150
static void TerminateHostApis( void )
152
/* terminate in reverse order from initialization */
153
PA_DEBUG(("TerminateHostApis in \n"));
155
while( hostApisCount_ > 0 )
158
hostApis_[hostApisCount_]->Terminate( hostApis_[hostApisCount_] );
164
PaUtil_FreeMemory( hostApis_ );
167
PA_DEBUG(("TerminateHostApis out\n"));
171
static PaError InitializeHostApis( void )
173
PaError result = paNoError;
174
int i, initializerCount, baseDeviceIndex;
176
initializerCount = CountHostApiInitializers();
178
hostApis_ = (PaUtilHostApiRepresentation**)PaUtil_AllocateMemory(
179
sizeof(PaUtilHostApiRepresentation*) * initializerCount );
182
result = paInsufficientMemory;
190
for( i=0; i< initializerCount; ++i )
192
hostApis_[hostApisCount_] = NULL;
194
PA_DEBUG(( "before paHostApiInitializers[%d].\n",i));
196
result = paHostApiInitializers[i]( &hostApis_[hostApisCount_], hostApisCount_ );
197
if( result != paNoError )
200
PA_DEBUG(( "after paHostApiInitializers[%d].\n",i));
202
if( hostApis_[hostApisCount_] )
204
PaUtilHostApiRepresentation* hostApi = hostApis_[hostApisCount_];
205
assert( hostApi->info.defaultInputDevice < hostApi->info.deviceCount );
206
assert( hostApi->info.defaultOutputDevice < hostApi->info.deviceCount );
208
hostApi->privatePaFrontInfo.baseDeviceIndex = baseDeviceIndex;
210
if( hostApi->info.defaultInputDevice != paNoDevice )
211
hostApi->info.defaultInputDevice += baseDeviceIndex;
213
if( hostApi->info.defaultOutputDevice != paNoDevice )
214
hostApi->info.defaultOutputDevice += baseDeviceIndex;
216
baseDeviceIndex += hostApi->info.deviceCount;
217
deviceCount_ += hostApi->info.deviceCount;
232
FindHostApi() finds the index of the host api to which
233
<device> belongs and returns it. if <hostSpecificDeviceIndex> is
234
non-null, the host specific device index is returned in it.
235
returns -1 if <device> is out of range.
238
static int FindHostApi( PaDeviceIndex device, int *hostSpecificDeviceIndex )
242
if( !PA_IS_INITIALISED_ )
248
while( i < hostApisCount_
249
&& device >= hostApis_[i]->info.deviceCount )
252
device -= hostApis_[i]->info.deviceCount;
256
if( i >= hostApisCount_ )
259
if( hostSpecificDeviceIndex )
260
*hostSpecificDeviceIndex = device;
266
static void AddOpenStream( PaStream* stream )
268
((PaUtilStreamRepresentation*)stream)->nextOpenStream = firstOpenStream_;
269
firstOpenStream_ = (PaUtilStreamRepresentation*)stream;
273
static void RemoveOpenStream( PaStream* stream )
275
PaUtilStreamRepresentation *previous = NULL;
276
PaUtilStreamRepresentation *current = firstOpenStream_;
278
while( current != NULL )
280
if( ((PaStream*)current) == stream )
282
if( previous == NULL )
284
firstOpenStream_ = current->nextOpenStream;
288
previous->nextOpenStream = current->nextOpenStream;
295
current = current->nextOpenStream;
301
static void CloseOpenStreams( void )
303
/* we call Pa_CloseStream() here to ensure that the same destruction
304
logic is used for automatically closed streams */
306
while( firstOpenStream_ != NULL )
307
Pa_CloseStream( firstOpenStream_ );
311
PaError Pa_Initialize( void )
315
PA_LOGAPI_ENTER( "Pa_Initialize" );
317
if( PA_IS_INITIALISED_ )
319
++initializationCount_;
324
PA_VALIDATE_TYPE_SIZES;
325
PA_VALIDATE_ENDIANNESS;
327
PaUtil_InitializeClock();
328
PaUtil_ResetTraceMessages();
330
result = InitializeHostApis();
331
if( result == paNoError )
332
++initializationCount_;
335
PA_LOGAPI_EXIT_PAERROR( "Pa_Initialize", result );
341
PaError Pa_Terminate( void )
345
PA_LOGAPI_ENTER( "Pa_Terminate" );
347
if( PA_IS_INITIALISED_ )
349
if( --initializationCount_ == 0 )
355
PaUtil_DumpTraceMessages();
361
result= paNotInitialized;
364
PA_LOGAPI_EXIT_PAERROR( "Pa_Terminate", result );
370
const PaHostErrorInfo* Pa_GetLastHostErrorInfo( void )
372
return &lastHostErrorInfo_;
376
const char *Pa_GetErrorText( PaError errorCode )
382
case paNoError: result = "Success"; break;
383
case paNotInitialized: result = "PortAudio not initialized"; break;
384
/** @todo could catenate the last host error text to result in the case of paUnanticipatedHostError */
385
case paUnanticipatedHostError: result = "Unanticipated host error"; break;
386
case paInvalidChannelCount: result = "Invalid number of channels"; break;
387
case paInvalidSampleRate: result = "Invalid sample rate"; break;
388
case paInvalidDevice: result = "Invalid device"; break;
389
case paInvalidFlag: result = "Invalid flag"; break;
390
case paSampleFormatNotSupported: result = "Sample format not supported"; break;
391
case paBadIODeviceCombination: result = "Illegal combination of I/O devices"; break;
392
case paInsufficientMemory: result = "Insufficient memory"; break;
393
case paBufferTooBig: result = "Buffer too big"; break;
394
case paBufferTooSmall: result = "Buffer too small"; break;
395
case paNullCallback: result = "No callback routine specified"; break;
396
case paBadStreamPtr: result = "Invalid stream pointer"; break;
397
case paTimedOut: result = "Wait timed out"; break;
398
case paInternalError: result = "Internal PortAudio error"; break;
399
case paDeviceUnavailable: result = "Device unavailable"; break;
400
case paIncompatibleHostApiSpecificStreamInfo: result = "Incompatible host API specific stream info"; break;
401
case paStreamIsStopped: result = "Stream is stopped"; break;
402
case paStreamIsNotStopped: result = "Stream is not stopped"; break;
403
case paInputOverflowed: result = "Input overflowed"; break;
404
case paOutputUnderflowed: result = "Output underflowed"; break;
405
case paHostApiNotFound: result = "Host API not found"; break;
406
case paInvalidHostApi: result = "Invalid host API"; break;
407
case paCanNotReadFromACallbackStream: result = "Can't read from a callback stream"; break;
408
case paCanNotWriteToACallbackStream: result = "Can't write to a callback stream"; break;
409
case paCanNotReadFromAnOutputOnlyStream: result = "Can't read from an output only stream"; break;
410
case paCanNotWriteToAnInputOnlyStream: result = "Can't write to an input only stream"; break;
411
case paIncompatibleStreamHostApi: result = "Incompatible stream host API"; break;
412
case paBadBufferPtr: result = "Bad buffer pointer"; break;
415
result = "Invalid error code (value greater than zero)";
417
result = "Invalid error code";
424
PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type )
426
PaHostApiIndex result;
429
PA_LOGAPI_ENTER_PARAMS( "Pa_HostApiTypeIdToHostApiIndex" );
430
PA_LOGAPI(("\tPaHostApiTypeId type: %d\n", type ));
432
if( !PA_IS_INITIALISED_ )
434
result = paNotInitialized;
438
result = paHostApiNotFound;
440
for( i=0; i < hostApisCount_; ++i )
442
if( hostApis_[i]->info.type == type )
450
PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT( "Pa_HostApiTypeIdToHostApiIndex", "PaHostApiIndex: %d", result );
456
PaError PaUtil_GetHostApiRepresentation( struct PaUtilHostApiRepresentation **hostApi,
457
PaHostApiTypeId type )
462
if( !PA_IS_INITIALISED_ )
464
result = paNotInitialized;
468
result = paHostApiNotFound;
470
for( i=0; i < hostApisCount_; ++i )
472
if( hostApis_[i]->info.type == type )
474
*hostApi = hostApis_[i];
485
PaError PaUtil_DeviceIndexToHostApiDeviceIndex(
486
PaDeviceIndex *hostApiDevice, PaDeviceIndex device, struct PaUtilHostApiRepresentation *hostApi )
491
x = device - hostApi->privatePaFrontInfo.baseDeviceIndex;
493
if( x < 0 || x >= hostApi->info.deviceCount )
495
result = paInvalidDevice;
507
PaHostApiIndex Pa_GetHostApiCount( void )
511
PA_LOGAPI_ENTER( "Pa_GetHostApiCount" );
513
if( !PA_IS_INITIALISED_ )
515
result = paNotInitialized;
519
result = hostApisCount_;
522
PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT( "Pa_GetHostApiCount", "PaHostApiIndex: %d", result );
528
PaHostApiIndex Pa_GetDefaultHostApi( void )
532
PA_LOGAPI_ENTER( "Pa_GetDefaultHostApi" );
534
if( !PA_IS_INITIALISED_ )
536
result = paNotInitialized;
540
result = paDefaultHostApiIndex;
542
/* internal consistency check: make sure that the default host api
543
index is within range */
545
if( result < 0 || result >= hostApisCount_ )
547
result = paInternalError;
551
PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT( "Pa_GetDefaultHostApi", "PaHostApiIndex: %d", result );
557
const PaHostApiInfo* Pa_GetHostApiInfo( PaHostApiIndex hostApi )
561
PA_LOGAPI_ENTER_PARAMS( "Pa_GetHostApiInfo" );
562
PA_LOGAPI(("\tPaHostApiIndex hostApi: %d\n", hostApi ));
564
if( !PA_IS_INITIALISED_ )
568
PA_LOGAPI(("Pa_GetHostApiInfo returned:\n" ));
569
PA_LOGAPI(("\tPaHostApiInfo*: NULL [ PortAudio not initialized ]\n" ));
572
else if( hostApi < 0 || hostApi >= hostApisCount_ )
576
PA_LOGAPI(("Pa_GetHostApiInfo returned:\n" ));
577
PA_LOGAPI(("\tPaHostApiInfo*: NULL [ hostApi out of range ]\n" ));
582
info = &hostApis_[hostApi]->info;
584
PA_LOGAPI(("Pa_GetHostApiInfo returned:\n" ));
585
PA_LOGAPI(("\tPaHostApiInfo*: 0x%p\n", info ));
586
PA_LOGAPI(("\t{\n" ));
587
PA_LOGAPI(("\t\tint structVersion: %d\n", info->structVersion ));
588
PA_LOGAPI(("\t\tPaHostApiTypeId type: %d\n", info->type ));
589
PA_LOGAPI(("\t\tconst char *name: %s\n", info->name ));
590
PA_LOGAPI(("\t}\n" ));
598
PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi, int hostApiDeviceIndex )
600
PaDeviceIndex result;
602
PA_LOGAPI_ENTER_PARAMS( "Pa_HostApiDeviceIndexToPaDeviceIndex" );
603
PA_LOGAPI(("\tPaHostApiIndex hostApi: %d\n", hostApi ));
604
PA_LOGAPI(("\tint hostApiDeviceIndex: %d\n", hostApiDeviceIndex ));
606
if( !PA_IS_INITIALISED_ )
608
result = paNotInitialized;
612
if( hostApi < 0 || hostApi >= hostApisCount_ )
614
result = paInvalidHostApi;
618
if( hostApiDeviceIndex < 0 ||
619
hostApiDeviceIndex >= hostApis_[hostApi]->info.deviceCount )
621
result = paInvalidDevice;
625
result = hostApis_[hostApi]->privatePaFrontInfo.baseDeviceIndex + hostApiDeviceIndex;
630
PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT( "Pa_HostApiDeviceIndexToPaDeviceIndex", "PaDeviceIndex: %d", result );
636
PaDeviceIndex Pa_GetDeviceCount( void )
638
PaDeviceIndex result;
640
PA_LOGAPI_ENTER( "Pa_GetDeviceCount" );
642
if( !PA_IS_INITIALISED_ )
644
result = paNotInitialized;
648
result = deviceCount_;
651
PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT( "Pa_GetDeviceCount", "PaDeviceIndex: %d", result );
657
PaDeviceIndex Pa_GetDefaultInputDevice( void )
659
PaHostApiIndex hostApi;
660
PaDeviceIndex result;
662
PA_LOGAPI_ENTER( "Pa_GetDefaultInputDevice" );
664
hostApi = Pa_GetDefaultHostApi();
671
result = hostApis_[hostApi]->info.defaultInputDevice;
674
PA_LOGAPI_EXIT_T( "Pa_GetDefaultInputDevice", "PaDeviceIndex: %d", result );
680
PaDeviceIndex Pa_GetDefaultOutputDevice( void )
682
PaHostApiIndex hostApi;
683
PaDeviceIndex result;
685
PA_LOGAPI_ENTER( "Pa_GetDefaultOutputDevice" );
687
hostApi = Pa_GetDefaultHostApi();
694
result = hostApis_[hostApi]->info.defaultOutputDevice;
697
PA_LOGAPI_EXIT_T( "Pa_GetDefaultOutputDevice", "PaDeviceIndex: %d", result );
703
const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device )
705
int hostSpecificDeviceIndex;
706
int hostApiIndex = FindHostApi( device, &hostSpecificDeviceIndex );
707
PaDeviceInfo *result;
710
PA_LOGAPI_ENTER_PARAMS( "Pa_GetDeviceInfo" );
711
PA_LOGAPI(("\tPaDeviceIndex device: %d\n", device ));
713
if( hostApiIndex < 0 )
717
PA_LOGAPI(("Pa_GetDeviceInfo returned:\n" ));
718
PA_LOGAPI(("\tPaDeviceInfo* NULL [ invalid device index ]\n" ));
723
result = hostApis_[hostApiIndex]->deviceInfos[ hostSpecificDeviceIndex ];
725
PA_LOGAPI(("Pa_GetDeviceInfo returned:\n" ));
726
PA_LOGAPI(("\tPaDeviceInfo*: 0x%p:\n", result ));
727
PA_LOGAPI(("\t{\n" ));
729
PA_LOGAPI(("\t\tint structVersion: %d\n", result->structVersion ));
730
PA_LOGAPI(("\t\tconst char *name: %s\n", result->name ));
731
PA_LOGAPI(("\t\tPaHostApiIndex hostApi: %d\n", result->hostApi ));
732
PA_LOGAPI(("\t\tint maxInputChannels: %d\n", result->maxInputChannels ));
733
PA_LOGAPI(("\t\tint maxOutputChannels: %d\n", result->maxOutputChannels ));
734
PA_LOGAPI(("\t}\n" ));
743
SampleFormatIsValid() returns 1 if sampleFormat is a sample format
744
defined in portaudio.h, or 0 otherwise.
746
static int SampleFormatIsValid( PaSampleFormat format )
748
switch( format & ~paNonInterleaved )
750
case paFloat32: return 1;
751
case paInt16: return 1;
752
case paInt32: return 1;
753
case paInt24: return 1;
754
case paInt8: return 1;
755
case paUInt8: return 1;
756
case paCustomFormat: return 1;
762
NOTE: make sure this validation list is kept syncronised with the one in
765
ValidateOpenStreamParameters() checks that parameters to Pa_OpenStream()
766
conform to the expected values as described below. This function is
767
also designed to be used with the proposed Pa_IsFormatSupported() function.
769
There are basically two types of validation that could be performed:
770
Generic conformance validation, and device capability mismatch
771
validation. This function performs only generic conformance validation.
772
Validation that would require knowledge of device capabilities is
773
not performed because of potentially complex relationships between
774
combinations of parameters - for example, even if the sampleRate
775
seems ok, it might not be for a duplex stream - we have no way of
776
checking this in an API-neutral way, so we don't try.
778
On success the function returns PaNoError and fills in hostApi,
779
hostApiInputDeviceID, and hostApiOutputDeviceID fields. On failure
780
the function returns an error code indicating the first encountered
784
If ValidateOpenStreamParameters() returns paNoError, the following
785
assertions are guaranteed to be true.
787
- at least one of inputParameters & outputParmeters is valid (not NULL)
789
- if inputParameters & outputParameters are both valid, that
790
inputParameters->device & outputParameters->device both use the same host api
792
PaDeviceIndex inputParameters->device
793
- is within range (0 to Pa_GetDeviceCount-1) Or:
794
- is paUseHostApiSpecificDeviceSpecification and
795
inputParameters->hostApiSpecificStreamInfo is non-NULL and refers
798
int inputParameters->channelCount
799
- if inputParameters->device is not paUseHostApiSpecificDeviceSpecification, channelCount is > 0
800
- upper bound is NOT validated against device capabilities
802
PaSampleFormat inputParameters->sampleFormat
803
- is one of the sample formats defined in portaudio.h
805
void *inputParameters->hostApiSpecificStreamInfo
806
- if supplied its hostApi field matches the input device's host Api
808
PaDeviceIndex outputParmeters->device
809
- is within range (0 to Pa_GetDeviceCount-1)
811
int outputParmeters->channelCount
812
- if inputDevice is valid, channelCount is > 0
813
- upper bound is NOT validated against device capabilities
815
PaSampleFormat outputParmeters->sampleFormat
816
- is one of the sample formats defined in portaudio.h
818
void *outputParmeters->hostApiSpecificStreamInfo
819
- if supplied its hostApi field matches the output device's host Api
822
- is not an 'absurd' rate (less than 1000. or greater than 200000.)
823
- sampleRate is NOT validated against device capabilities
825
PaStreamFlags streamFlags
826
- unused platform neutral flags are zero
827
- paNeverDropInput is only used for full-duplex callback streams with
828
variable buffer size (paFramesPerBufferUnspecified)
830
static PaError ValidateOpenStreamParameters(
831
const PaStreamParameters *inputParameters,
832
const PaStreamParameters *outputParameters,
834
unsigned long framesPerBuffer,
835
PaStreamFlags streamFlags,
836
PaStreamCallback *streamCallback,
837
PaUtilHostApiRepresentation **hostApi,
838
PaDeviceIndex *hostApiInputDevice,
839
PaDeviceIndex *hostApiOutputDevice )
841
int inputHostApiIndex = -1, /* Surpress uninitialised var warnings: compiler does */
842
outputHostApiIndex = -1; /* not see that if inputParameters and outputParame- */
843
/* ters are both nonzero, these indices are set. */
845
if( (inputParameters == NULL) && (outputParameters == NULL) )
847
return paInvalidDevice; /** @todo should be a new error code "invalid device parameters" or something */
851
if( inputParameters == NULL )
853
*hostApiInputDevice = paNoDevice;
855
else if( inputParameters->device == paUseHostApiSpecificDeviceSpecification )
857
if( inputParameters->hostApiSpecificStreamInfo )
859
inputHostApiIndex = Pa_HostApiTypeIdToHostApiIndex(
860
((PaUtilHostApiSpecificStreamInfoHeader*)inputParameters->hostApiSpecificStreamInfo)->hostApiType );
862
if( inputHostApiIndex != -1 )
864
*hostApiInputDevice = paUseHostApiSpecificDeviceSpecification;
865
*hostApi = hostApis_[inputHostApiIndex];
869
return paInvalidDevice;
874
return paInvalidDevice;
879
if( inputParameters->device < 0 || inputParameters->device >= deviceCount_ )
880
return paInvalidDevice;
882
inputHostApiIndex = FindHostApi( inputParameters->device, hostApiInputDevice );
883
if( inputHostApiIndex < 0 )
884
return paInternalError;
886
*hostApi = hostApis_[inputHostApiIndex];
888
if( inputParameters->channelCount <= 0 )
889
return paInvalidChannelCount;
891
if( !SampleFormatIsValid( inputParameters->sampleFormat ) )
892
return paSampleFormatNotSupported;
894
if( inputParameters->hostApiSpecificStreamInfo != NULL )
896
if( ((PaUtilHostApiSpecificStreamInfoHeader*)inputParameters->hostApiSpecificStreamInfo)->hostApiType
897
!= (*hostApi)->info.type )
898
return paIncompatibleHostApiSpecificStreamInfo;
902
if( outputParameters == NULL )
904
*hostApiOutputDevice = paNoDevice;
906
else if( outputParameters->device == paUseHostApiSpecificDeviceSpecification )
908
if( outputParameters->hostApiSpecificStreamInfo )
910
outputHostApiIndex = Pa_HostApiTypeIdToHostApiIndex(
911
((PaUtilHostApiSpecificStreamInfoHeader*)outputParameters->hostApiSpecificStreamInfo)->hostApiType );
913
if( outputHostApiIndex != -1 )
915
*hostApiOutputDevice = paUseHostApiSpecificDeviceSpecification;
916
*hostApi = hostApis_[outputHostApiIndex];
920
return paInvalidDevice;
925
return paInvalidDevice;
930
if( outputParameters->device < 0 || outputParameters->device >= deviceCount_ )
931
return paInvalidDevice;
933
outputHostApiIndex = FindHostApi( outputParameters->device, hostApiOutputDevice );
934
if( outputHostApiIndex < 0 )
935
return paInternalError;
937
*hostApi = hostApis_[outputHostApiIndex];
939
if( outputParameters->channelCount <= 0 )
940
return paInvalidChannelCount;
942
if( !SampleFormatIsValid( outputParameters->sampleFormat ) )
943
return paSampleFormatNotSupported;
945
if( outputParameters->hostApiSpecificStreamInfo != NULL )
947
if( ((PaUtilHostApiSpecificStreamInfoHeader*)outputParameters->hostApiSpecificStreamInfo)->hostApiType
948
!= (*hostApi)->info.type )
949
return paIncompatibleHostApiSpecificStreamInfo;
953
if( (inputParameters != NULL) && (outputParameters != NULL) )
955
/* ensure that both devices use the same API */
956
if( inputHostApiIndex != outputHostApiIndex )
957
return paBadIODeviceCombination;
962
/* Check for absurd sample rates. */
963
if( (sampleRate < 1000.0) || (sampleRate > 200000.0) )
964
return paInvalidSampleRate;
966
if( ((streamFlags & ~paPlatformSpecificFlags) & ~(paClipOff | paDitherOff | paNeverDropInput | paPrimeOutputBuffersUsingStreamCallback ) ) != 0 )
967
return paInvalidFlag;
969
if( streamFlags & paNeverDropInput )
971
/* must be a callback stream */
972
if( !streamCallback )
973
return paInvalidFlag;
975
/* must be a full duplex stream */
976
if( (inputParameters == NULL) || (outputParameters == NULL) )
977
return paInvalidFlag;
979
/* must use paFramesPerBufferUnspecified */
980
if( framesPerBuffer != paFramesPerBufferUnspecified )
981
return paInvalidFlag;
988
PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters,
989
const PaStreamParameters *outputParameters,
993
PaUtilHostApiRepresentation *hostApi = 0;
994
PaDeviceIndex hostApiInputDevice = paNoDevice, hostApiOutputDevice = paNoDevice;
995
PaStreamParameters hostApiInputParameters, hostApiOutputParameters;
996
PaStreamParameters *hostApiInputParametersPtr, *hostApiOutputParametersPtr;
999
#ifdef PA_LOG_API_CALLS
1000
PA_LOGAPI_ENTER_PARAMS( "Pa_IsFormatSupported" );
1002
if( inputParameters == NULL ){
1003
PA_LOGAPI(("\tPaStreamParameters *inputParameters: NULL\n" ));
1005
PA_LOGAPI(("\tPaStreamParameters *inputParameters: 0x%p\n", inputParameters ));
1006
PA_LOGAPI(("\tPaDeviceIndex inputParameters->device: %d\n", inputParameters->device ));
1007
PA_LOGAPI(("\tint inputParameters->channelCount: %d\n", inputParameters->channelCount ));
1008
PA_LOGAPI(("\tPaSampleFormat inputParameters->sampleFormat: %d\n", inputParameters->sampleFormat ));
1009
PA_LOGAPI(("\tPaTime inputParameters->suggestedLatency: %f\n", inputParameters->suggestedLatency ));
1010
PA_LOGAPI(("\tvoid *inputParameters->hostApiSpecificStreamInfo: 0x%p\n", inputParameters->hostApiSpecificStreamInfo ));
1013
if( outputParameters == NULL ){
1014
PA_LOGAPI(("\tPaStreamParameters *outputParameters: NULL\n" ));
1016
PA_LOGAPI(("\tPaStreamParameters *outputParameters: 0x%p\n", outputParameters ));
1017
PA_LOGAPI(("\tPaDeviceIndex outputParameters->device: %d\n", outputParameters->device ));
1018
PA_LOGAPI(("\tint outputParameters->channelCount: %d\n", outputParameters->channelCount ));
1019
PA_LOGAPI(("\tPaSampleFormat outputParameters->sampleFormat: %d\n", outputParameters->sampleFormat ));
1020
PA_LOGAPI(("\tPaTime outputParameters->suggestedLatency: %f\n", outputParameters->suggestedLatency ));
1021
PA_LOGAPI(("\tvoid *outputParameters->hostApiSpecificStreamInfo: 0x%p\n", outputParameters->hostApiSpecificStreamInfo ));
1024
PA_LOGAPI(("\tdouble sampleRate: %g\n", sampleRate ));
1027
if( !PA_IS_INITIALISED_ )
1029
result = paNotInitialized;
1031
PA_LOGAPI_EXIT_PAERROR( "Pa_IsFormatSupported", result );
1035
result = ValidateOpenStreamParameters( inputParameters,
1037
sampleRate, 0, paNoFlag, 0,
1039
&hostApiInputDevice,
1040
&hostApiOutputDevice );
1041
if( result != paNoError )
1043
PA_LOGAPI_EXIT_PAERROR( "Pa_IsFormatSupported", result );
1048
if( inputParameters )
1050
hostApiInputParameters.device = hostApiInputDevice;
1051
hostApiInputParameters.channelCount = inputParameters->channelCount;
1052
hostApiInputParameters.sampleFormat = inputParameters->sampleFormat;
1053
hostApiInputParameters.suggestedLatency = inputParameters->suggestedLatency;
1054
hostApiInputParameters.hostApiSpecificStreamInfo = inputParameters->hostApiSpecificStreamInfo;
1055
hostApiInputParametersPtr = &hostApiInputParameters;
1059
hostApiInputParametersPtr = NULL;
1062
if( outputParameters )
1064
hostApiOutputParameters.device = hostApiOutputDevice;
1065
hostApiOutputParameters.channelCount = outputParameters->channelCount;
1066
hostApiOutputParameters.sampleFormat = outputParameters->sampleFormat;
1067
hostApiOutputParameters.suggestedLatency = outputParameters->suggestedLatency;
1068
hostApiOutputParameters.hostApiSpecificStreamInfo = outputParameters->hostApiSpecificStreamInfo;
1069
hostApiOutputParametersPtr = &hostApiOutputParameters;
1073
hostApiOutputParametersPtr = NULL;
1076
result = hostApi->IsFormatSupported( hostApi,
1077
hostApiInputParametersPtr, hostApiOutputParametersPtr,
1080
#ifdef PA_LOG_API_CALLS
1081
PA_LOGAPI(("Pa_OpenStream returned:\n" ));
1082
if( result == paFormatIsSupported )
1083
PA_LOGAPI(("\tPaError: 0 [ paFormatIsSupported ]\n" ));
1085
PA_LOGAPI(("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) ));
1092
PaError Pa_OpenStream( PaStream** stream,
1093
const PaStreamParameters *inputParameters,
1094
const PaStreamParameters *outputParameters,
1096
unsigned long framesPerBuffer,
1097
PaStreamFlags streamFlags,
1098
PaStreamCallback *streamCallback,
1102
PaUtilHostApiRepresentation *hostApi = 0;
1103
PaDeviceIndex hostApiInputDevice = paNoDevice, hostApiOutputDevice = paNoDevice;
1104
PaStreamParameters hostApiInputParameters, hostApiOutputParameters;
1105
PaStreamParameters *hostApiInputParametersPtr, *hostApiOutputParametersPtr;
1108
#ifdef PA_LOG_API_CALLS
1109
PA_LOGAPI_ENTER_PARAMS( "Pa_OpenStream" );
1110
PA_LOGAPI(("\tPaStream** stream: 0x%p\n", stream ));
1112
if( inputParameters == NULL ){
1113
PA_LOGAPI(("\tPaStreamParameters *inputParameters: NULL\n" ));
1115
PA_LOGAPI(("\tPaStreamParameters *inputParameters: 0x%p\n", inputParameters ));
1116
PA_LOGAPI(("\tPaDeviceIndex inputParameters->device: %d\n", inputParameters->device ));
1117
PA_LOGAPI(("\tint inputParameters->channelCount: %d\n", inputParameters->channelCount ));
1118
PA_LOGAPI(("\tPaSampleFormat inputParameters->sampleFormat: %d\n", inputParameters->sampleFormat ));
1119
PA_LOGAPI(("\tPaTime inputParameters->suggestedLatency: %f\n", inputParameters->suggestedLatency ));
1120
PA_LOGAPI(("\tvoid *inputParameters->hostApiSpecificStreamInfo: 0x%p\n", inputParameters->hostApiSpecificStreamInfo ));
1123
if( outputParameters == NULL ){
1124
PA_LOGAPI(("\tPaStreamParameters *outputParameters: NULL\n" ));
1126
PA_LOGAPI(("\tPaStreamParameters *outputParameters: 0x%p\n", outputParameters ));
1127
PA_LOGAPI(("\tPaDeviceIndex outputParameters->device: %d\n", outputParameters->device ));
1128
PA_LOGAPI(("\tint outputParameters->channelCount: %d\n", outputParameters->channelCount ));
1129
PA_LOGAPI(("\tPaSampleFormat outputParameters->sampleFormat: %d\n", outputParameters->sampleFormat ));
1130
PA_LOGAPI(("\tPaTime outputParameters->suggestedLatency: %f\n", outputParameters->suggestedLatency ));
1131
PA_LOGAPI(("\tvoid *outputParameters->hostApiSpecificStreamInfo: 0x%p\n", outputParameters->hostApiSpecificStreamInfo ));
1134
PA_LOGAPI(("\tdouble sampleRate: %g\n", sampleRate ));
1135
PA_LOGAPI(("\tunsigned long framesPerBuffer: %d\n", framesPerBuffer ));
1136
PA_LOGAPI(("\tPaStreamFlags streamFlags: 0x%x\n", streamFlags ));
1137
PA_LOGAPI(("\tPaStreamCallback *streamCallback: 0x%p\n", streamCallback ));
1138
PA_LOGAPI(("\tvoid *userData: 0x%p\n", userData ));
1141
if( !PA_IS_INITIALISED_ )
1143
result = paNotInitialized;
1145
PA_LOGAPI(("Pa_OpenStream returned:\n" ));
1146
PA_LOGAPI(("\t*(PaStream** stream): undefined\n" ));
1147
PA_LOGAPI(("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) ));
1151
/* Check for parameter errors.
1152
NOTE: make sure this validation list is kept syncronised with the one
1156
if( stream == NULL )
1158
result = paBadStreamPtr;
1160
PA_LOGAPI(("Pa_OpenStream returned:\n" ));
1161
PA_LOGAPI(("\t*(PaStream** stream): undefined\n" ));
1162
PA_LOGAPI(("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) ));
1166
result = ValidateOpenStreamParameters( inputParameters,
1168
sampleRate, framesPerBuffer,
1169
streamFlags, streamCallback,
1171
&hostApiInputDevice,
1172
&hostApiOutputDevice );
1173
if( result != paNoError )
1175
PA_LOGAPI(("Pa_OpenStream returned:\n" ));
1176
PA_LOGAPI(("\t*(PaStream** stream): undefined\n" ));
1177
PA_LOGAPI(("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) ));
1182
if( inputParameters )
1184
hostApiInputParameters.device = hostApiInputDevice;
1185
hostApiInputParameters.channelCount = inputParameters->channelCount;
1186
hostApiInputParameters.sampleFormat = inputParameters->sampleFormat;
1187
hostApiInputParameters.suggestedLatency = inputParameters->suggestedLatency;
1188
hostApiInputParameters.hostApiSpecificStreamInfo = inputParameters->hostApiSpecificStreamInfo;
1189
hostApiInputParametersPtr = &hostApiInputParameters;
1193
hostApiInputParametersPtr = NULL;
1196
if( outputParameters )
1198
hostApiOutputParameters.device = hostApiOutputDevice;
1199
hostApiOutputParameters.channelCount = outputParameters->channelCount;
1200
hostApiOutputParameters.sampleFormat = outputParameters->sampleFormat;
1201
hostApiOutputParameters.suggestedLatency = outputParameters->suggestedLatency;
1202
hostApiOutputParameters.hostApiSpecificStreamInfo = outputParameters->hostApiSpecificStreamInfo;
1203
hostApiOutputParametersPtr = &hostApiOutputParameters;
1207
hostApiOutputParametersPtr = NULL;
1210
result = hostApi->OpenStream( hostApi, stream,
1211
hostApiInputParametersPtr, hostApiOutputParametersPtr,
1212
sampleRate, framesPerBuffer, streamFlags, streamCallback, userData );
1214
if( result == paNoError )
1215
AddOpenStream( *stream );
1218
PA_LOGAPI(("Pa_OpenStream returned:\n" ));
1219
PA_LOGAPI(("\t*(PaStream** stream): 0x%p\n", *stream ));
1220
PA_LOGAPI(("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) ));
1226
PaError Pa_OpenDefaultStream( PaStream** stream,
1227
int inputChannelCount,
1228
int outputChannelCount,
1229
PaSampleFormat sampleFormat,
1231
unsigned long framesPerBuffer,
1232
PaStreamCallback *streamCallback,
1236
PaStreamParameters hostApiInputParameters, hostApiOutputParameters;
1237
PaStreamParameters *hostApiInputParametersPtr, *hostApiOutputParametersPtr;
1239
PA_LOGAPI_ENTER_PARAMS( "Pa_OpenDefaultStream" );
1240
PA_LOGAPI(("\tPaStream** stream: 0x%p\n", stream ));
1241
PA_LOGAPI(("\tint inputChannelCount: %d\n", inputChannelCount ));
1242
PA_LOGAPI(("\tint outputChannelCount: %d\n", outputChannelCount ));
1243
PA_LOGAPI(("\tPaSampleFormat sampleFormat: %d\n", sampleFormat ));
1244
PA_LOGAPI(("\tdouble sampleRate: %g\n", sampleRate ));
1245
PA_LOGAPI(("\tunsigned long framesPerBuffer: %d\n", framesPerBuffer ));
1246
PA_LOGAPI(("\tPaStreamCallback *streamCallback: 0x%p\n", streamCallback ));
1247
PA_LOGAPI(("\tvoid *userData: 0x%p\n", userData ));
1250
if( inputChannelCount > 0 )
1252
hostApiInputParameters.device = Pa_GetDefaultInputDevice();
1253
if( hostApiInputParameters.device == paNoDevice )
1254
return paDeviceUnavailable;
1256
hostApiInputParameters.channelCount = inputChannelCount;
1257
hostApiInputParameters.sampleFormat = sampleFormat;
1258
/* defaultHighInputLatency is used below instead of
1259
defaultLowInputLatency because it is more important for the default
1260
stream to work reliably than it is for it to work with the lowest
1263
hostApiInputParameters.suggestedLatency =
1264
Pa_GetDeviceInfo( hostApiInputParameters.device )->defaultHighInputLatency;
1265
hostApiInputParameters.hostApiSpecificStreamInfo = NULL;
1266
hostApiInputParametersPtr = &hostApiInputParameters;
1270
hostApiInputParametersPtr = NULL;
1273
if( outputChannelCount > 0 )
1275
hostApiOutputParameters.device = Pa_GetDefaultOutputDevice();
1276
if( hostApiOutputParameters.device == paNoDevice )
1277
return paDeviceUnavailable;
1279
hostApiOutputParameters.channelCount = outputChannelCount;
1280
hostApiOutputParameters.sampleFormat = sampleFormat;
1281
/* defaultHighOutputLatency is used below instead of
1282
defaultLowOutputLatency because it is more important for the default
1283
stream to work reliably than it is for it to work with the lowest
1286
hostApiOutputParameters.suggestedLatency =
1287
Pa_GetDeviceInfo( hostApiOutputParameters.device )->defaultHighOutputLatency;
1288
hostApiOutputParameters.hostApiSpecificStreamInfo = NULL;
1289
hostApiOutputParametersPtr = &hostApiOutputParameters;
1293
hostApiOutputParametersPtr = NULL;
1297
result = Pa_OpenStream(
1298
stream, hostApiInputParametersPtr, hostApiOutputParametersPtr,
1299
sampleRate, framesPerBuffer, paNoFlag, streamCallback, userData );
1301
PA_LOGAPI(("Pa_OpenDefaultStream returned:\n" ));
1302
PA_LOGAPI(("\t*(PaStream** stream): 0x%p", *stream ));
1303
PA_LOGAPI(("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) ));
1309
PaError PaUtil_ValidateStreamPointer( PaStream* stream )
1311
if( !PA_IS_INITIALISED_ ) return paNotInitialized;
1313
if( stream == NULL ) return paBadStreamPtr;
1315
if( ((PaUtilStreamRepresentation*)stream)->magic != PA_STREAM_MAGIC )
1316
return paBadStreamPtr;
1322
PaError Pa_CloseStream( PaStream* stream )
1324
PaUtilStreamInterface *interface;
1325
PaError result = PaUtil_ValidateStreamPointer( stream );
1327
PA_LOGAPI_ENTER_PARAMS( "Pa_CloseStream" );
1328
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1330
/* always remove the open stream from our list, even if this function
1331
eventually returns an error. Otherwise CloseOpenStreams() will
1332
get stuck in an infinite loop */
1333
RemoveOpenStream( stream ); /* be sure to call this _before_ closing the stream */
1335
if( result == paNoError )
1337
interface = PA_STREAM_INTERFACE(stream);
1339
/* abort the stream if it isn't stopped */
1340
result = interface->IsStopped( stream );
1343
else if( result == 0 )
1344
result = interface->Abort( stream );
1346
if( result == paNoError ) /** @todo REVIEW: shouldn't we close anyway? */
1347
result = interface->Close( stream );
1350
PA_LOGAPI_EXIT_PAERROR( "Pa_CloseStream", result );
1356
PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback )
1358
PaError result = PaUtil_ValidateStreamPointer( stream );
1360
PA_LOGAPI_ENTER_PARAMS( "Pa_SetStreamFinishedCallback" );
1361
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1362
PA_LOGAPI(("\tPaStreamFinishedCallback* streamFinishedCallback: 0x%p\n", streamFinishedCallback ));
1364
if( result == paNoError )
1366
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1369
result = paStreamIsNotStopped ;
1373
PA_STREAM_REP( stream )->streamFinishedCallback = streamFinishedCallback;
1378
PA_LOGAPI_EXIT_PAERROR( "Pa_SetStreamFinishedCallback", result );
1385
PaError Pa_StartStream( PaStream *stream )
1387
PaError result = PaUtil_ValidateStreamPointer( stream );
1389
PA_LOGAPI_ENTER_PARAMS( "Pa_StartStream" );
1390
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1392
if( result == paNoError )
1394
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1397
result = paStreamIsNotStopped ;
1399
else if( result == 1 )
1401
result = PA_STREAM_INTERFACE(stream)->Start( stream );
1405
PA_LOGAPI_EXIT_PAERROR( "Pa_StartStream", result );
1411
PaError Pa_StopStream( PaStream *stream )
1413
PaError result = PaUtil_ValidateStreamPointer( stream );
1415
PA_LOGAPI_ENTER_PARAMS( "Pa_StopStream" );
1416
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1418
if( result == paNoError )
1420
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1423
result = PA_STREAM_INTERFACE(stream)->Stop( stream );
1425
else if( result == 1 )
1427
result = paStreamIsStopped;
1431
PA_LOGAPI_EXIT_PAERROR( "Pa_StopStream", result );
1437
PaError Pa_AbortStream( PaStream *stream )
1439
PaError result = PaUtil_ValidateStreamPointer( stream );
1441
PA_LOGAPI_ENTER_PARAMS( "Pa_AbortStream" );
1442
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1444
if( result == paNoError )
1446
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1449
result = PA_STREAM_INTERFACE(stream)->Abort( stream );
1451
else if( result == 1 )
1453
result = paStreamIsStopped;
1457
PA_LOGAPI_EXIT_PAERROR( "Pa_AbortStream", result );
1463
PaError Pa_IsStreamStopped( PaStream *stream )
1465
PaError result = PaUtil_ValidateStreamPointer( stream );
1467
PA_LOGAPI_ENTER_PARAMS( "Pa_IsStreamStopped" );
1468
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1470
if( result == paNoError )
1471
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1473
PA_LOGAPI_EXIT_PAERROR( "Pa_IsStreamStopped", result );
1479
PaError Pa_IsStreamActive( PaStream *stream )
1481
PaError result = PaUtil_ValidateStreamPointer( stream );
1483
PA_LOGAPI_ENTER_PARAMS( "Pa_IsStreamActive" );
1484
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1486
if( result == paNoError )
1487
result = PA_STREAM_INTERFACE(stream)->IsActive( stream );
1490
PA_LOGAPI_EXIT_PAERROR( "Pa_IsStreamActive", result );
1496
const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream )
1498
PaError error = PaUtil_ValidateStreamPointer( stream );
1499
const PaStreamInfo *result;
1501
PA_LOGAPI_ENTER_PARAMS( "Pa_GetStreamInfo" );
1502
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1504
if( error != paNoError )
1508
PA_LOGAPI(("Pa_GetStreamInfo returned:\n" ));
1509
PA_LOGAPI(("\tconst PaStreamInfo*: 0 [PaError error:%d ( %s )]\n", error, Pa_GetErrorText( error ) ));
1514
result = &PA_STREAM_REP( stream )->streamInfo;
1516
PA_LOGAPI(("Pa_GetStreamInfo returned:\n" ));
1517
PA_LOGAPI(("\tconst PaStreamInfo*: 0x%p:\n", result ));
1518
PA_LOGAPI(("\t{" ));
1520
PA_LOGAPI(("\t\tint structVersion: %d\n", result->structVersion ));
1521
PA_LOGAPI(("\t\tPaTime inputLatency: %f\n", result->inputLatency ));
1522
PA_LOGAPI(("\t\tPaTime outputLatency: %f\n", result->outputLatency ));
1523
PA_LOGAPI(("\t\tdouble sampleRate: %f\n", result->sampleRate ));
1524
PA_LOGAPI(("\t}\n" ));
1532
PaTime Pa_GetStreamTime( PaStream *stream )
1534
PaError error = PaUtil_ValidateStreamPointer( stream );
1537
PA_LOGAPI_ENTER_PARAMS( "Pa_GetStreamTime" );
1538
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1540
if( error != paNoError )
1544
PA_LOGAPI(("Pa_GetStreamTime returned:\n" ));
1545
PA_LOGAPI(("\tPaTime: 0 [PaError error:%d ( %s )]\n", result, error, Pa_GetErrorText( error ) ));
1550
result = PA_STREAM_INTERFACE(stream)->GetTime( stream );
1552
PA_LOGAPI(("Pa_GetStreamTime returned:\n" ));
1553
PA_LOGAPI(("\tPaTime: %g\n", result ));
1561
double Pa_GetStreamCpuLoad( PaStream* stream )
1563
PaError error = PaUtil_ValidateStreamPointer( stream );
1566
PA_LOGAPI_ENTER_PARAMS( "Pa_GetStreamCpuLoad" );
1567
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1569
if( error != paNoError )
1574
PA_LOGAPI(("Pa_GetStreamCpuLoad returned:\n" ));
1575
PA_LOGAPI(("\tdouble: 0.0 [PaError error: %d ( %s )]\n", error, Pa_GetErrorText( error ) ));
1580
result = PA_STREAM_INTERFACE(stream)->GetCpuLoad( stream );
1582
PA_LOGAPI(("Pa_GetStreamCpuLoad returned:\n" ));
1583
PA_LOGAPI(("\tdouble: %g\n", result ));
1591
PaError Pa_ReadStream( PaStream* stream,
1593
unsigned long frames )
1595
PaError result = PaUtil_ValidateStreamPointer( stream );
1597
PA_LOGAPI_ENTER_PARAMS( "Pa_ReadStream" );
1598
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1600
if( result == paNoError )
1604
/* XXX: Should we not allow the implementation to signal any overflow condition? */
1607
else if( buffer == 0 )
1609
result = paBadBufferPtr;
1613
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1616
result = PA_STREAM_INTERFACE(stream)->Read( stream, buffer, frames );
1618
else if( result == 1 )
1620
result = paStreamIsStopped;
1625
PA_LOGAPI_EXIT_PAERROR( "Pa_ReadStream", result );
1631
PaError Pa_WriteStream( PaStream* stream,
1633
unsigned long frames )
1635
PaError result = PaUtil_ValidateStreamPointer( stream );
1637
PA_LOGAPI_ENTER_PARAMS( "Pa_WriteStream" );
1638
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1640
if( result == paNoError )
1644
/* XXX: Should we not allow the implementation to signal any underflow condition? */
1647
else if( buffer == 0 )
1649
result = paBadBufferPtr;
1653
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1656
result = PA_STREAM_INTERFACE(stream)->Write( stream, buffer, frames );
1658
else if( result == 1 )
1660
result = paStreamIsStopped;
1665
PA_LOGAPI_EXIT_PAERROR( "Pa_WriteStream", result );
1670
signed long Pa_GetStreamReadAvailable( PaStream* stream )
1672
PaError error = PaUtil_ValidateStreamPointer( stream );
1675
PA_LOGAPI_ENTER_PARAMS( "Pa_GetStreamReadAvailable" );
1676
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1678
if( error != paNoError )
1682
PA_LOGAPI(("Pa_GetStreamReadAvailable returned:\n" ));
1683
PA_LOGAPI(("\tunsigned long: 0 [ PaError error: %d ( %s ) ]\n", error, Pa_GetErrorText( error ) ));
1688
result = PA_STREAM_INTERFACE(stream)->GetReadAvailable( stream );
1690
PA_LOGAPI(("Pa_GetStreamReadAvailable returned:\n" ));
1691
PA_LOGAPI(("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) ));
1699
signed long Pa_GetStreamWriteAvailable( PaStream* stream )
1701
PaError error = PaUtil_ValidateStreamPointer( stream );
1704
PA_LOGAPI_ENTER_PARAMS( "Pa_GetStreamWriteAvailable" );
1705
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
1707
if( error != paNoError )
1711
PA_LOGAPI(("Pa_GetStreamWriteAvailable returned:\n" ));
1712
PA_LOGAPI(("\tunsigned long: 0 [ PaError error: %d ( %s ) ]\n", error, Pa_GetErrorText( error ) ));
1717
result = PA_STREAM_INTERFACE(stream)->GetWriteAvailable( stream );
1719
PA_LOGAPI(("Pa_GetStreamWriteAvailable returned:\n" ));
1720
PA_LOGAPI(("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) ));
1728
PaError Pa_GetSampleSize( PaSampleFormat format )
1732
PA_LOGAPI_ENTER_PARAMS( "Pa_GetSampleSize" );
1733
PA_LOGAPI(("\tPaSampleFormat format: %d\n", format ));
1735
switch( format & ~paNonInterleaved )
1757
result = paSampleFormatNotSupported;
1761
PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT( "Pa_GetSampleSize", "int: %d", result );
1763
return (PaError) result;