libsamplerate

In This Posting, I gave much thought, to how the ‘Digital Audio Workstation’ named QTractor might hypothetically do a sample-rate conversion.

I thought of several combinations, of “Half-Band Filters” that are based on the Sinc Function, and ‘Polynomial Smoothing’. The latter possibility would have often caused a computational penalty. But there was one, simpler combination of methods, which I did not think of.

QTractor uses a GPL Linux library named ‘libsamplerate‘. Its premise starts out with the idea, that a number of Half-Band Filters can be applied in correct sequences with 2x oversampling or 2x down-sampling, to achieve a variety of effects.

But then, ‘libsamplerate‘ does something ingenious in its simplicity: A Linear Interpolation! Linear interpolation will not offer as clean a spectrum as polynomial smoothing will in one step. But then, this library makes up for that, by just offering a finer resolution of oversampling, if the client application chooses it.

This library offers three quality levels:

  1. SRC_SINC_FASTEST
  2. SRC_SINC_MEDIUM_QUALITY
  3. SRC_SINC_BEST_QUALITY

 

Now, in This Posting, I identified an additional issue which arises, when we are doing an “Arbitrary Re-Sampling” and down-sampling. This issue was, that the source stream contains frequency components that are higher than the output stream Nyquist Frequency, and which need to be eliminated, even though the output stream is not in sync with the source stream.

To the best of my understanding, this problem can be solved, by making a temporary output stream 2x as fast as the final output stream, and then down-sampling by a factor of 2 again…

Sincerely,

Dirk

(Edit 07/21/2016 : ) The ‘GPL’ requires that this library be kept as free software, because it is in the nature of the GPL license, that any work derived from the code must also stay GPL, which stands of the “General Public License”.

But, because the possibility exists of some commercial exploitation being sought after, the Open-Source Software movement allows for a type of license, which is called the ‘LGPL’, which stands for the “Lesser General Public License”. The LGPL will allow for some software to be derived from the original code, which can be migrated into the private domain, so that the author of the derived code may close their source-code and sell their product for profit.

There exists a library similar to this one, that is named ‘libresample‘, with the express purpose that that one be LGPL code.

Yet, the authors of ‘libsamplerate‘ believe that this GPL version of the library is the superior one, which they would therefore have kept in the public domain.


 

Further, I think that a concept which should remain key is, that when interpolating, the source sample-rate should always be higher, than that of the samples which are not in sync, and whose values are taken ‘from someplace between the source samples’.

If this was not observed, the result would be that sometimes, two consecutive output samples are taken from the same linearly-interpolated segment derived from the input samples. If that was to happen, a type of artifact – i.e. noise – would result, which the subsequent down-sampling of the output stream cannot remove.

Hence, if the chosen quality-level was “SRC_SINC_FASTEST“, and if we were down-sampling like so:


48 kHz -> 44.1 kHz

It might be tempting to say, that ‘minimal sinc-filtering was applied‘, when a temporary output sample-rate of 88.2 kHz was being used to determine the points at which 48 kHz was being probed.

But according to what I claim to understand, the input sample-rate should then still be up-sampled to 96 kHz first, thus up-sampling it once, before points that are derived from the 88.2 kHz rate are probed from the input stream.

A failure on the part of the real programmers to do this, would disappoint me. This would mean that If the minimal quality level was chosen, Then to import a 48 kHz sample into a 44.1 kHz QTractor project, would do more damage, than if it was the other way around…

 

Print Friendly, PDF & Email

One thought on “libsamplerate”

Leave a Reply

Your email address will not be published. Required fields are marked *

Please Prove You Are Not A Robot *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>