locked
Return value of IAudioClient::Initialize() RRS feed

  • Question

  • 	mOutputWFX.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
    
    	mOutputWFX.Format.wBitsPerSample = 16;
    	mOutputWFX.Format.nSamplesPerSec = 44100;
    	mOutputWFX.Format.nChannels = (ChannelsIndex*2) + 2;
    	mOutputWFX.Samples.wValidBitsPerSample = 16;
    
    	mOutputWFX.Format.nBlockAlign = mOutputWFX.Format.nChannels * (mOutputWFX.Format.wBitsPerSample / 8);
    	mOutputWFX.Format.nAvgBytesPerSec = mOutputWFX.Format.nSamplesPerSec * mOutputWFX.Format.nBlockAlign;
    	mOutputWFX.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
    	mOutputWFX.dwChannelMask = KSAUDIO_SPEAKER_STEREO;
    	mOutputWFX.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
    	
    	WAVEFORMATEX* wfxClosest;
    
    	hr = mpClient->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 0, 0, &mOutputWFX.Format, NULL);
    
    	if (FAILED(hr))
    	{
    
    		//Get the mix format of the device
    		mpClient->GetMixFormat(&wfxClosest);
    		if (wfxClosest == NULL)
    		{
    			SAFE_RELEASE(mpClient);
    			return E_OUTOFMEMORY;
    		}
    		hr = mpClient->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 0, 0, wfxClosest, NULL);
    
    	}

    The first call to Initialize() returns 0x88890008 (AUDCLNT_E_UNSUPPORTED_FORMAT)

    The second call to Initialise() returns 0x88890002 (AUDCLNT_E_ALREADY_INITIALIZED)

    AUDCLNT_E_UNSUPPORTED_FORMAT implies the call failed, if so how can the device be initialised?

    Thanks.


    • Edited by John_78f Monday, October 8, 2012 2:33 PM
    Monday, October 8, 2012 1:57 PM

Answers

  • It's partway initialized; you can either throw away that IAudioClient and activate a new one, or try IAudioClient::Reset, or use IAudioClient::IsFormatSupported(...) to probe format support rather than calling IAudioClient::Initialize(...) right away.

    Matthew van Eerde

    • Marked as answer by John_78f Wednesday, October 10, 2012 4:20 PM
    Monday, October 8, 2012 3:28 PM