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

📄 wavein.cpp

📁 CIRRUS 93XX系列windows mobile 6.0 BSP
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    do
    {
        ulTemp    = *pulSrc++;
        *pusDst++ = (USHORT)(ulTemp>>8);
    }
    while(pusDst < pusEnd);
}



//****************************************************************************
// ConvertWordsToBytesMonoToStereo
//****************************************************************************
// Converts a stream of bytes to words.
//
// pUnused              - Unused pointer.
// pulSrc               - Signed 24 bit values right justified.
// pucDst               - Unsigned 8 bit values.
// pulSrcSamples        - IN/OUT Number of Source Samples Available/Used
// pulDstSamples        - IN/OUT Number of Destination Samples Available/Used
//
void ConvertWordsToBytesStereoToMono
(
    PVOID       pUnused,
    PULONG      pulSrc, 
    PUCHAR      pucDst, 
    PULONG      pulSrcSamples,
    PULONG      pulDstSamples
)
{
    ULONG   ulCount;
    ULONG   ulTemp;
    ULONG   ulSamples;

    if(*pulSrcSamples > *pulDstSamples)
    {
        ulSamples = *pulSrcSamples = *pulDstSamples;
    }
    else
    {
        ulSamples = *pulDstSamples = *pulSrcSamples;
    }
    
    for(ulCount = 0; ulCount <ulSamples ; ulCount++)
    {   
        //
        // TODO - Should really add the values together and check for 
        // saturation.
        //
        ulTemp     = *pulSrc++;
        pulSrc++;
        *pucDst++ = UCHAR((ulTemp>>16) + 0x80);
    }
}

//****************************************************************************
// ConvertShortsToWordsMonoToStereo
//****************************************************************************
// Converts a stream of bytes to words.
//
// pUnused              - Unused pointer.
// pulSrc               - Signed 24 bit values right justified.
// pusDst               - Unsigned 8 bit values.
// pulSrcSamples        - IN/OUT Number of Source Samples Available/Used
// pulDstSamples        - IN/OUT Number of Destination Samples Available/Used
//
void ConvertWordsToShortsStereoToMono
(
    PVOID       pUnused,
    PULONG      pulSrc, 
    PUSHORT     pusDst, 
    PULONG      pulSrcSamples,
    PULONG      pulDstSamples
)
{
    ULONG   ulCount;
    ULONG   ulTemp;
    ULONG   ulSamples;

    if(*pulSrcSamples > *pulDstSamples)
    {
        ulSamples = *pulSrcSamples = *pulDstSamples;
    }
    else
    {
        ulSamples = *pulDstSamples = *pulSrcSamples;
    }
    
    for(ulCount = 0; ulCount <ulSamples ; ulCount++)
    {   
        //
        // TODO - Should really add the values together and check for 
        // saturation.
        //
        ulTemp    = *pulSrc++;
        pulSrc++;
        *pusDst++ = USHORT(ulTemp>>8);
    }
}

//****************************************************************************
// ConvertShortsToShorts
//****************************************************************************
// Converts a stream of stereo shorts to shorts (memcpy).
//
// pUnused              - Unused pointer.
// pusSrc               - Signed 16 bit values 
// pusDst               - Signed 16 bit values 
// pulSrcSamples        - IN/OUT Number of Source Samples Available/Used
// pulDstSamples        - IN/OUT Number of Destination Samples Available/Used
//

void ConvertShortsToShorts
(
    PVOID   pUnused,
    PUSHORT pusSrc, 
    PUCHAR  pusDst, 
    PULONG  pulSrcSamples,
    PULONG  pulDstSamples
)
{
    ULONG   ulSamples;

    if(*pulSrcSamples > *pulDstSamples)
    {
        ulSamples = *pulSrcSamples = *pulDstSamples;
    }
    else
    {
        ulSamples = *pulDstSamples = *pulSrcSamples;
    }
    memcpy(pusDst, pusSrc, ulSamples * sizeof(ULONG));
}


//****************************************************************************
// ConvertShortsToBytesStereoToMono
//****************************************************************************
// Converts a stream of stereo shorts to mono bytess.
//
// pUnused              - Unused pointer.
// pusSrc               - Signed 16 bit values 
// pucDst               - Unsigned 8 bit values.
// pulSrcSamples        - IN/OUT Number of Source Samples Available/Used
// pulDstSamples        - IN/OUT Number of Destination Samples Available/Used
//
void ConvertShortsToBytesStereoToMono
(
    PVOID       pUnused,
    PUSHORT     pusSrc, 
    PUCHAR      pucDst, 
    PULONG      pulSrcSamples,
    PULONG      pulDstSamples
)
{
    PUCHAR  pucEnd;
    UCHAR   ucTemp;
    ULONG   ulSamples;

    if(*pulSrcSamples > *pulDstSamples)
    {
        ulSamples = *pulSrcSamples = *pulDstSamples;
    }
    else
    {
        ulSamples = *pulDstSamples = *pulSrcSamples;
    }
    pucEnd = pucDst + ulSamples;
    do
    {
        ucTemp          = (UCHAR)((*pusSrc++>> 8) & 0xFF);
        pusSrc++;
        *pucDst++ = ucTemp + 0x80;

    } while(pucDst <pucEnd);

}

//****************************************************************************
// ConvertShortsStereoToMono
//****************************************************************************
// Converts a stream of shorts from stereo to mono.
//
// pUnused              - Unused pointer.
// pusSrc               - Signed 16 bit values 
// pusDst               - Signed 16 bit values 
// pulSrcSamples        - IN/OUT Number of Source Samples Available/Used
// pulDstSamples        - IN/OUT Number of Destination Samples Available/Used
//
void ConvertShortsStereoToMono
(
    PVOID       pUnused,
    PUSHORT     pusSrc, 
    PUSHORT     pusDst, 
    PULONG      pulSrcSamples,
    PULONG      pulDstSamples
)
{

    PUSHORT pusEnd;
    ULONG   ulSamples;

    if(*pulSrcSamples > *pulDstSamples)
    {
        ulSamples = *pulSrcSamples = *pulDstSamples;
    }
    else
    {
        ulSamples = *pulDstSamples = *pulSrcSamples;
    }
    pusEnd = pusDst + ulSamples;
    do
    {
        *pusDst++ = *pusSrc++;
        pusSrc++;
    } while(pusDst <pusEnd);
}

//****************************************************************************
// ConvertShortsToBytes
//****************************************************************************
// Converts a stream of shorts to Bytes
//
// pUnused              - Unused pointer.
// pusSrc               - Signed 16 bit values 
// pusDst               - Signed 16 bit values 
// pulSrcSamples        - IN/OUT Number of Source Samples Available/Used
// pulDstSamples        - IN/OUT Number of Destination Samples Available/Used
//

void ConvertShortsToBytes
(
    PVOID       pUnused,
    PUSHORT     pusSrc, 
    PUCHAR      pucDst, 
    PULONG      pulSrcSamples,
    PULONG      pulDstSamples
)
{
    PUCHAR  pucEnd;
    UCHAR   ucTemp;
    ULONG   ulSamples;

    if(*pulSrcSamples > *pulDstSamples)
    {
        ulSamples = *pulSrcSamples = *pulDstSamples;
    }
    else
    {
        ulSamples = *pulDstSamples = *pulSrcSamples;
    }

    pucEnd = pucDst + (ulSamples<<1);
    do
    {
        ucTemp    = (UCHAR)((*pusSrc++>> 8) & 0xFF);
        *pucDst++ = ucTemp + 0x80;
    } while(pucDst <pucEnd);
}


//****************************************************************************
// WaveIn::EmptyDMABuffer
//****************************************************************************
// dwStartPos - Starting Copy Position of the DMA buffer
// dwEndPos   - End Copy Position of the DMA buffer.
//
void WaveIn::EmptyDMABuffer
(
    DWORD   dwStartPos,
    DWORD   dwEndPos
)
{
    BOOL        bIsEmpty = FALSE;
    DWORD       dwSourceSamples, dwDestSamples;

    //
    // While the DMA buffer is not empty, try to empty it.
    //
    while(!bIsEmpty)
    {
        DWORD       dwDestBytesRecorded;

        //
        // If we ran out of buffers, there's not much we can do.
        //
        if(!m_pWaveNext)
        {
            break;
        }

        //
        // Determine the amount of data left in the DMA buffer.
        //
        dwSourceSamples = (dwEndPos - dwStartPos) >> m_dwSourceFactor;
        dwDestSamples   = (m_pWaveNext->dwBufferLength - m_pWaveNext->dwBytesRecorded) >> m_dwDestFactor;

        m_pfnWaveCopyFunc
        (
            &m_Src,
            (UCHAR *)m_pBuffer + dwStartPos, 
            (UCHAR *)m_pWaveNext->lpData + m_pWaveNext->dwBytesRecorded,
            &dwSourceSamples,
            &dwDestSamples
    
        );

        //
        // Update the count of the number of bytes that have been recorded.
        //
        dwDestBytesRecorded = (dwDestSamples <<m_dwDestFactor);
        m_dwRecordedBytes               += dwDestBytesRecorded;
        m_pWaveNext->dwBytesRecorded    += dwDestBytesRecorded;

        //
        // Increment the start point in the DMA buffer by the number
        // of bytes copied from it
        //
        dwStartPos += (dwSourceSamples << m_dwSourceFactor);

        //
        // Bump the start position up to the ending position
        //
        if(dwStartPos == dwEndPos)
        {
            //
            // We emptied the DMA buffer
            //
            bIsEmpty = TRUE;
        }

        if(!bIsEmpty && !(m_pWaveNext->dwBufferLength == m_pWaveNext->dwBytesRecorded))
        {
            ASSERT(0);
        }

        //
        // If we filled a wave header, move on to the next one
        //
        if(m_pWaveNext->dwBytesRecorded == m_pWaveNext->dwBufferLength)
        {
            //
            // Mark the buffer as done.
            //
            MARK_BUFFER_DONE(m_pWaveNext);

            //
            // Remove the first wave header from m_pWaveNext.
            //
            m_pWaveNext = m_pWaveNext->lpNext;
        }
    }
}

//****************************************************************************
// WaveIn::RemoveCompleteBlocks
//****************************************************************************
// Removes any blocks that have been completed.
// 
//
void WaveIn::RemoveCompleteBlocks()
{
    PWAVEHDR pWave;

    while (m_pWaveHead != NULL) 
    {
        if (IS_BUFFER_DONE(m_pWaveHead))  
        {
            pWave = m_pWaveHead;
            //
            // Only remove a block if it's not in a loop.
            //
            WIDM_MSG((L"MM_WIM_DONE: pWave = 0x%08x\n",(DWORD)pWave));

            m_pWaveHead = m_pWaveHead->lpNext;
            MARK_BUFFER_DEQUEUED(pWave);

            //
            // Check to see if the next buffer is at the front.
            // If so set it to the next one in the list.
            //
            if(pWave == m_pWaveNext)
            {
                m_pWaveNext = m_pWaveHead;
            }
            
            //
            // Make the callback function call to the Wave API Manager
            //
            m_pfnCallback(m_hCallback, MM_WIM_DATA, m_dwInstance, (DWORD) pWave, 0);
        }
        else 
        {
            //
            // Only remove from the front of the list, but as many as are done.
            //
            break;  // If the first one's not DONE, then break the loop.
        }
    }   
}


//****************************************************************************
// WaveIn::InterruptHandler
//****************************************************************************
// Interrupt handler.
// 
//
void WaveIn::InterruptHandler(void *Handle, BOOL bLastHalf)
{
    WaveIn *pWaveIn = (WaveIn *)Handle;

    DWORD   dwStartPos, dwEndPos;
    
    
    EnterCriticalSection( &pWaveIn->m_CriticalSection);
//    dwAccessKey=GetCurrentPermissions();
//    SetProcPermissions((ULONG) -1); //  access everybody

    //
    // Find out which half of the DMA buffer we are playing.
    //
    if(bLastHalf)
    {
        dwStartPos  = pWaveIn->m_ulDmaBufferSize/2;
        dwEndPos    = pWaveIn->m_ulDmaBufferSize;
    }
    else        
    {
        dwStartPos  = 0;
        dwEndPos    = pWaveIn->m_ulDmaBufferSize/2;
    }        

    //
    // If we are using an Software SRC copy the contents into a cached buffer.
    //
    if(pWaveIn->m_bUseSrc)
    {
        memcpy
        (
            PUCHAR(pWaveIn->m_pBuffer) + dwStartPos,
            PUCHAR(pWaveIn->m_pDmaBuffer) + dwStartPos,
            pWaveIn->m_ulDmaBufferSize/2
        );
    }
    
    //
    // Copy the data into the buffer.
    //
    pWaveIn->EmptyDMABuffer(dwStartPos, dwEndPos);

    //
    // Remove the completed buffers.
    //
    pWaveIn->RemoveCompleteBlocks();

    //
    // If we are using a sample rate converter and the last half of the 
    // buffer,  copy the last few samples to the begining.
    //
    if( pWaveIn->m_bUseSrc && bLastHalf)
    {
        ULONG   ulFilterByteSize = 2 * sizeof(ULONG) * pWaveIn->m_Src.sFilterSize;

        memcpy
        ( 
            PUCHAR(pWaveIn->m_pBuffer) -  ulFilterByteSize,
            PUCHAR(pWaveIn->m_pDmaBuffer) + pWaveIn->m_ulDmaBufferSize  - ulFilterByteSize,
            ulFilterByteSize
        );
    }


    //
    //  change permission back
    //
//    SetProcPermissions(dwAccessKey);
    
    LeaveCriticalSection( &pWaveIn->m_CriticalSection);

}

⌨️ 快捷键说明

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