HRESULT CTranscoder::ConfigureAudioOutput()
{
    assert (m_pProfile);

    HRESULT hr = S_OK;
    DWORD dwMTCount = 0;

    IMFCollection   *pAvailableTypes = NULL;
    IUnknown        *pUnkAudioType = NULL;
    IMFMediaType    *pAudioType = NULL;
    IMFAttributes   *pAudioAttrs = NULL;

    // Get the list of output formats supported by the Windows Media 
    // audio encoder.

    hr = MFTranscodeGetAudioOutputAvailableTypes(
        MFAudioFormat_WMAudioV9, 
        MFT_ENUM_FLAG_ALL, 
        NULL, 
        &pAvailableTypes
        );

    // Get the number of elements in the list.

    if (SUCCEEDED(hr))
    {
        hr = pAvailableTypes->GetElementCount( &dwMTCount );

        if (dwMTCount == 0)
        {
            hr = E_UNEXPECTED;
        }
    }

    // In this simple case, use the first media type in the collection.

    if (SUCCEEDED(hr))
    {
        hr = pAvailableTypes->GetElement(0, &pUnkAudioType);    
    }

    if (SUCCEEDED(hr))
    {
        hr = pUnkAudioType->QueryInterface(IID_PPV_ARGS(&pAudioType)); 
    }

    // Create a copy of the attribute store so that we can modify it safely.
    if (SUCCEEDED(hr))
    {
        hr = MFCreateAttributes(&pAudioAttrs, 0);     
    }

    if (SUCCEEDED(hr))
    {
        hr = pAudioType->CopyAllItems(pAudioAttrs);
    }

    // Set the encoder to be Windows Media audio encoder, so that the 
    // appropriate MFTs are added to the topology.

    if (SUCCEEDED(hr))
    {
        hr = pAudioAttrs->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_WMAudioV9);
    }
    
    // Set the attribute store on the transcode profile.
    if (SUCCEEDED(hr))
    {
        hr = m_pProfile->SetAudioAttributes( pAudioAttrs );
    }

    SafeRelease(&pAvailableTypes);
    SafeRelease(&pAudioType);
    SafeRelease(&pUnkAudioType);
    SafeRelease(&pAudioAttrs);

    return hr;
}