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

📄 pa_process.c

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 C
📖 第 1 页 / 共 5 页
字号:
        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 */    unsigned int destChannelStrideBytes; /* stride from one channel to the next, in bytes */    unsigned int i;    unsigned long frameCount;    unsigned long framesToGo = framesToProcess;    unsigned long framesProcessed = 0;    if( *streamCallbackResult == paContinue )    {        do        {            frameCount = PA_MIN_( bp->framesPerTempBuffer, framesToGo );            /* configure user input buffer and convert input data (host -> user) */            if( bp->inputChannelCount == 0 )            {                /* no input */                userInput = 0;            }            else /* there are input channels */            {                /*                    could use more elaborate logic here and sometimes process                    buffers in-place.                */                            destBytePtr = (unsigned char *)bp->tempInputBuffer;                if( bp->userInputIsInterleaved )                {                    destSampleStrideSamples = bp->inputChannelCount;                    destChannelStrideBytes = bp->bytesPerUserInputSample;                    userInput = bp->tempInputBuffer;                }                else /* user input is not interleaved */                {                    destSampleStrideSamples = 1;                    destChannelStrideBytes = frameCount * bp->bytesPerUserInputSample;                    /* setup non-interleaved ptrs */                    for( i=0; i<bp->inputChannelCount; ++i )                    {                        bp->tempInputBufferPtrs[i] = ((unsigned char*)bp->tempInputBuffer) +                            i * bp->bytesPerUserInputSample * frameCount;                    }                                    userInput = bp->tempInputBufferPtrs;                }                if( !bp->hostInputChannels[0][0].data )                {                    /* no input was supplied (see PaUtil_SetNoInput), so                        zero the input buffer */                    for( i=0; i<bp->inputChannelCount; ++i )                    {                        bp->inputZeroer( destBytePtr, destSampleStrideSamples, frameCount );                        destBytePtr += destChannelStrideBytes;  /* skip to next destination channel */                    }                }                else                {                    for( i=0; i<bp->inputChannelCount; ++i )                    {                        bp->inputConverter( destBytePtr, destSampleStrideSamples,                                                hostInputChannels[i].data,                                                hostInputChannels[i].stride,                                                frameCount, &bp->ditherGenerator );                        destBytePtr += destChannelStrideBytes;  /* skip to next destination channel */                        /* advance src ptr for next iteration */                        hostInputChannels[i].data = ((unsigned char*)hostInputChannels[i].data) +                                frameCount * hostInputChannels[i].stride * bp->bytesPerHostInputSample;                    }                }            }            /* configure user output buffer */            if( bp->outputChannelCount == 0 )            {                /* no output */                userOutput = 0;            }            else /* there are output channels */            {                if( bp->userOutputIsInterleaved )                {                    userOutput = bp->tempOutputBuffer;                }                else /* user output is not interleaved */                {                    for( i = 0; i < bp->outputChannelCount; ++i )                    {                        bp->tempOutputBufferPtrs[i] = ((unsigned char*)bp->tempOutputBuffer) +                            i * bp->bytesPerUserOutputSample * frameCount;                    }                    userOutput = bp->tempOutputBufferPtrs;                }            }                    *streamCallbackResult = bp->streamCallback( userInput, userOutput,                    frameCount, bp->timeInfo, bp->callbackStatusFlags, bp->userData );            if( *streamCallbackResult == paAbort )            {                /* callback returned paAbort, don't advance framesProcessed                        and framesToGo, they will be handled below */            }            else            {                bp->timeInfo->inputBufferAdcTime += frameCount * bp->samplePeriod;                bp->timeInfo->outputBufferDacTime += frameCount * bp->samplePeriod;                /* convert output data (user -> host) */                if( bp->outputChannelCount != 0 )                {                    /*                        could use more elaborate logic here and sometimes process                        buffers in-place.                    */                                srcBytePtr = (unsigned char *)bp->tempOutputBuffer;                    if( bp->userOutputIsInterleaved )                    {                        srcSampleStrideSamples = bp->outputChannelCount;                        srcChannelStrideBytes = bp->bytesPerUserOutputSample;                    }                    else /* user output is not interleaved */                    {                        srcSampleStrideSamples = 1;                        srcChannelStrideBytes = frameCount * bp->bytesPerUserOutputSample;                    }                    for( i=0; i<bp->outputChannelCount; ++i )                    {                        bp->outputConverter(    hostOutputChannels[i].data,                                                hostOutputChannels[i].stride,                                                srcBytePtr, srcSampleStrideSamples,                                                frameCount, &bp->ditherGenerator );                        srcBytePtr += srcChannelStrideBytes;  /* skip to next source channel */                        /* advance dest ptr for next iteration */                        hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) +                                frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample;                    }                }                framesProcessed += frameCount;                framesToGo -= frameCount;            }        }        while( framesToGo > 0  && *streamCallbackResult == paContinue );    }    if( framesToGo > 0 )    {        /* zero any remaining frames. There will only be remaining frames            if the callback has returned paComplete or paAbort */        frameCount = framesToGo;        for( i=0; i<bp->outputChannelCount; ++i )        {            bp->outputZeroer(   hostOutputChannels[i].data,                                hostOutputChannels[i].stride,                                frameCount );            /* advance dest ptr for next iteration */            hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) +                    frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample;        }                    framesProcessed += frameCount;    }    return framesProcessed;}/*    AdaptingInputOnlyProcess() is a half duplex input buffer processor. It    converts data from the input buffers into the temporary input buffer,    when the temporary input buffer is full, it calls the streamCallback.*/static unsigned long AdaptingInputOnlyProcess( PaUtilBufferProcessor *bp,        int *streamCallbackResult,        PaUtilChannelDescriptor *hostInputChannels,        unsigned long framesToProcess ){    void *userInput, *userOutput;    unsigned char *destBytePtr;    unsigned int destSampleStrideSamples; /* stride from one sample to the next within a channel, in samples */    unsigned int destChannelStrideBytes; /* stride from one channel to the next, in bytes */    unsigned int i;    unsigned long frameCount;    unsigned long framesToGo = framesToProcess;    unsigned long framesProcessed = 0;        userOutput = 0;    do    {        frameCount = ( bp->framesInTempInputBuffer + framesToGo > bp->framesPerUserBuffer )                ? ( bp->framesPerUserBuffer - bp->framesInTempInputBuffer )                : framesToGo;        /* convert frameCount samples into temp buffer */        if( bp->userInputIsInterleaved )        {            destBytePtr = ((unsigned char*)bp->tempInputBuffer) +                    bp->bytesPerUserInputSample * bp->inputChannelCount *                    bp->framesInTempInputBuffer;                                  destSampleStrideSamples = bp->inputChannelCount;            destChannelStrideBytes = bp->bytesPerUserInputSample;            userInput = bp->tempInputBuffer;        }        else /* user input is not interleaved */        {            destBytePtr = ((unsigned char*)bp->tempInputBuffer) +                    bp->bytesPerUserInputSample * bp->framesInTempInputBuffer;            destSampleStrideSamples = 1;            destChannelStrideBytes = bp->framesPerUserBuffer * bp->bytesPerUserInputSample;            /* setup non-interleaved ptrs */            for( i=0; i<bp->inputChannelCount; ++i )            {                bp->tempInputBufferPtrs[i] = ((unsigned char*)bp->tempInputBuffer) +                    i * bp->bytesPerUserInputSample * bp->framesPerUserBuffer;            }                                userInput = bp->tempInputBufferPtrs;        }        for( i=0; i<bp->inputChannelCount; ++i )        {            bp->inputConverter( destBytePtr, destSampleStrideSamples,                                    hostInputChannels[i].data,                                    hostInputChannels[i].stride,                                    frameCount, &bp->ditherGenerator );            destBytePtr += destChannelStrideBytes;  /* skip to next destination channel */            /* advance src ptr for next iteration */            hostInputChannels[i].data = ((unsigned char*)hostInputChannels[i].data) +                    frameCount * hostInputChannels[i].stride * bp->bytesPerHostInputSample;        }        bp->framesInTempInputBuffer += frameCount;        if( bp->framesInTempInputBuffer == bp->framesPerUserBuffer )        {            /**            @todo (non-critical optimisation)            The conditional below implements the continue/complete/abort mechanism            simply by continuing on iterating through the input buffer, but not            passing the data to the callback. With care, the outer loop could be            terminated earlier, thus some unneeded conversion cycles would be            saved.            */            if( *streamCallbackResult == paContinue )            {                bp->timeInfo->outputBufferDacTime = 0;                *streamCallbackResult = bp->streamCallback( userInput, userOutput,                        bp->framesPerUserBuffer, bp->timeInfo,                        bp->callbackStatusFlags, bp->userData );                bp->timeInfo->inputBufferAdcTime += frameCount * bp->samplePeriod;            }                        bp->framesInTempInputBuffer = 0;        }        framesProcessed += frameCount;        framesToGo -= frameCount;    }while( framesToGo > 0 );    return framesProcessed;}/*    AdaptingOutputOnlyProcess() is a half duplex output buffer processor.    It converts data from the temporary output buffer, to the output buffers,    when the temporary output buffer is empty, it calls the streamCallback.*/static unsigned long AdaptingOutputOnlyProcess( PaUtilBufferProcessor *bp,        int *streamCallbackResult,        PaUtilChannelDescriptor *hostOutputChannels,        unsigned long framesToProcess ){    void *userInput, *userOutput;    unsigned char *srcBytePtr;    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 i;    unsigned long frameCount;    unsigned long framesToGo = framesToProcess;    unsigned long framesProcessed = 0;    do    {        if( bp->framesInTempOutputBuffer == 0 && *streamCallbackResult == paContinue )        {            userInput = 0;            /* setup userOutput */            if( bp->userOutputIsInterleaved )            {                userOutput = bp->tempOutputBuffer;            }            else /* user output is not interleaved */            {                for( i = 0; i < bp->outputChannelCount; ++i )                {                    bp->tempOutputBufferPtrs[i] = ((unsigned char*)bp->tempOutputBuffer) +                            i * bp->framesPerUserBuffer * bp->bytesPerUserOutputSample;                }                userOutput = bp->tempOutputBufferPtrs;            }

⌨️ 快捷键说明

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