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 3878 - New resampler: audible aliasing when upsampling 11k or 22k audio
Summary: New resampler: audible aliasing when upsampling 11k or 22k audio
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: audio (show other bugs)
Version: HG 2.0
Hardware: x86 Other
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-12 19:27 UTC by Eric Wasylishen
Modified: 2018-02-22 18:43 UTC (History)
1 user (show)

See Also:


Attachments
11025Hz wav with 5kHz sine wave (21.58 KB, audio/x-wav)
2017-10-12 19:27 UTC, Eric Wasylishen
Details
Another test case (21.58 KB, audio/x-wav)
2017-11-11 18:20 UTC, Eric Wasylishen
Details
Resampler w.i.p. (9.52 KB, patch)
2018-02-22 11:08 UTC, Eric Wasylishen
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Wasylishen 2017-10-12 19:27:12 UTC
Created attachment 2981 [details]
11025Hz wav with 5kHz sine wave

The new resampler seems to be letting too much aliasing through.
Here is a test case to see the problem:

testresample sine11025.wav sine44100.wav 44100 1
sox sine44100.wav -n spectrogram -o sine44100.png
open sine44100.png

You can hear the aliasing (warning, it's a loud / high pitched sine tone) - sine11025.wav contains a pure sine at 5kHz, but the resampled sine44100.wav will have an additional tone at 6kHz that's almost the same volume as the 5kHz one.

(There are other test cases you can use - e.g. generate 1 second of white noise at 11025Hz in Audacity and upsample it with testresample, or upsample the 22.05kHz test/sample.wav from SDL to 44.1kHz)
Comment 1 Eric Wasylishen 2017-11-11 18:20:55 UTC
Created attachment 3083 [details]
Another test case

Here is another test case I'm using, it's a sine sweep from 0 to 5.5kHz, at a 11025Hz sample rate.  Cases to test are upsampling to e.g. 44100 or 48000.

If the resampler is performing correctly, the spectrogram of the resampled file should show nothing much above 5.5kHz.

I'm working on a patch for this that lowers the cutoff frequency (currently it is at 0.5*inrate which is too high).
Comment 2 Ryan C. Gordon 2018-02-17 23:10:47 UTC
(In reply to Eric Wasylishen from comment #1)
> I'm working on a patch for this that lowers the cutoff frequency (currently
> it is at 0.5*inrate which is too high).

Did you ever make any progress on a patch? I'd like to get it into revision control.

Thanks,
--ryan.
Comment 3 Eric Wasylishen 2018-02-21 21:03:49 UTC
Sorry about neglecting this! 
Will try to dust off my patch later today or tomorrow and get back to you.
Comment 4 Sam Lantinga 2018-02-21 21:12:25 UTC
Thanks, we're trying to get a 2.0.8 RC tomorrow and would like to include this.
Comment 5 Eric Wasylishen 2018-02-22 11:08:10 UTC
Created attachment 3178 [details]
Resampler w.i.p.

Here's what I have as of tonight..

On the plus side, it fixes this bug,
https://bugzilla.libsdl.org/show_bug.cgi?id=3955
https://bugzilla.libsdl.org/show_bug.cgi?id=3956
and the quality seems good when resampling whole files using "testresample". Testing sine sweeps, upsampling and downsampling them, and looking at the spectrogram with sox.


On the downside, this is more of a rewrite than a small patch. 
I broke streaming (clicking artifact when doing:
    SDL_AUDIODRIVER=disk SDL_DISKAUDIOFILE=44100.raw FREQ=44100 ./test/loopwave some-96k-input.wav
using the patch to the disk driver from https://bugzilla.libsdl.org/show_bug.cgi?id=3848#c10 
), so the patch is not usable as-is. It's also ~2x as slow as what's currently in hg

Aside from fixing streaming, it could use some more documentation / tests / assertions against buffer overflows.
I can have a look on the weekend at fixing the streaming clicking problem and tidying it a bit more.
Comment 6 Sam Lantinga 2018-02-22 18:43:20 UTC
Okay, we'll hold off on this for 2.0.8.

Thanks!