audio/sysvad/APO/DelayAPO/DelayAPOMFX.cpp
STDMETHODIMP CDelayAPOMFX::LockForProcess(UINT32 u32NumInputConnections,
    APO_CONNECTION_DESCRIPTOR** ppInputConnections,  
    UINT32 u32NumOutputConnections, APO_CONNECTION_DESCRIPTOR** ppOutputConnections)
{
    ASSERT_NONREALTIME();
    HRESULT hr = S_OK;
    
    hr = CBaseAudioProcessingObject::LockForProcess(u32NumInputConnections,
        ppInputConnections, u32NumOutputConnections, ppOutputConnections);
    IF_FAILED_JUMP(hr, Exit);
    
    if (!IsEqualGUID(m_AudioProcessingMode, AUDIO_SIGNALPROCESSINGMODE_RAW) && m_fEnableDelayMFX)
    {
        m_nDelayFrames = FRAMES_FROM_HNS(HNS_DELAY);
        m_iDelayIndex = 0;

        m_pf32DelayBuffer.Free();

        // Allocate one second's worth of audio
        // 
        // This allocation is being done using CoTaskMemAlloc because the delay is very large
        // This introduces a risk of glitches if the delay buffer gets paged out
        //
        // A more typical approach would be to allocate the memory using AERT_Allocate, which locks the memory
        // But for the purposes of this APO, CoTaskMemAlloc suffices, and the risk of glitches is not important
        m_pf32DelayBuffer.Allocate(GetSamplesPerFrame() * m_nDelayFrames);
        WriteSilence(m_pf32DelayBuffer, m_nDelayFrames, GetSamplesPerFrame());
        if (nullptr == m_pf32DelayBuffer)
        {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    }
    
Exit:
    return hr;
}
//-------------------------------------------------------------------------
// Description:
//
//  Verifies that the APO is ready to process and locks its state if so.
//
// Parameters:
//
//      u32NumInputConnections - [in] number of input connections attached to this APO
//      ppInputConnections - [in] connection descriptor of each input connection attached to this APO
//      u32NumOutputConnections - [in] number of output connections attached to this APO
//      ppOutputConnections - [in] connection descriptor of each output connection attached to this APO
//
// Return values:
//
//      S_OK                                Object is locked and ready to process.
//      E_POINTER                           Invalid pointer passed to function.
//      APOERR_INVALID_CONNECTION_FORMAT    Invalid connection format.
//      APOERR_NUM_CONNECTIONS_INVALID      Number of input or output connections is not valid on
//                                          this APO.

Verifies that the APO is ready to process and locks its state if so.



[in] number of input connections attached to this APO
ppInputConnections - [in] connection descriptor of each input connection attached to this APO
u32NumOutputConnections - [in] number of output connections attached to this APO
ppOutputConnections - [in] connection descriptor of each output connection attached to this APO

Return values.

S_OK                                Object is locked and ready to process.
E_POINTER                           Invalid pointer passed to function.
APOERR_INVALID_CONNECTION_FORMAT    Invalid connection format.
APOERR_NUM_CONNECTIONS_INVALID      Number of input or output connections is not valid on
this APO.
Verifies that the APO is ready to process and locks its state if so . [ in ] number of input connections attached to this APO ppInputConnections - [ in ] connection descriptor of each input connection attached to this APO u32NumOutputConnections - [ in ] number of output connections attached to this APO ppOutputConnections - [ in ] connection descriptor of each output connection attached to this APO Return values . S_OK Object is locked and ready to process . E_POINTER Invalid pointer passed to function . APOERR_INVALID_CONNECTION_FORMAT Invalid connection format . APOERR_NUM_CONNECTIONS_INVALID Number of input or output connections is not valid on this APO .
STDMETHODIMP CDelayAPOMFX::LockForProcess(UINT32 u32NumInputConnections,
    APO_CONNECTION_DESCRIPTOR** ppInputConnections,  
    UINT32 u32NumOutputConnections, APO_CONNECTION_DESCRIPTOR** ppOutputConnections)
{
    ASSERT_NONREALTIME();
    HRESULT hr = S_OK;
    hr = CBaseAudioProcessingObject::LockForProcess(u32NumInputConnections,
        ppInputConnections, u32NumOutputConnections, ppOutputConnections);
    IF_FAILED_JUMP(hr, Exit);
    if (!IsEqualGUID(m_AudioProcessingMode, AUDIO_SIGNALPROCESSINGMODE_RAW) && m_fEnableDelayMFX)
    {
        m_nDelayFrames = FRAMES_FROM_HNS(HNS_DELAY);
        m_iDelayIndex = 0;
        m_pf32DelayBuffer.Free();
        m_pf32DelayBuffer.Allocate(GetSamplesPerFrame() * m_nDelayFrames);
        WriteSilence(m_pf32DelayBuffer, m_nDelayFrames, GetSamplesPerFrame());
        if (nullptr == m_pf32DelayBuffer)
        {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    }
Exit:
    return hr;
}
STDMETHODIMP CDelayAPOMFX :: LockForProcess ( UINT32 u32NumInputConnections , APO_CONNECTION_DESCRIPTOR * * ppInputConnections , UINT32 u32NumOutputConnections , APO_CONNECTION_DESCRIPTOR * * ppOutputConnections ) { ASSERT_NONREALTIME ( ) ; HRESULT hr = S_OK ; hr = CBaseAudioProcessingObject :: LockForProcess ( u32NumInputConnections , ppInputConnections , u32NumOutputConnections , ppOutputConnections ) ; IF_FAILED_JUMP ( hr , Exit ) ; if ( ! IsEqualGUID ( m_AudioProcessingMode , AUDIO_SIGNALPROCESSINGMODE_RAW ) && m_fEnableDelayMFX ) { m_nDelayFrames = FRAMES_FROM_HNS ( HNS_DELAY ) ; m_iDelayIndex = 0 ; m_pf32DelayBuffer . Free ( ) ; m_pf32DelayBuffer . Allocate ( GetSamplesPerFrame ( ) * m_nDelayFrames ) ; WriteSilence ( m_pf32DelayBuffer , m_nDelayFrames , GetSamplesPerFrame ( ) ) ; if ( nullptr == m_pf32DelayBuffer ) { hr = E_OUTOFMEMORY ; goto Exit ; } } Exit : return hr ; }
Description:
Verifies that the APO is ready to process and locks its state if so.
Description : Verifies that the APO is ready to process and locks its state if so .
// Allocate one second's worth of audio
 // 
 // This allocation is being done using CoTaskMemAlloc because the delay is very large
 // This introduces a risk of glitches if the delay buffer gets paged out
 //
 // A more typical approach would be to allocate the memory using AERT_Allocate, which locks the memory
 // But for the purposes of this APO, CoTaskMemAlloc suffices, and the risk of glitches is not important
