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

📄 cpi_player_output_directsound.c

📁 VC++视频开发实例集锦(包括“远程视频监控”"语音识别系统"等13个经典例子)
💻 C
📖 第 1 页 / 共 2 页
字号:
                                           &pbData,
                                           &dwLength,
                                           NULL,
                                           NULL,
                                           0);
        if(FAILED(hrRetVal))
        {
            CPP_OMDS_Uninitialise(pModule);
            CP_FAIL("Cannot lock soundbuffer");
        }

        if( (pContext->m_WriteCursor + dwAmountToFill) >= CPC_OUTPUTBLOCKSIZE)
            RealLength = CPC_OUTPUTBLOCKSIZE - pContext->m_WriteCursor;
        else
            RealLength = dwAmountToFill;
        if(RealLength)
        {
            bMoreData = pModule->m_pCoDec->GetPCMBlock(pModule->m_pCoDec, pContext->m_pShadowBuffer + pContext->m_WriteCursor, &RealLength);
            memcpy(pbData + pContext->m_WriteCursor, pContext->m_pShadowBuffer + pContext->m_WriteCursor, RealLength);
        }

        {
            CPs_EqualiserModule* pEQModule = (CPs_EqualiserModule*)pModule->m_pEqualiser;
            if(RealLength)
                pEQModule->ApplyEQToBlock_Inplace(pEQModule, pbData + pContext->m_WriteCursor, RealLength);
        }

        pContext->m_WriteCursor += RealLength;
        if(pContext->m_WriteCursor >= CPC_OUTPUTBLOCKSIZE)
            pContext->m_WriteCursor -= CPC_OUTPUTBLOCKSIZE;

        hrRetVal = IDirectSoundBuffer_Unlock(pContext->lpDSB,
                                             pbData,
                                             dwLength,
                                             NULL,
                                             0L);
        if(FAILED(hrRetVal))
        {
            CPP_OMDS_Uninitialise(pModule);
            CP_FAIL("Cannot Unlock soundbuffer");
        }
    }

    if(bMoreData == FALSE)
    {
        CP_TRACE0("Stream exhausted");
        pModule->m_pCoDec->CloseFile(pModule->m_pCoDec);
        pModule->m_pCoDec = NULL;
    }

    pContext->m_TermState_Wrapped = FALSE;
    pContext->m_TermState_WriteCursor = CPC_INVALIDCURSORPOS;
    pContext->m_TermState_HighestPlayPos = CPC_INVALIDCURSORPOS;
    if(!pContext->m_bStreamRunning)
        CPP_OMDS_EnablePlay(pModule, TRUE);
}
//
void CPP_OMDS_SetPause(CPs_OutputModule* pModule, const BOOL bPause)
{
    CPs_OutputContext_DirectSound* pContext = (CPs_OutputContext_DirectSound*)pModule->m_pModuleCookie;
    CP_CHECKOBJECT(pContext);
    if(!pContext->lpDirectSound)
        return;

    CPP_OMDS_EnablePlay(pModule, !bPause);
}
//
BOOL CPP_OMDS_IsOutputComplete(CPs_OutputModule* pModule)
{
    CPs_OutputContext_DirectSound* pContext = (CPs_OutputContext_DirectSound*)pModule->m_pModuleCookie;
    DWORD dwCurrentPlayCursor, dwInvalidLength;
    CP_CHECKOBJECT(pContext);

    if(!pContext->lpDirectSound)
        return TRUE;

    if(pContext->m_WriteCursor == CPC_INVALIDCURSORPOS)
        return TRUE;

    if(pContext->m_TermState_WriteCursor == CPC_INVALIDCURSORPOS)
        pContext->m_TermState_WriteCursor = pContext->m_WriteCursor;

    if(pModule->m_pCoDec)
        return FALSE;

    GetPlayPosAndInvalidLength(pContext, &dwCurrentPlayCursor, &dwInvalidLength);

    if(dwInvalidLength > 0)
    {
        BYTE *pbData = NULL;
        DWORD dwLength=0;

        IDirectSoundBuffer_Lock(pContext->lpDSB,
                                pContext->m_WriteCursor,
                                dwInvalidLength,
                                &pbData,
                                &dwLength,
                                NULL,
                                NULL,
                                0);

        if(pbData)
            memset(pbData, 0, dwLength);

        IDirectSoundBuffer_Unlock(pContext->lpDSB,
                                  pbData,
                                  dwLength,
                                  NULL,
                                  0L);

        pContext->m_WriteCursor += dwInvalidLength;
        if(pContext->m_WriteCursor >= CPC_OUTPUTBLOCKSIZE)
            pContext->m_WriteCursor -= CPC_OUTPUTBLOCKSIZE;

    }

    if(pContext->m_TermState_HighestPlayPos == CPC_INVALIDCURSORPOS || pContext->m_TermState_HighestPlayPos < dwCurrentPlayCursor)
        pContext->m_TermState_HighestPlayPos = dwCurrentPlayCursor;
    else
        pContext->m_TermState_Wrapped = TRUE;

    if(pContext->m_TermState_Wrapped == FALSE)
        return FALSE;

    if(dwCurrentPlayCursor > pContext->m_TermState_WriteCursor)
        return TRUE;

    return FALSE;
}
//
void CPP_OMDS_Flush(CPs_OutputModule* pModule)
{
    DWORD dwCurrentPlayCursor;
    CPs_OutputContext_DirectSound* pContext = (CPs_OutputContext_DirectSound*)pModule->m_pModuleCookie;
    CP_CHECKOBJECT(pContext);
    if(!pContext->lpDirectSound)
        return;

    CPP_OMDS_EnablePlay(pModule, FALSE);
    IDirectSoundBuffer_GetCurrentPosition(pContext->lpDSB, &dwCurrentPlayCursor, NULL);
    pContext->m_WriteCursor = dwCurrentPlayCursor;
}
//
void CPP_OMDS_EnablePlay(CPs_OutputModule* pModule, const BOOL bEnable)
{
    CPs_OutputContext_DirectSound* pContext = (CPs_OutputContext_DirectSound*)pModule->m_pModuleCookie;
    CP_CHECKOBJECT(pContext);
    pContext->m_bStreamRunning = bEnable;

    if(bEnable)
    {
        IDirectSoundBuffer_Play(pContext->lpDSB,0,0,DSBPLAY_LOOPING);

        if(pContext->m_TimerId == 0)
        {
            pContext->m_TimerId = timeSetEvent(20,
                                               10,	
                                               (LPTIMECALLBACK)pModule->m_evtBlockFree,
                                               0,
                                               TIME_PERIODIC | TIME_CALLBACK_EVENT_SET);
        }
    }
    else
    {
        IDirectSoundBuffer_Stop(pContext->lpDSB);
        timeKillEvent(pContext->m_TimerId);
        pContext->m_TimerId = 0;
    }
}
//
void CPP_OMDS_OnEQChanged(CPs_OutputModule* pModule)
{
    CPs_OutputContext_DirectSound* pContext = (CPs_OutputContext_DirectSound*)pModule->m_pModuleCookie;
    BYTE *pbData = NULL;
    DWORD dwLength=0;
//    DWORD dwPlayPos;
//    CPs_EqualiserModule* pEQModule;
    CP_CHECKOBJECT(pContext);

  /*  
    IDirectSoundBuffer_GetCurrentPosition(pContext->lpDSB, &dwPlayPos, NULL);

    IDirectSoundBuffer_Lock(pContext->lpDSB,
                            0,
                            CPC_OUTPUTBLOCKSIZE,
                            &pbData,
                            &dwLength,
                            NULL,
                            NULL,
                            0);

    if(pbData)
        memcpy(pbData, pContext->m_pShadowBuffer, dwLength);

   
    pEQModule = (CPs_EqualiserModule*)pModule->m_pEqualiser;
    if(pContext->m_WriteCursor > dwPlayPos)
    {
        
        if(pContext->m_WriteCursor != CPC_INVALIDCURSORPOS)
            pEQModule->ApplyEQToBlock_Inplace(pEQModule, pbData + dwPlayPos, pContext->m_WriteCursor - dwPlayPos);
    }
    else
    {
       
     
        pEQModule->ApplyEQToBlock_Inplace(pEQModule, pbData + dwPlayPos, CPC_OUTPUTBLOCKSIZE - dwPlayPos);
        pEQModule->ApplyEQToBlock_Inplace(pEQModule, pbData, pContext->m_WriteCursor);
    }

    IDirectSoundBuffer_Unlock(pContext->lpDSB,
                              pbData,
                              dwLength,
                              NULL,
                              0L);
							  */
}

void CPP_OMDS_SetInternalVolume(CPs_OutputModule* pModule, const int iNewVolume)
{
    CPs_OutputContext_DirectSound* pContext = (CPs_OutputContext_DirectSound*)pModule->m_pModuleCookie;
    LONG lVolume;
    CP_CHECKOBJECT(pContext);

    lVolume = (int)( pow((double)(100-iNewVolume)*0.01, 3) * (double)DSBVOLUME_MIN);  //((100-iNewVolume) * DSBVOLUME_MIN) / 500;
    IDirectSoundBuffer_SetVolume(pContext->lpDSB, lVolume);
}


⌨️ 快捷键说明

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