Help - Search - Members - Calendar
Full Version: New resample library
Hydrogenaudio Forums > Hydrogenaudio Forum > General Audio
PatchWorKs
QUOTE
About

libinterp is a tiny library for real-time data interpolation, especially focused on sound resampling.

It is written in plain C and, as of now, it just offers three algorithms (zero order hold, linear and cubic splines calculated on 4 points), only on mono channels and only using regular float values for input and output.

However, you can already process multiple mono channels and switch algorithms and buffer sizes (thus also the output rate) on the fly.

For the (near or far) future I hope to add some sinc-based algorithms, (optional?) low-pass filtering when downsampling, optional limiting (maybe normalization?), support for other data encodings, maybe even support for interleaved data for multiple channels and some toy/simple analysis/example programs.

However this is a "part part time" thing, so I'm not working regularly on it. Contributions are very welcome.


Porting

As of now it works on Linux and BeOS (probably Haiku and Zeta too).

However, since the code is very platform neutral , you can easily port it to other operating systems as well. If you're interested, take a look at the configure.ac and include/libinterp/config.h files (those should be quite self-explaining).

Official website

NASPRO - NASPRO Architecture for Sound PROcessing, another cool project from the same author.
cabbagerat
I would certainly keep recommending the excellent libsamplerate instead of this library, at least for the moment. The MIT licence on this software might attract some people, though. The homepage for this resampler does link to libsamplerate, which is cool.

The choice of algorithms is fairly odd - ZOH is ok for quick and dirty resampling, but linear and cubic spline aren't particularly interesting. The implementation of a bandlimited interpolation procedure would make it useful for high fidelity audio resampling - including for fairly large rational rate changes (like 441/480). Libsamplerate includes an implementation of this already, including some extremely good optimisations.

NASPRO looks quite cool. It's going to be interesting to see where it goes in the future. Stephano D'Angelo is a name that I have been seeing attached to cool software for years and years.

When it comes to Free code, the more the merrier smile.gif
SebastianG
QUOTE(cabbagerat @ Dec 20 2007, 17:42) *

The choice of algorithms is fairly odd - ZOH is ok for quick and dirty resampling, but linear and cubic spline aren't particularly interesting.


Depending on your definition of "cubic spline" it might not even be "cubic spline" interpolation. In my book cubic splines lead to 2 times continously differentiable functions (C^2) whereas his interpolated function is not even once continously differentable. So, it's really not much better than linear interpolation (!)

The interested reader is referred to Image Interpolation and Resampling. Although the focus is on image interpolation the same principles apply to audio as well. A very interesting result is also mentioned: Interpolation via Splines of increasing orders converges to sinc interpolation. For audio, however, I suggest using spline interpolation on reasonably oversampled data only.

Cheers!
SG
Axon
What do you mean by "reasonably oversampled"? A high integral amount, like 8x?
cabbagerat
QUOTE(Axon @ Dec 20 2007, 14:54) *

What do you mean by "reasonably oversampled"? A high integral amount, like 8x?
Of course, using polynomial interpolation on oversampled data is unlikely to have computational advantages over using windowed Sinc interpolation on non-oversampled data. It is equivalent to windowed sinc interpolation using the binomial window[1], increasing the number of taps corresponds to the increasing the degree of the polynomial.

In the audio field bandlimited interpolation is perceptually problematic on some types of images and polynomial interpolation can look better. In audio, the opposite seems to be the case.

[1] Kootsookos and Williamson, "FIR Approximation of Fractional Sample Delay Systems," IEEE Transactions on Circuits and Systems, Feb 1996.
SebastianG
QUOTE(Axon @ Dec 20 2007, 14:54) *

What do you mean by "reasonably oversampled"? A high integral amount, like 8x?

I'm not sure either.

QUOTE(cabbagerat @ Dec 21 2007, 08:45) *

In the audio field bandlimited interpolation is perceptually problematic on some types of images and polynomial interpolation can look better. In audio, the opposite seems to be the case.

I really don't differentiate between "bandlimited interpolation" and "polynomial interpolation". In the end it's all the same: You convolve the digital signal with some function (windowed sinc or piece-wise polynomial) and sample it again. The only difference is that "bandlimited interpolation" is usually associated with reconstruction filters that have a rather "sharp" frequency cut-off. The libinterp "cubic" example also has a certain reconstruction filter -- a quite bad one even for a 3rd order polynomial I might add.

Of course, the requirements for audio and video differ. Requirements in terms of reconstruction filter properties.

Note that I'm not advocating (general!) polynomial interpolation. If anything it'd be B-Spline interpolation which is only a small subset of what you can do with polynomials in terms of interpolation. They approximate sinc quite well due to their smoothness.

Implementation-wise you can go wild by using cubic b-spline interpolation on oversampled lowpass filter taps. This is extremely usefull for very odd ratios like 5039:5051 or even non-rational ratios...


Cheers!
SG
cabbagerat
QUOTE(cabbagerat @ Dec 20 2007, 23:45) *

In the audio field bandlimited interpolation is perceptually problematic on some types of images and polynomial interpolation can look better.
I meant image processing instead of audio here. I need to edit my posts better. dry.gif Images with sharp edges and repetitive patterns can get some very strange looking artifacts when this kind of interpolation is used.

QUOTE(SebastianG @ Dec 21 2007, 05:38) *

Implementation-wise you can go wild by using cubic b-spline interpolation on oversampled lowpass filter taps. This is extremely usefull for very odd ratios like 5039:5051 or even non-rational ratios...
How do these approaches compare in SNR to computational requirements ratio to simple windowed sinc interpolation?

Edit: Strange triple post phenomenon.
SebastianG
QUOTE(cabbagerat @ Dec 21 2007, 20:50) *

QUOTE(SebastianG @ Dec 21 2007, 05:38) *

Implementation-wise you can go wild by using cubic b-spline interpolation on oversampled lowpass filter taps. This is extremely usefull for very odd ratios like 5039:5051 or even non-rational ratios...
How do these approaches compare in SNR to computational requirements ratio to simple windowed sinc interpolation?

I don't think there's a big difference qualitywise. Either you have a large table of all filter taps or a small table and interpolate the taps as needed. You trade flexibility and low memory usage with complexity. That's it.

Example: 44.1 kHz to 48 kHz. The intermediate rate (least common multiple) is 7,056.0 kHz. So you have to sample a lowpass filter's impulse response (cut off = 22.05 kHz) at 7,056.0 kHz which then would be 160 times oversampled. Instead you could sample the filter's impulse response at only 705.6 kHz (16 times oversampled) and use b-spline interpolation to compute the taps as needed.

A different approach would be to use an "FFT lowpass filter" on (a possibly zero-stuffed version of) the original to get an oversampled intermediate version and then to use b-spline interpolation. Whether it's really worth the hassle I don't know. It might be faster due to the fast convolution in the first stage.

There's more that one way to skin a cat ...


Cheers!
SG
cabbagerat
QUOTE(SebastianG @ Dec 21 2007, 12:13) *

Example: 44.1 kHz to 48 kHz. The intermediate rate (least common multiple) is 7,056.0 kHz. So you have to sample a lowpass filter's impulse response (cut off = 22.05 kHz) at 7,056.0 kHz which then would be 160 times oversampled. Instead you could sample the filter's impulse response at only 705.6 kHz (16 times oversampled) and use b-spline interpolation to compute the taps as needed.
Indeed, thanks.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.