📄 pa_front.c
字号:
PaError PaUtil_GetHostApiRepresentation( struct PaUtilHostApiRepresentation **hostApi, PaHostApiTypeId type ){ 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 ) { *hostApi = hostApis_[i]; result = paNoError; break; } } } return result;}PaError PaUtil_DeviceIndexToHostApiDeviceIndex( PaDeviceIndex *hostApiDevice, PaDeviceIndex device, struct PaUtilHostApiRepresentation *hostApi ){ PaError result; PaDeviceIndex x; x = device - hostApi->privatePaFrontInfo.baseDeviceIndex; if( x < 0 || x >= hostApi->info.deviceCount ) { result = paInvalidDevice; } else { *hostApiDevice = x; result = paNoError; } return result;}PaHostApiIndex Pa_GetHostApiCount( void ){ int result;#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetHostApiCount called.\n" );#endif if( !PA_IS_INITIALISED_ ) { result = paNotInitialized; } else { result = hostApisCount_; }#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetHostApiCount returned:\n" ); if( result < 0 ) PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) ); else PaUtil_DebugPrint("\tPaHostApiIndex %d\n\n", result );#endif return result;}PaHostApiIndex Pa_GetDefaultHostApi( void ){ int result;#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetDefaultHostApi called.\n" );#endif if( !PA_IS_INITIALISED_ ) { result = paNotInitialized; } else { result = paDefaultHostApiIndex; /* internal consistency check: make sure that the default host api index is within range */ if( result < 0 || result >= hostApisCount_ ) { result = paInternalError; } }#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetDefaultHostApi returned:\n" ); if( result < 0 ) PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) ); else PaUtil_DebugPrint("\tPaHostApiIndex %d\n\n", result );#endif return result;}const PaHostApiInfo* Pa_GetHostApiInfo( PaHostApiIndex hostApi ){ PaHostApiInfo *info;#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetHostApiInfo called:\n" ); PaUtil_DebugPrint("\tPaHostApiIndex hostApi: %d\n", hostApi );#endif if( !PA_IS_INITIALISED_ ) { info = NULL;#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetHostApiInfo returned:\n" ); PaUtil_DebugPrint("\tPaHostApiInfo*: NULL [ PortAudio not initialized ]\n\n" );#endif } else if( hostApi < 0 || hostApi >= hostApisCount_ ) { info = NULL; #ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetHostApiInfo returned:\n" ); PaUtil_DebugPrint("\tPaHostApiInfo*: NULL [ hostApi out of range ]\n\n" );#endif } else { info = &hostApis_[hostApi]->info;#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetHostApiInfo returned:\n" ); PaUtil_DebugPrint("\tPaHostApiInfo*: 0x%p\n", info ); PaUtil_DebugPrint("\t{" ); PaUtil_DebugPrint("\t\tint structVersion: %d\n", info->structVersion ); PaUtil_DebugPrint("\t\tPaHostApiTypeId type: %d\n", info->type ); PaUtil_DebugPrint("\t\tconst char *name: %s\n\n", info->name ); PaUtil_DebugPrint("\t}\n\n" );#endif } return info;}PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi, int hostApiDeviceIndex ){ PaDeviceIndex result;#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_HostApiDeviceIndexToPaDeviceIndex called:\n" ); PaUtil_DebugPrint("\tPaHostApiIndex hostApi: %d\n", hostApi ); PaUtil_DebugPrint("\tint hostApiDeviceIndex: %d\n", hostApiDeviceIndex );#endif if( !PA_IS_INITIALISED_ ) { result = paNotInitialized; } else { if( hostApi < 0 || hostApi >= hostApisCount_ ) { result = paInvalidHostApi; } else { if( hostApiDeviceIndex < 0 || hostApiDeviceIndex >= hostApis_[hostApi]->info.deviceCount ) { result = paInvalidDevice; } else { result = hostApis_[hostApi]->privatePaFrontInfo.baseDeviceIndex + hostApiDeviceIndex; } } }#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_HostApiDeviceIndexToPaDeviceIndex returned:\n" ); if( result < 0 ) PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) ); else PaUtil_DebugPrint("\tPaDeviceIndex: %d\n\n", result );#endif return result;}PaDeviceIndex Pa_GetDeviceCount( void ){ PaDeviceIndex result;#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetDeviceCount called.\n" );#endif if( !PA_IS_INITIALISED_ ) { result = paNotInitialized; } else { result = deviceCount_; }#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetDeviceCount returned:\n" ); if( result < 0 ) PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) ); else PaUtil_DebugPrint("\tPaDeviceIndex: %d\n\n", result );#endif return result;}PaDeviceIndex Pa_GetDefaultInputDevice( void ){ PaHostApiIndex hostApi; PaDeviceIndex result;#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetDefaultInputDevice called.\n" );#endif hostApi = Pa_GetDefaultHostApi(); if( hostApi < 0 ) { result = paNoDevice; } else { result = hostApis_[hostApi]->info.defaultInputDevice; }#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetDefaultInputDevice returned:\n" ); PaUtil_DebugPrint("\tPaDeviceIndex: %d\n\n", result );#endif return result;}PaDeviceIndex Pa_GetDefaultOutputDevice( void ){ PaHostApiIndex hostApi; PaDeviceIndex result; #ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetDefaultOutputDevice called.\n" );#endif hostApi = Pa_GetDefaultHostApi(); if( hostApi < 0 ) { result = paNoDevice; } else { result = hostApis_[hostApi]->info.defaultOutputDevice; }#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetDefaultOutputDevice returned:\n" ); PaUtil_DebugPrint("\tPaDeviceIndex: %d\n\n", result );#endif return result;}const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device ){ int hostSpecificDeviceIndex; int hostApiIndex = FindHostApi( device, &hostSpecificDeviceIndex ); PaDeviceInfo *result;#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetDeviceInfo called:\n" ); PaUtil_DebugPrint("\tPaDeviceIndex device: %d\n", device );#endif if( hostApiIndex < 0 ) { result = NULL;#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetDeviceInfo returned:\n" ); PaUtil_DebugPrint("\tPaDeviceInfo* NULL [ invalid device index ]\n\n" );#endif } else { result = hostApis_[hostApiIndex]->deviceInfos[ hostSpecificDeviceIndex ];#ifdef PA_LOG_API_CALLS PaUtil_DebugPrint("Pa_GetDeviceInfo returned:\n" ); PaUtil_DebugPrint("\tPaDeviceInfo*: 0x%p:\n", result ); PaUtil_DebugPrint("\t{\n" ); PaUtil_DebugPrint("\t\tint structVersion: %d\n", result->structVersion ); PaUtil_DebugPrint("\t\tconst char *name: %s\n", result->name ); PaUtil_DebugPrint("\t\tPaHostApiIndex hostApi: %d\n", result->hostApi ); PaUtil_DebugPrint("\t\tint maxInputChannels: %d\n", result->maxInputChannels ); PaUtil_DebugPrint("\t\tint maxOutputChannels: %d\n", result->maxOutputChannels ); PaUtil_DebugPrint("\t}\n\n" );#endif } return result;}/* SampleFormatIsValid() returns 1 if sampleFormat is a sample format defined in portaudio.h, or 0 otherwise.*/static int SampleFormatIsValid( PaSampleFormat format ){ switch( format & ~paNonInterleaved ) { case paFloat32: return 1; case paInt16: return 1; case paInt32: return 1; case paInt24: return 1; case paInt8: return 1; case paUInt8: return 1; case paCustomFormat: return 1; default: return 0; }}/* NOTE: make sure this validation list is kept syncronised with the one in pa_hostapi.h 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. Validation that would require knowledge of device capabilities is not performed because of potentially complex relationships between 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 inputParameters->hostApiSpecificStreamInfo is non-NULL and refers to a valid host api 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 200000.) - 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 variable buffer size (paFramesPerBufferUnspecified)*/static PaError ValidateOpenStreamParameters( const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, PaUtilHostApiRepresentation **hostApi, PaDeviceIndex *hostApiInputDevice, PaDeviceIndex *hostApiOutputDevice ){ int inputHostApiIndex = -1, /* Surpress uninitialised var warnings: compiler does */ outputHostApiIndex = -1; /* not see that if inputParameters and outputParame- */ /* ters are both nonzero, these indices are set. */ if( (inputParameters == NULL) && (outputParameters == NULL) ) { return paInvalidDevice; /** @todo should be a new error code "invalid device parameters" or something */ } else { if( inputParameters == NULL ) { *hostApiInputDevice = paNoDevice; } else if( inputParameters->device == paUseHostApiSpecificDeviceSpecification ) { if( inputParameters->hostApiSpecificStreamInfo ) { inputHostApiIndex = Pa_HostApiTypeIdToHostApiIndex( ((PaUtilHostApiSpecificStreamInfoHeader*)inputParameters->hostApiSpecificStreamInfo)->hostApiType ); if( inputHostApiIndex != -1 ) { *hostApiInputDevice = paUseHostApiSpecificDeviceSpecification; *hostApi = hostApis_[inputHostApiIndex]; } else { return paInvalidDevice; } } else { return paInvalidDevice; } } else { if( inputParameters->device < 0 || inputParameters->device >= deviceCount_ ) return paInvalidDevice; inputHostApiIndex = FindHostApi( inputParameters->device, hostApiInputDevice ); if( inputHostApiIndex < 0 ) return paInternalError; *hostApi = hostApis_[inputHostApiIndex]; if( inputParameters->channelCount <= 0 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -