pa_process.c

来自「基于sip协议的网络电话源码」· C语言 代码 · 共 1,757 行 · 第 1/5 页

C
1,757
字号
    PaUtil_InitializeTriangularDitherState( &bp->ditherGenerator );    bp->samplePeriod = 1. / sampleRate;    bp->streamCallback = streamCallback;    bp->userData = userData;    return result;error:    if( bp->tempInputBuffer )        PaUtil_FreeMemory( bp->tempInputBuffer );    if( bp->tempInputBufferPtrs )        PaUtil_FreeMemory( bp->tempInputBufferPtrs );    if( bp->hostInputChannels[0] )        PaUtil_FreeMemory( bp->hostInputChannels[0] );    if( bp->tempOutputBuffer )        PaUtil_FreeMemory( bp->tempOutputBuffer );    if( bp->tempOutputBufferPtrs )        PaUtil_FreeMemory( bp->tempOutputBufferPtrs );    if( bp->hostOutputChannels[0] )        PaUtil_FreeMemory( bp->hostOutputChannels[0] );    return result;}void PaUtil_TerminateBufferProcessor( PaUtilBufferProcessor* bp ){    if( bp->tempInputBuffer )        PaUtil_FreeMemory( bp->tempInputBuffer );    if( bp->tempInputBufferPtrs )        PaUtil_FreeMemory( bp->tempInputBufferPtrs );    if( bp->hostInputChannels[0] )        PaUtil_FreeMemory( bp->hostInputChannels[0] );            if( bp->tempOutputBuffer )        PaUtil_FreeMemory( bp->tempOutputBuffer );    if( bp->tempOutputBufferPtrs )        PaUtil_FreeMemory( bp->tempOutputBufferPtrs );    if( bp->hostOutputChannels[0] )        PaUtil_FreeMemory( bp->hostOutputChannels[0] );}void PaUtil_ResetBufferProcessor( PaUtilBufferProcessor* bp ){    unsigned long tempInputBufferSize, tempOutputBufferSize;    bp->framesInTempInputBuffer = bp->initialFramesInTempInputBuffer;    bp->framesInTempOutputBuffer = bp->initialFramesInTempOutputBuffer;    if( bp->framesInTempInputBuffer > 0 )    {        tempInputBufferSize =            bp->framesPerTempBuffer * bp->bytesPerUserInputSample * bp->inputChannelCount;        memset( bp->tempInputBuffer, 0, tempInputBufferSize );    }    if( bp->framesInTempOutputBuffer > 0 )    {              tempOutputBufferSize =            bp->framesPerTempBuffer * bp->bytesPerUserOutputSample * bp->outputChannelCount;        memset( bp->tempOutputBuffer, 0, tempOutputBufferSize );    }}unsigned long PaUtil_GetBufferProcessorInputLatency( PaUtilBufferProcessor* bp ){    return bp->initialFramesInTempInputBuffer;}unsigned long PaUtil_GetBufferProcessorOutputLatency( PaUtilBufferProcessor* bp ){    return bp->initialFramesInTempOutputBuffer;}void PaUtil_SetInputFrameCount( PaUtilBufferProcessor* bp,        unsigned long frameCount ){    if( frameCount == 0 )        bp->hostInputFrameCount[0] = bp->framesPerHostBuffer;    else        bp->hostInputFrameCount[0] = frameCount;}        void PaUtil_SetNoInput( PaUtilBufferProcessor* bp ){    assert( bp->inputChannelCount > 0 );    bp->hostInputChannels[0][0].data = 0;}void PaUtil_SetInputChannel( PaUtilBufferProcessor* bp,        unsigned int channel, void *data, unsigned int stride ){    assert( channel < bp->inputChannelCount );        bp->hostInputChannels[0][channel].data = data;    bp->hostInputChannels[0][channel].stride = stride;}void PaUtil_SetInterleavedInputChannels( PaUtilBufferProcessor* bp,        unsigned int firstChannel, void *data, unsigned int channelCount ){    unsigned int i;    unsigned int channel = firstChannel;    unsigned char *p = (unsigned char*)data;    if( channelCount == 0 )        channelCount = bp->inputChannelCount;    assert( firstChannel < bp->inputChannelCount );    assert( firstChannel + channelCount <= bp->inputChannelCount );    for( i=0; i< channelCount; ++i )    {        bp->hostInputChannels[0][channel+i].data = p;        p += bp->bytesPerHostInputSample;        bp->hostInputChannels[0][channel+i].stride = channelCount;    }}void PaUtil_SetNonInterleavedInputChannel( PaUtilBufferProcessor* bp,        unsigned int channel, void *data ){    assert( channel < bp->inputChannelCount );        bp->hostInputChannels[0][channel].data = data;    bp->hostInputChannels[0][channel].stride = 1;}void PaUtil_Set2ndInputFrameCount( PaUtilBufferProcessor* bp,        unsigned long frameCount ){    bp->hostInputFrameCount[1] = frameCount;}void PaUtil_Set2ndInputChannel( PaUtilBufferProcessor* bp,        unsigned int channel, void *data, unsigned int stride ){    assert( channel < bp->inputChannelCount );    bp->hostInputChannels[1][channel].data = data;    bp->hostInputChannels[1][channel].stride = stride;}void PaUtil_Set2ndInterleavedInputChannels( PaUtilBufferProcessor* bp,        unsigned int firstChannel, void *data, unsigned int channelCount ){    unsigned int i;    unsigned int channel = firstChannel;    unsigned char *p = (unsigned char*)data;    if( channelCount == 0 )        channelCount = bp->inputChannelCount;    assert( firstChannel < bp->inputChannelCount );    assert( firstChannel + channelCount <= bp->inputChannelCount );        for( i=0; i< channelCount; ++i )    {        bp->hostInputChannels[1][channel+i].data = p;        p += bp->bytesPerHostInputSample;        bp->hostInputChannels[1][channel+i].stride = channelCount;    }}        void PaUtil_Set2ndNonInterleavedInputChannel( PaUtilBufferProcessor* bp,        unsigned int channel, void *data ){    assert( channel < bp->inputChannelCount );        bp->hostInputChannels[1][channel].data = data;    bp->hostInputChannels[1][channel].stride = 1;}void PaUtil_SetOutputFrameCount( PaUtilBufferProcessor* bp,        unsigned long frameCount ){    if( frameCount == 0 )        bp->hostOutputFrameCount[0] = bp->framesPerHostBuffer;    else        bp->hostOutputFrameCount[0] = frameCount;}void PaUtil_SetNoOutput( PaUtilBufferProcessor* bp ){    assert( bp->outputChannelCount > 0 );    bp->hostOutputChannels[0][0].data = 0;}void PaUtil_SetOutputChannel( PaUtilBufferProcessor* bp,        unsigned int channel, void *data, unsigned int stride ){    assert( channel < bp->outputChannelCount );        bp->hostOutputChannels[0][channel].data = data;    bp->hostOutputChannels[0][channel].stride = stride;}void PaUtil_SetInterleavedOutputChannels( PaUtilBufferProcessor* bp,        unsigned int firstChannel, void *data, unsigned int channelCount ){    unsigned int i;    unsigned int channel = firstChannel;    unsigned char *p = (unsigned char*)data;    if( channelCount == 0 )        channelCount = bp->outputChannelCount;    assert( firstChannel < bp->outputChannelCount );    assert( firstChannel + channelCount <= bp->outputChannelCount );        for( i=0; i< channelCount; ++i )    {        bp->hostOutputChannels[0][channel+i].data = p;        p += bp->bytesPerHostOutputSample;        bp->hostOutputChannels[0][channel+i].stride = channelCount;    }}void PaUtil_SetNonInterleavedOutputChannel( PaUtilBufferProcessor* bp,        unsigned int channel, void *data ){    assert( channel < bp->outputChannelCount );    bp->hostOutputChannels[0][channel].data = data;    bp->hostOutputChannels[0][channel].stride = 1;}void PaUtil_Set2ndOutputFrameCount( PaUtilBufferProcessor* bp,        unsigned long frameCount ){    bp->hostOutputFrameCount[1] = frameCount;}void PaUtil_Set2ndOutputChannel( PaUtilBufferProcessor* bp,        unsigned int channel, void *data, unsigned int stride ){    assert( channel < bp->outputChannelCount );    bp->hostOutputChannels[1][channel].data = data;    bp->hostOutputChannels[1][channel].stride = stride;}void PaUtil_Set2ndInterleavedOutputChannels( PaUtilBufferProcessor* bp,        unsigned int firstChannel, void *data, unsigned int channelCount ){    unsigned int i;    unsigned int channel = firstChannel;    unsigned char *p = (unsigned char*)data;    if( channelCount == 0 )        channelCount = bp->outputChannelCount;    assert( firstChannel < bp->outputChannelCount );    assert( firstChannel + channelCount <= bp->outputChannelCount );        for( i=0; i< channelCount; ++i )    {        bp->hostOutputChannels[1][channel+i].data = p;        p += bp->bytesPerHostOutputSample;        bp->hostOutputChannels[1][channel+i].stride = channelCount;    }}        void PaUtil_Set2ndNonInterleavedOutputChannel( PaUtilBufferProcessor* bp,        unsigned int channel, void *data ){    assert( channel < bp->outputChannelCount );        bp->hostOutputChannels[1][channel].data = data;    bp->hostOutputChannels[1][channel].stride = 1;}void PaUtil_BeginBufferProcessing( PaUtilBufferProcessor* bp,        PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags callbackStatusFlags ){    bp->timeInfo = timeInfo;    /* the first streamCallback will be called to process samples which are        currently in the input buffer before the ones starting at the timeInfo time */            bp->timeInfo->inputBufferAdcTime -= bp->framesInTempInputBuffer * bp->samplePeriod;        bp->timeInfo->currentTime = 0; /** FIXME: @todo time info currentTime not implemented */    /* the first streamCallback will be called to generate samples which will be        outputted after the frames currently in the output buffer have been        outputted. */    bp->timeInfo->outputBufferDacTime += bp->framesInTempOutputBuffer * bp->samplePeriod;    bp->callbackStatusFlags = callbackStatusFlags;    bp->hostInputFrameCount[1] = 0;    bp->hostOutputFrameCount[1] = 0;}/*    NonAdaptingProcess() is a simple buffer copying adaptor that can handle    both full and half duplex copies. It processes framesToProcess frames,    broken into blocks bp->framesPerTempBuffer long.    This routine can be used when the streamCallback doesn't care what length    the buffers are, or when framesToProcess is an integer multiple of    bp->framesPerTempBuffer, in which case streamCallback will always be called    with bp->framesPerTempBuffer samples.*/static unsigned long NonAdaptingProcess( PaUtilBufferProcessor *bp,        int *streamCallbackResult,        PaUtilChannelDescriptor *hostInputChannels,        PaUtilChannelDescriptor *hostOutputChannels,        unsigned long framesToProcess ){    void *userInput, *userOutput;    unsigned char *srcBytePtr, *destBytePtr;    unsigned int srcSampleStrideSamples; /* stride from one sample to the next within a channel, in samples */    unsigned int srcChannelStrideBytes; /* stride from one channel to the next, in bytes */    unsigned int destSampleStrideSamples; /* stride from one sample to the next within a channel, in samples */

⌨️ 快捷键说明

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