Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WASAPI resampling when the sample rate significantly differs from the mix format #194

Merged
merged 1 commit into from
Nov 28, 2018

Conversation

cgutman
Copy link
Contributor

@cgutman cgutman commented Oct 14, 2018

My application is decoding incoming audio at a fixed 48 KHz sample rate and I'm depending on WASAPI resampling to handle conversion to the mix format. Right now, libsoundio is using AUDCLNT_STREAMFLAGS_RATEADJUST and IAudioClockAdjustment::SetSampleRate() to handle sample rates that differ from the native mix format.

However, when setting my mix format in the Sound Control Panel to 16-bit, 192 KHz, SetSampleRate() fails with E_INVALIDARG meaning "The sample rate is out of the range for the Audio Processing Object." according to MSDN. The amount of sample rate adjustment available using SetSampleRate() appears to be limited.

It seems that what we really want here is AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM which automatically handles sample rate conversion to the mix format. Using this flag fixes the 48 KHz -> 192 KHz resampling case.

To reproduce:

  1. Open Control Panel and click Sound
  2. Choose your default audio device and click Properties then the Advanced tab
  3. Select "16 bit, 192000 Hz"
  4. Play audio with libsoundio using a 48 KHz sample rate
  5. Note that soundio_outstream_open() fails with SoundIoErrorOpeningDevice

@cgutman
Copy link
Contributor Author

cgutman commented Nov 4, 2018

I've been shipping this code in production for a few weeks across several thousand Windows users (Win7 to Win10) and haven't received any more complaints from users with 192 KHz audio.

@andrewrk andrewrk merged commit fb23636 into andrewrk:master Nov 28, 2018
@andrewrk
Copy link
Owner

Hey thanks for submitting your changes upstream, and thanks for the follow-up to report that user testing worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants