locked
play audio buffer with IAudioClient

    Question

  • Hi, 

    I want to render audio buffer with IAudioClient, this is my code:

    	Platform::String^ id = Windows::Media::Devices::MediaDevice::GetDefaultAudioCaptureId( 
    											Windows::Media::Devices::AudioDeviceRole::Default );
    	ActivateAudioInterface( id->Data(), __uuidof( IAudioClient ), (void**)&m_pAudioClient);
    
    	REFERENCE_TIME hnsRequestedDuration = REFTIMES_PER_SEC;
        REFERENCE_TIME hnsActualDuration;
    	WAVEFORMATEX *pwfx = NULL;
    	HRESULT hr = m_pAudioClient->GetMixFormat(&pwfx);
        DX::ThrowIfFailed(hr);
    
    	try{
    		hr = m_pAudioClient->Initialize(
    			AUDCLNT_SHAREMODE_SHARED,
    			0,
    			hnsRequestedDuration,
    			hnsRequestedDuration,
    			pwfx,
    			NULL);
    	}
    	catch(Platform::Exception^ e)
    	{
    		OutputDebugString(L"open file failed");
    	}
    	DX::ThrowIfFailed(hr);

    It's OK to get the instance of audio client, but it hangs in "Initialize", does somebody know why?


    haha

    Tuesday, March 27, 2012 7:52 AM

Answers

  • Hello Wuyueduzun,

    I don't see where you are obtaining a pointer to your IMMDevice object.

    A client obtains a reference to an IAudioClient interface for an audio endpoint device by following these steps:

    1.By using one of the techniques described in IMMDevice Interface, obtain a reference to the IMMDevice interface for an audio endpoint device.
     
    2.Call the IMMDevice::Activate method with parameter iid set to REFIID IID_IAudioClient.
     
    The application thread that uses this interface must be initialized for COM. For more information about COM initialization, see the description of the CoInitializeEx function in the Windows SDK documentation.

    IAudioClient interface

    http://msdn.microsoft.com/en-us/library/windows/apps/dd370865.aspx

    Give this a try and let me know if it doesn't work for you.

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/


    Tuesday, March 27, 2012 7:37 PM
    Moderator

All replies

  • Hello Wuyueduzun,

    I don't see where you are obtaining a pointer to your IMMDevice object.

    A client obtains a reference to an IAudioClient interface for an audio endpoint device by following these steps:

    1.By using one of the techniques described in IMMDevice Interface, obtain a reference to the IMMDevice interface for an audio endpoint device.
     
    2.Call the IMMDevice::Activate method with parameter iid set to REFIID IID_IAudioClient.
     
    The application thread that uses this interface must be initialized for COM. For more information about COM initialization, see the description of the CoInitializeEx function in the Windows SDK documentation.

    IAudioClient interface

    http://msdn.microsoft.com/en-us/library/windows/apps/dd370865.aspx

    Give this a try and let me know if it doesn't work for you.

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/


    Tuesday, March 27, 2012 7:37 PM
    Moderator
  • Thanks.


    haha

    Wednesday, March 28, 2012 2:05 AM