question

TuckervonHolten-7173 avatar image
0 Votes"
TuckervonHolten-7173 asked ·

WASAPI IsFormatSupported succeeds but causes Initialize to fail

Is there a situation where IsFormatSupported will succeed but the input format will not actually be a valid format for an exclusive mode stream for audio?

I'm using WASAPI's Exclusive Mode stream to try to get raw audio data from the OS and would like to get it in IEEE float (for it's increased accuracy over s16 PCM). The IsFormatSupported passes without error using the format specified below, yet, when I call Initialize, I get back an error of 0x80070057. Has anyone experienced anything similar to this?

A snippet of my code is shown below (everything runs successfully except the last printf, which is never reached. The above error is thrown directly before that line is run):

     WAVEFORMATEXTENSIBLE pwfx_ex_back;
     pwfx = (WAVEFORMATEX *) &pwfx_ex_back;
     WAVEFORMATEXTENSIBLE *pwfx_ex = (WAVEFORMATEXTENSIBLE*) &pwfx_ex_back;
     pwfx->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
     pwfx->nChannels = 2;
     pwfx->nSamplesPerSec = 48000;
     pwfx->wBitsPerSample = 32;
     pwfx->nBlockAlign = (pwfx->nChannels * pwfx->wBitsPerSample) / 8;
     pwfx->nAvgBytesPerSec = pwfx->nChannels * pwfx->nSamplesPerSec * (pwfx->wBitsPerSample / 8);
     pwfx->cbSize = 22;
     pwfx_ex->Samples.wValidBitsPerSample = 32;
     pwfx_ex->dwChannelMask = 0x00000001 | 0x00000002;
     pwfx_ex->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
    
     print_waveformat(pwfx);
    
     write_headers_for_wav_file(wavfile, pwfx);
    
     WAVEFORMATEX **ppClosestMatch = NULL;
     hr = pAudioClient->IsFormatSupported(
         AUDCLNT_SHAREMODE_EXCLUSIVE,
         pwfx,
         NULL
     );
     EXIT_ON_ERROR(hr)
     printf("Closest match pointer-to-a-pointer value: %llx\n", (uint64_t) ppClosestMatch);
    
        
     REFERENCE_TIME phnsDefaultDevicePeriod;
     REFERENCE_TIME phnsMinimumDevicePeriod;
     hr = pAudioClient->GetDevicePeriod(
         &phnsDefaultDevicePeriod,
         &phnsMinimumDevicePeriod);
     EXIT_ON_ERROR(hr)
     printf("Default Period: %lli, Minimum Period: %lli\n", phnsDefaultDevicePeriod, phnsMinimumDevicePeriod);
    
     hr = pAudioClient->Initialize(
         AUDCLNT_SHAREMODE_EXCLUSIVE,
         0,
         60000, // 10 is 1 us, 10000 is 1 ms, 10000000 is 1 second, 0 is defaultminimumperiod for exclusive mode streams
         30000,
         pwfx,
         NULL
     );
     EXIT_ON_ERROR(hr)
    
     printf("Audioclient Initialized successfully.\n");
windows-api-graphics-media
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, @TuckervonHolten-7173

Please check this thread, and tell me if it is useful.

cbSize would be 0. Try that.



Thank you!

If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.







0 Votes 0 ·

1 Answer

7777 avatar image
0 Votes"
7777 answered ·

pwfx->wFormatTag = WAVE_FORMAT_EXTENSIBLE; // not WAVE_FORMAT_IEEE_FLOAT;

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.