polpo / picogus

Emulation of ISA sound cards on Raspberry Pi Pico (GUS, SB/Adlib, MPU-401, Tandy, CMS) with USB mouse/joystick support
GNU General Public License v2.0
518 stars 34 forks source link

Psuedocode for doing fast cubic spline interpolation (for better resampling quality) #2

Open 8bitbubsy opened 1 year ago

8bitbubsy commented 1 year ago

So I saw the talk about a possible cubic spline interpolator mode for PicoGUS, which would result in crisper audio with less treble being cut off from linear interpolation.

Here's some code I wrote that should work: https://pastebin.com/raw/Yvyh63VP

The only problem is that you need to input the correct sample points for the s0..s3 function parameters. This is slightly tricker than having to deal with just one extra sample (like with linear interpolation).

Here's what s0..s3 should be based on a few conditions (could be off, but something like this anyway).

Some notes first:

Non-looping sample:

Forward-looping sample:

Bidirectional-looping sample:

There could be some off-by-one (or bigger) errors here, so do experiment with it. If it's possible to sample backwards in "forward loop" mode, then it would also need more logic.

PS: I totally understand if this is too bothersome to implement, and that's fine. :-)

ramapcsx2 commented 1 year ago

Hey, I'm not part of this project, but I wonder what you think the performance / RAM impact of this will be :)

8bitbubsy commented 1 year ago

It ought to be quite faster than doing cubic spline without a table. RAM usage for the table is 4x512x2 (4096) bytes.

EDIT: Naturally it's slower than linear interpolation, but the quality improvement is quite good.