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

📄 src.cpp

📁 EP931X系列的WinCE声卡驱动源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
)
{
    register long lOutData;
    register short *psPtr1;
    register ULONG  *pulPtr2;
    long lInSamples, lConsumed, lOutSamples, lProduced;
    PUCHAR   pucOutData = (PUCHAR)psOutData;

    //
    // Get the initial values of the sample counters.
    //
    lInSamples = *plInSamples;
    lConsumed = 0;
    lOutSamples = *plOutSamples;
    lProduced = 0;

    //
    // Run the sample rate converter filter for the specified number of
    // samples.
    //
    while(lOutSamples && lInSamples)
    {
        //
        // See if we've passed the entire filter, indicating that we've
        // consumed one of the input samples.
        //
        while(pSRC->sFilterOffset >= pSRC->sFilterSize)
        {
            //
            // We have, so wrap the filter offset (i.e. treat the filter as if
            // it were a circular buffer in memory).
            //
            pSRC->sFilterOffset -= pSRC->sFilterSize;

            //
            // Consume the input sample.
            //
            //psInData++;
            //
            // RLG
            // Since the input stream is always stereo for I2S skip every 
            // Left Sample
            //
            pulInData+=2;

            //
            // Decrement the count of input samples available.
            //
            lInSamples--;

            //
            // Increment the count of input samples consumed.
            //
            lConsumed++;

            //
            // If there are no more input samples, then stop processing data.
            //
            if(lInSamples == 0)
            {
                //
                // Return the number of samples produced and consumed.
                //
                *plInSamples = lConsumed;
                *plOutSamples = lProduced;

                //
                // Return to the caller.
                //
                return;
            }
        }

        //
        // Get a pointer to the filter and to the sample data.
        //
        psPtr1      = pSRC->psFilter + pSRC->sFilterOffset;
        pulPtr2     = pulInData;

        //
        // Run the filter over the sample data.  The number of MACs here must
        // agree with NUMTAPS.
        //
        lOutData = *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;

        //
        // Clip the filtered sample if necessary.
        //
        if((lOutData + 0x40000000) < 0)
        {
            lOutData = (lOutData & 0x80000000) ? 0xc0000000 : 0x3fffffff;
        }

        //
        // Write out the sample.
        //
        if(b8Bit)
        {
            *pucOutData++ = UCHAR((lOutData>>23) & 0xFF) + 0x80;
        }
        else
        {
            *psOutData++  = (short)(lOutData >> 15);
        }

        //
        // Decrement the count of output sample space available.
        //
        lOutSamples--;

        //
        // Increment the count of output samples produced.
        //
        lProduced++;

        //
        // Increment the offset into the filter.
        //
        pSRC->sFilterOffset += pSRC->sFilterIncr;

    }

    //
    // Return the number of samples produced and consumed.
    //
    *plInSamples = lConsumed;
    *plOutSamples = lProduced;
}

//****************************************************************************
// FilterMono6
//****************************************************************************
// FilterMono6 performs the actual sample rate conversion for a single mono
// stream of data using a 6-tap filter.
//
// IN     tSRC         -  Pointer to the SRC structure.
// IN     plInData     - Pointer to the Input Buffer.
// IN     psOutData    - Pointer to the output buffer.
// IN/OUT plInSamples  - Number of Sample avaliable/consumed in Input Buffer.
// IN/OUT plOutSamples - Number of Sample avaliable/consumed in Output buffer.
// IN     b8Bit        - Is the Output 8 bit.
//
//
static void
FilterMono6
(
    tSRC    *pSRC, 
    ULONG   *pulInData, 
    short   *psOutData, 
    long    *plInSamples,
    long    *plOutSamples,
    BOOL    b8Bit
)
{
    register long lOutData;
    register short *psPtr1;
    register unsigned long  *pulPtr2;
    long lInSamples, lConsumed, lOutSamples, lProduced;
    PUCHAR   pucOutData = (PUCHAR)psOutData;

    //
    // Get the initial values of the sample counters.
    //
    lInSamples = *plInSamples;
    lConsumed = 0;
    lOutSamples = *plOutSamples;
    lProduced = 0;

    //
    // Run the sample rate converter filter for the specified number of
    // samples.
    //
    while(lOutSamples && lInSamples)
    {
        //
        // See if we've passed the entire filter, indicating that we've
        // consumed one of the input samples.
        //
        while(pSRC->sFilterOffset >= pSRC->sFilterSize)
        {
            //
            // We have, so wrap the filter offset (i.e. treat the filter as if
            // it were a circular buffer in memory).
            //
            pSRC->sFilterOffset -= pSRC->sFilterSize;

            //
            // Consume the input sample.
            //
            // psInData++;

            // RLG
            // Since the input stream is always stereo for I2S skip every 
            // Left Sample
            //
            pulInData+=2;

            //
            // Decrement the count of input samples available.
            //
            lInSamples--;

            //
            // Increment the count of input samples consumed.
            //
            lConsumed++;

            //
            // If there are no more input samples, then stop processing data.
            //
            if(lInSamples == 0)
            {
                //
                // Return the number of samples produced and consumed.
                //
                *plInSamples = lConsumed;
                *plOutSamples = lProduced;

                //
                // Return to the caller.
                //
                return;
            }
        }

        //
        // Get a pointer to the filter and to the sample data.
        //
        psPtr1 = pSRC->psFilter + pSRC->sFilterOffset;
        pulPtr2 = (PULONG)pulInData;

        //
        // Run the filter over the sample data.
        //
        lOutData = *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;
        lOutData += *psPtr1++ * short(*pulPtr2>>8);
        pulPtr2-=2;

        //
        // Clip the filtered sample if necessary.
        //
        if((lOutData + 0x40000000) < 0)
        {
            lOutData = (lOutData & 0x80000000) ? 0xc0000000 : 0x3fffffff;
        }

        //
        // Write out the sample.
        //
        if(b8Bit)
        {
            *pucOutData++ = UCHAR((lOutData>>23) & 0xFF) + 0x80;
        }
        else
        {
            *psOutData++  = (short)(lOutData >> 15);
        }

        //
        // Decrement the count of output sample space available.
        //
        lOutSamples--;

        //
        // Increment the count of output samples produced.
        //
        lProduced++;

        //
        // Increment the offset into the filter.
        //
        pSRC->sFilterOffset += pSRC->sFilterIncr;
    }

    //
    // Return the number of samples produced and consumed.
    //
    *plInSamples = lConsumed;
    *plOutSamples = lProduced;
}

//****************************************************************************
// FilterStereo13
//****************************************************************************
// FilterStereo13 performs the actual sample rate conversion using a 
// 13-tap filter.
//
// IN     tSRC         - Pointer to the SRC structure.
// IN     pusInData    - Pointer to the Input Buffer.
// IN     pusOutData   - Pointer to the output buffer.
// IN/OUT plInSamples  - Number of Sample avaliable/consumed in Input Buffer.
// IN/OUT plOutSamples - Number of Sample avaliable/consumed in Output buffer.
// IN     b8Bit        - Is the Output 8 bit.
//
//
static void FilterStereo13
(
    tSRC    *pSRC, 
    ULONG   *pulInData, 
    short   *psOutData, 
    long    *plInSamples,
    long    *plOutSamples,
    BOOL    b8Bit
)
{
    register long lOutDataLeft, lOutDataRight;
    register short *psPtr1;
    register unsigned long  *pulPtr2;
    register short sCoeff;
    long lInSamples, lConsumed, lOutSamples, lProduced;
    PUCHAR   pucOutData = (PUCHAR)psOutData;


    //
    // Get the initial values of the sample counters.
    //
    lInSamples = *plInSamples;
    lConsumed = 0;
    lOutSamples = *plOutSamples;
    lProduced = 0;

    //
    // Run the sample rate converter filter for the specified number of
    // samples.
    //
    while(lOutSamples && lInSamples)
    {
        //

⌨️ 快捷键说明

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