We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2551 - [xaudio2] poor quality when playing 11025hz sound compared to winmm/directsound
Summary: [xaudio2] poor quality when playing 11025hz sound compared to winmm/directsound
Status: RESOLVED WONTFIX
Alias: None
Product: SDL
Classification: Unclassified
Component: audio (show other bugs)
Version: HG 2.1
Hardware: x86_64 Windows 8
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-18 21:50 UTC by Eric Wasylishen
Modified: 2017-08-14 05:07 UTC (History)
0 users

See Also:


Attachments
sample audio file and recordings (812.08 KB, application/x-zip-compressed)
2014-05-18 21:50 UTC, Eric Wasylishen
Details
partial fix (1.47 KB, patch)
2014-05-19 07:32 UTC, Eric Wasylishen
Details | Diff
recording of sample.wav played back distorted by Xaudio2 (176.57 KB, audio/mpeg)
2015-03-26 21:53 UTC, Eric Wasylishen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Wasylishen 2014-05-18 21:50:34 UTC
Created attachment 1650 [details]
sample audio file and recordings

Tested with SDL-2.0.3-8746.zip on Windows 8.

Steps to reproduce:
- use the loopwave SDL2 sample app to play "440.wav" from the attached zipfile. This is an 8-bit 11025hz wav of a 440hz sinewave.
- Check that sdl is using the xaudio2 driver (look for INFO: Using audio driver: xaudio2 in stdout)

- Expected: should sound the same as playing 440.wav in a media player (e.g. vlc)
- Observed: There's a sort of ticking sound over the sine wave. I made a recording with audacity and attached it as 440-xaudio2-recording.wav.

I also tested the loopwave sample with the "winmm" and "directsound" drivers, by adding a line SDL_AudioInit("winmm"), and both of these drivers produce correct sounding output. For reference, I attached recordings made with these drivers as 440-directsound-recording.wav and 440-winmm-recording.wav.
Comment 1 Eric Wasylishen 2014-05-19 07:32:18 UTC
Created attachment 1652 [details]
partial fix

I investigated a bit more and came up with a partial fix; instead of resampling between the 'mastering voice' and device, I moved resampling to between the 'source voice' and 'mastering voice'.
Don't know why that works, but it gets rid of the worst distortion. It appears that this is an xaudio2 bug..

Unfortunately, the results still sound pretty bad. I recorded the output of playing my 440.wav file in loopwave, with this patch applied, and checking the frequency spectrum in audacity, there's still a lot of audio > 5kHz. There should be basically nothing over 5.5kHz since the input file is sampled 11025hz. The output with 'winmm' and 'directsound' are both correctly brickwalled at ~5.5kHz. Basically, xaudio2's resampler seems to suck, at least when given low sample rate input :-(

There's a mention in some DirectX release notes of what may be the same problem I'm seeing:

http://www.microsoft.com/en-us/download/details.aspx?id=5770

"In the March 2008 and later SDKs, the resampler in XAudio2 may introduce more aliasing for mono 16-bit source data compared to other formats. This is noticeable mostly on frequency changes larger than a factor of two. To workaround this issue, use a submix voice to implement the bulk of the frequency change."

I experimented with using a submix voice between the source voice and mastering voice, but it didn't seem to have any effect.
Comment 2 Eric Wasylishen 2015-03-12 20:00:20 UTC
Christian Knudsen also reported hitting the same issue on Windows 7, with 22050Hz sounds. "high frequencies getting a sharp/hissy tinge " was reported that went away when using 44100Hz, or avoiding Xaudio2 with SDL_AudioInit("winmm") or SDL_AudioInit("directsound ").

https://forums.libsdl.org/viewtopic.php?t=11092

I'm thinking the best solution would be for SDL to avoid using Xaudio2 if it's going to perform any resampling.
Comment 3 Eric Wasylishen 2015-03-26 21:53:00 UTC
Created attachment 2090 [details]
recording of sample.wav played back distorted by Xaudio2

Still reproducing on the latest HG. Here is a simpler way to repro:
- run the loopwave SDL2 sample app (no need to download the sound files I posted)
- Check that sdl is using the xaudio2 driver (look for INFO: Using audio driver: xaudio2 in stdout)

- Expected: jazz music plays (SDL/test/sample.wav), it sounds the same as playing the file in a media player (e.g. vlc)
- Observed: Bad distortion is heard over the music. Attached a recording of this, distorted.mp3
Comment 4 Sam Lantinga 2017-08-14 05:07:06 UTC
We're removing XAudio2 in favor of WASAPI after the 2.0.6 release.