⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pa_front.c

📁 一个开源的sip源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
                return paInvalidChannelCount;            if( !SampleFormatIsValid( inputParameters->sampleFormat ) )                return paSampleFormatNotSupported;            if( inputParameters->hostApiSpecificStreamInfo != NULL )            {                if( ((PaUtilHostApiSpecificStreamInfoHeader*)inputParameters->hostApiSpecificStreamInfo)->hostApiType                        != (*hostApi)->info.type )                    return paIncompatibleHostApiSpecificStreamInfo;            }        }        if( outputParameters == NULL )        {            *hostApiOutputDevice = paNoDevice;        }        else if( outputParameters->device == paUseHostApiSpecificDeviceSpecification  )        {            if( outputParameters->hostApiSpecificStreamInfo )            {                outputHostApiIndex = Pa_HostApiTypeIdToHostApiIndex(                        ((PaUtilHostApiSpecificStreamInfoHeader*)outputParameters->hostApiSpecificStreamInfo)->hostApiType );                if( outputHostApiIndex != -1 )                {                    *hostApiOutputDevice = paUseHostApiSpecificDeviceSpecification;                    *hostApi = hostApis_[outputHostApiIndex];                }                else                {                    return paInvalidDevice;                }            }            else            {                return paInvalidDevice;            }        }        else        {            if( outputParameters->device < 0 || outputParameters->device >= deviceCount_ )                return paInvalidDevice;            outputHostApiIndex = FindHostApi( outputParameters->device, hostApiOutputDevice );            if( outputHostApiIndex < 0 )                return paInternalError;            *hostApi = hostApis_[outputHostApiIndex];            if( outputParameters->channelCount <= 0 )                return paInvalidChannelCount;            if( !SampleFormatIsValid( outputParameters->sampleFormat ) )                return paSampleFormatNotSupported;            if( outputParameters->hostApiSpecificStreamInfo != NULL )            {                if( ((PaUtilHostApiSpecificStreamInfoHeader*)outputParameters->hostApiSpecificStreamInfo)->hostApiType                        != (*hostApi)->info.type )                    return paIncompatibleHostApiSpecificStreamInfo;            }        }           if( (inputParameters != NULL) && (outputParameters != NULL) )        {            /* ensure that both devices use the same API */            if( inputHostApiIndex != outputHostApiIndex )                return paBadIODeviceCombination;        }    }            /* Check for absurd sample rates. */    if( (sampleRate < 1000.0) || (sampleRate > 200000.0) )        return paInvalidSampleRate;    if( ((streamFlags & ~paPlatformSpecificFlags) & ~(paClipOff | paDitherOff | paNeverDropInput | paPrimeOutputBuffersUsingStreamCallback ) ) != 0 )        return paInvalidFlag;    if( streamFlags & paNeverDropInput )    {        /* must be a callback stream */        if( !streamCallback )             return paInvalidFlag;        /* must be a full duplex stream */        if( (inputParameters == NULL) || (outputParameters == NULL) )            return paInvalidFlag;        /* must use paFramesPerBufferUnspecified */        if( framesPerBuffer != paFramesPerBufferUnspecified )            return paInvalidFlag;    }        return paNoError;}PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters,                              const PaStreamParameters *outputParameters,                              double sampleRate ){    PaError result;    PaUtilHostApiRepresentation *hostApi = 0;    PaDeviceIndex hostApiInputDevice = paNoDevice, hostApiOutputDevice = paNoDevice;    PaStreamParameters hostApiInputParameters, hostApiOutputParameters;    PaStreamParameters *hostApiInputParametersPtr, *hostApiOutputParametersPtr;#ifdef PA_LOG_API_CALLS    PaUtil_DebugPrint("Pa_IsFormatSupported called:\n" );    if( inputParameters == NULL ){        PaUtil_DebugPrint("\tPaStreamParameters *inputParameters: NULL\n" );    }else{        PaUtil_DebugPrint("\tPaStreamParameters *inputParameters: 0x%p\n", inputParameters );        PaUtil_DebugPrint("\tPaDeviceIndex inputParameters->device: %d\n", inputParameters->device );        PaUtil_DebugPrint("\tint inputParameters->channelCount: %d\n", inputParameters->channelCount );        PaUtil_DebugPrint("\tPaSampleFormat inputParameters->sampleFormat: %d\n", inputParameters->sampleFormat );        PaUtil_DebugPrint("\tPaTime inputParameters->suggestedLatency: %f\n", inputParameters->suggestedLatency );        PaUtil_DebugPrint("\tvoid *inputParameters->hostApiSpecificStreamInfo: 0x%p\n", inputParameters->hostApiSpecificStreamInfo );    }    if( outputParameters == NULL ){        PaUtil_DebugPrint("\tPaStreamParameters *outputParameters: NULL\n" );    }else{        PaUtil_DebugPrint("\tPaStreamParameters *outputParameters: 0x%p\n", outputParameters );        PaUtil_DebugPrint("\tPaDeviceIndex outputParameters->device: %d\n", outputParameters->device );        PaUtil_DebugPrint("\tint outputParameters->channelCount: %d\n", outputParameters->channelCount );        PaUtil_DebugPrint("\tPaSampleFormat outputParameters->sampleFormat: %d\n", outputParameters->sampleFormat );        PaUtil_DebugPrint("\tPaTime outputParameters->suggestedLatency: %f\n", outputParameters->suggestedLatency );        PaUtil_DebugPrint("\tvoid *outputParameters->hostApiSpecificStreamInfo: 0x%p\n", outputParameters->hostApiSpecificStreamInfo );    }        PaUtil_DebugPrint("\tdouble sampleRate: %g\n", sampleRate );#endif    if( !PA_IS_INITIALISED_ )    {        result = paNotInitialized;#ifdef PA_LOG_API_CALLS        PaUtil_DebugPrint("Pa_IsFormatSupported returned:\n" );        PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) );#endif        return result;    }    result = ValidateOpenStreamParameters( inputParameters,                                           outputParameters,                                           sampleRate, 0, paNoFlag, 0,                                           &hostApi,                                           &hostApiInputDevice,                                           &hostApiOutputDevice );    if( result != paNoError )    {#ifdef PA_LOG_API_CALLS        PaUtil_DebugPrint("Pa_IsFormatSupported returned:\n" );        PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) );#endif        return result;    }        if( inputParameters )    {        hostApiInputParameters.device = hostApiInputDevice;        hostApiInputParameters.channelCount = inputParameters->channelCount;        hostApiInputParameters.sampleFormat = inputParameters->sampleFormat;        hostApiInputParameters.suggestedLatency = inputParameters->suggestedLatency;        hostApiInputParameters.hostApiSpecificStreamInfo = inputParameters->hostApiSpecificStreamInfo;        hostApiInputParametersPtr = &hostApiInputParameters;    }    else    {        hostApiInputParametersPtr = NULL;    }    if( outputParameters )    {        hostApiOutputParameters.device = hostApiOutputDevice;        hostApiOutputParameters.channelCount = outputParameters->channelCount;        hostApiOutputParameters.sampleFormat = outputParameters->sampleFormat;        hostApiOutputParameters.suggestedLatency = outputParameters->suggestedLatency;        hostApiOutputParameters.hostApiSpecificStreamInfo = outputParameters->hostApiSpecificStreamInfo;        hostApiOutputParametersPtr = &hostApiOutputParameters;    }    else    {        hostApiOutputParametersPtr = NULL;    }    result = hostApi->IsFormatSupported( hostApi,                                  hostApiInputParametersPtr, hostApiOutputParametersPtr,                                  sampleRate );#ifdef PA_LOG_API_CALLS    PaUtil_DebugPrint("Pa_OpenStream returned:\n" );    if( result == paFormatIsSupported )        PaUtil_DebugPrint("\tPaError: 0 [ paFormatIsSupported ]\n\n" );    else        PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) );#endif    return result;}PaError Pa_OpenStream( PaStream** stream,                       const PaStreamParameters *inputParameters,                       const PaStreamParameters *outputParameters,                       double sampleRate,                       unsigned long framesPerBuffer,                       PaStreamFlags streamFlags,                       PaStreamCallback *streamCallback,                       void *userData ){    PaError result;    PaUtilHostApiRepresentation *hostApi = 0;    PaDeviceIndex hostApiInputDevice = paNoDevice, hostApiOutputDevice = paNoDevice;    PaStreamParameters hostApiInputParameters, hostApiOutputParameters;    PaStreamParameters *hostApiInputParametersPtr, *hostApiOutputParametersPtr;#ifdef PA_LOG_API_CALLS    PaUtil_DebugPrint("Pa_OpenStream called:\n" );    PaUtil_DebugPrint("\tPaStream** stream: 0x%p\n", stream );    if( inputParameters == NULL ){        PaUtil_DebugPrint("\tPaStreamParameters *inputParameters: NULL\n" );    }else{        PaUtil_DebugPrint("\tPaStreamParameters *inputParameters: 0x%p\n", inputParameters );        PaUtil_DebugPrint("\tPaDeviceIndex inputParameters->device: %d\n", inputParameters->device );        PaUtil_DebugPrint("\tint inputParameters->channelCount: %d\n", inputParameters->channelCount );        PaUtil_DebugPrint("\tPaSampleFormat inputParameters->sampleFormat: %d\n", inputParameters->sampleFormat );        PaUtil_DebugPrint("\tPaTime inputParameters->suggestedLatency: %f\n", inputParameters->suggestedLatency );        PaUtil_DebugPrint("\tvoid *inputParameters->hostApiSpecificStreamInfo: 0x%p\n", inputParameters->hostApiSpecificStreamInfo );    }    if( outputParameters == NULL ){        PaUtil_DebugPrint("\tPaStreamParameters *outputParameters: NULL\n" );    }else{        PaUtil_DebugPrint("\tPaStreamParameters *outputParameters: 0x%p\n", outputParameters );        PaUtil_DebugPrint("\tPaDeviceIndex outputParameters->device: %d\n", outputParameters->device );        PaUtil_DebugPrint("\tint outputParameters->channelCount: %d\n", outputParameters->channelCount );        PaUtil_DebugPrint("\tPaSampleFormat outputParameters->sampleFormat: %d\n", outputParameters->sampleFormat );        PaUtil_DebugPrint("\tPaTime outputParameters->suggestedLatency: %f\n", outputParameters->suggestedLatency );        PaUtil_DebugPrint("\tvoid *outputParameters->hostApiSpecificStreamInfo: 0x%p\n", outputParameters->hostApiSpecificStreamInfo );    }        PaUtil_DebugPrint("\tdouble sampleRate: %g\n", sampleRate );    PaUtil_DebugPrint("\tunsigned long framesPerBuffer: %d\n", framesPerBuffer );    PaUtil_DebugPrint("\tPaStreamFlags streamFlags: 0x%x\n", streamFlags );    PaUtil_DebugPrint("\tPaStreamCallback *streamCallback: 0x%p\n", streamCallback );    PaUtil_DebugPrint("\tvoid *userData: 0x%p\n", userData );#endif    if( !PA_IS_INITIALISED_ )    {        result = paNotInitialized;#ifdef PA_LOG_API_CALLS        PaUtil_DebugPrint("Pa_OpenStream returned:\n" );        PaUtil_DebugPrint("\t*(PaStream** stream): undefined\n" );        PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) );#endif        return result;    }    /* Check for parameter errors.        NOTE: make sure this validation list is kept syncronised with the one        in pa_hostapi.h    */    if( stream == NULL )    {        result = paBadStreamPtr;#ifdef PA_LOG_API_CALLS        PaUtil_DebugPrint("Pa_OpenStream returned:\n" );        PaUtil_DebugPrint("\t*(PaStream** stream): undefined\n" );        PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) );#endif        return result;    }    result = ValidateOpenStreamParameters( inputParameters,                                           outputParameters,                                           sampleRate, framesPerBuffer,                                           streamFlags, streamCallback,                                           &hostApi,                                           &hostApiInputDevice,                                           &hostApiOutputDevice );    if( result != paNoError )    {#ifdef PA_LOG_API_CALLS        PaUtil_DebugPrint("Pa_OpenStream returned:\n" );        PaUtil_DebugPrint("\t*(PaStream** stream): undefined\n" );        PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) );#endif        return result;    }        if( inputParameters )    {        hostApiInputParameters.device = hostApiInputDevice;        hostApiInputParameters.channelCount = inputParameters->channelCount;        hostApiInputParameters.sampleFormat = inputParameters->sampleFormat;        hostApiInputParameters.suggestedLatency = inputParameters->suggestedLatency;        hostApiInputParameters.hostApiSpecificStreamInfo = inputParameters->hostApiSpecificStreamInfo;        hostApiInputParametersPtr = &hostApiInputParameters;    }    else    {        hostApiInputParametersPtr = NULL;    }    if( outputParameters )    {        hostApiOutputParameters.device = hostApiOutputDevice;        hostApiOutputParameters.channelCount = outputParameters->channelCount;        hostApiOutputParameters.sampleFormat = outputParameters->sampleFormat;        hostApiOutputParameters.suggestedLatency = outputParameters->suggestedLatency;        hostApiOutputParameters.hostApiSpecificStreamInfo = outputParameters->hostApiSpecificStreamInfo;        hostApiOutputParametersPtr = &hostApiOutputParameters;    }    else    {        hostApiOutputParametersPtr = NULL;    }    result = hostApi->OpenStream( hostApi, stream,                                  hostApiInputParametersPtr, hostApiOutputParametersPtr,                                  sampleRate, framesPerBuffer, streamFlags, streamCallback, userData );    if( result == paNoError )        AddOpenStream( *stream );#ifdef PA_LOG_API_CALLS    PaUtil_DebugPrint("Pa_OpenStream returned:\n" );    PaUtil_DebugPrint("\t*(PaStream** stream): 0x%p\n", *stream );    PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) );#endif    return result;}PaError Pa_OpenDefaultStream( PaStream** stream,                              int inputChannelCount,                              int outputChannelCount,                              PaSampleFormat sampleFormat,                              double sampleRate,                              unsigned long framesPerBuffer,                              PaStreamCallback *streamCallback,                              void *userData ){    PaError result;    PaStreamParameters hostApiInputParameters, hostApiOutputParameters;    PaStreamParameters *hostApiInputParametersPtr, *hostApiOutputParametersPtr;#ifdef PA_LOG_API_CALLS    PaUtil_DebugPrint("Pa_OpenDefaultStream called:\n" );    PaUtil_DebugPrint("\tPaStream** stream: 0x%p\n", stream );    PaUtil_DebugPrint("\tint inputChannelCount: %d\n", inputChannelCount );    PaUtil_DebugPrint("\tint outputChannelCount: %d\n", outputChannelCount );    PaUtil_DebugPrint("\tPaSampleFormat sampleFormat: %d\n", sampleFormat );    PaUtil_DebugPrint("\tdouble sampleRate: %g\n", sampleRate );    PaUtil_DebugPrint("\tunsigned long framesPerBuffer: %d\n", framesPerBuffer );    PaUtil_DebugPrint("\tPaStreamCallback *streamCallback: 0x%p\n", streamCallback );    PaUtil_DebugPrint("\tvoid *userData: 0x%p\n", userData );#endif    if( inputChannelCount > 0 )    {        hostApiInputParameters.device = Pa_GetDefaultInputDevice();		if( hostApiInputParameters.device == paNoDevice )			return paDeviceUnavailable; 	        hostApiInputParameters.channelCount = inputChannelCount;        hostApiInputParameters.sampleFormat = sampleFormat;        /* defaultHighInputLatency is used below instead of           defaultLowInputLatency because it is more important for the default           stream to work reliably than it is for it to work with the lowest           latency.         */        hostApiInputParameters.suggestedLatency =              Pa_GetDeviceInfo( hostApiInputParameters.device )->defaultHighInputLatency;        hostApiInputParameters.hostApiSpecificStreamInfo = NULL;        hostApiInputParametersPtr = &hostApiInputParameters;    }    else    {        hostApiInputParametersPtr = NULL;    }    if( outputChannelCount > 0 )    {        hostApiOutputParameters.device = Pa_GetDefaultOutputDevice();		if( hostApiOutputParameters.device == paNoDevice )			return paDeviceUnavailable;         hostApiOutputParameters.channelCount = outputChannelCount;        hostApiOutputParameters.sampleFormat = sampleFormat;        /* defaultHighOutputLatency is used below instead of           defaultLowOutputLatency because it is more important for the default           stream to work reliably than it is for it to work with the lowest           latency.         */        hostApiOutputParameters.suggestedLatency =             Pa_GetDeviceInfo( hostApiOutputParameters.device )->defaultHighOutputLatency;        hostApiOutputParameters.hostApiSpecificStreamInfo = NULL;        hostApiOutputParametersPtr = &hostApiOutputParameters;    }    else    {        hostApiOutputParametersPtr = NULL;    }    result = Pa_OpenStream(                 stream, hostApiInputParametersPtr, hostApiOutputParametersPtr,                 sampleRate, framesPerBuffer, paNoFlag, streamCallback, userData );#ifdef PA_LOG_API_CALLS    PaUtil_DebugPrint("Pa_OpenDefaultStream returned:\n" );    PaUtil_DebugPrint("\t*(PaStream** stream): 0x%p", *stream );    PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) );#endif    return result;}PaError PaUtil_ValidateStreamPointer( PaStream* stream ){    if( !PA_IS_INITIALISED_ ) return paNotInitialized;    if( stream == NULL ) return paBadStreamPtr;    if( ((PaUtilStreamRepresentation*)stream)->magic != PA_STREAM_MAGIC )        return paBadStreamPtr;    return paNoError;}PaError Pa_CloseStream( PaStream* stream ){    PaUtilStreamInterface *interface;    PaError result = PaUtil_ValidateStreamPointer( stream );#ifdef PA_LOG_API_CALLS    PaUtil_DebugPrint("Pa_CloseStream called:\n" );    PaUtil_DebugPrint("\tPaStream* stream: 0x%p\n", stream );#endif    /* always remove the open stream from our list, even if this function        eventually returns an error. Otherwise CloseOpenStreams() will        get stuck in an infinite loop */    RemoveOpenStream( stream ); /* be sure to call this _before_ closing the stream */    if( result == paNoError )    {        interface = PA_STREAM_INTERFACE(stream);        /* abort the stream if it isn't stopped */        result = interface->IsStopped( stream );        if( result == 1 )            result = paNoError;        else if( result == 0 )            result = interface->Abort( stream );        if( result == paNoError )                 /** @todo REVIEW: shouldn't we close anyway? */            result = interface->Close( stream );    }#ifdef PA_LOG_API_CALLS    PaUtil_DebugPrint("Pa_CloseStream returned:\n" );    PaUtil_DebugPrint("\tPaError: %d ( %s )\n\n", result, Pa_GetErrorText( result ) );#endif    return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -