[pulseaudio-discuss] [PATCH 0/4] Add support for libsoxr resampler

Andrey Semashev andrey.semashev at gmail.com
Thu Nov 13 14:49:14 PST 2014


On Thursday 13 November 2014 11:32:09 you wrote:
> On Thu, Nov 13, 2014 at 8:33 AM, David Henningsson
> 
> <david.henningsson at canonical.com> wrote:
> > On 2014-11-11 22:39, Andrey Semashev wrote:
> >> In short, libsoxr is almost always faster than speex, and introduces much
> >> less distortions. Its passband frequency is slightly lower than speex
> >> though, and it can add a delay up to 20 ms in some cases.
> > 
> > I'm interested in knowing more about the delay. What are "some cases"?
> 
> "Some cases" means some sample rate combinations. In my tests I
> measured the delay of the resampler, and it was ~20 ms max. I don't
> have the results accessible now, I'll add them tonight to the results
> page.

Ok, here are some interesting results.

1. The delay does not depend on the input format (int16 vs float) or content. 
I tried with two different input pieces of content.

2. The delay _does_ depend on the input frame size (i.e. the amount of input 
samples you pass to the resampler in one chunk). I tested for frame sizes of 
20 and 100 samples per channel. There isn't a particularly obvious relation 
between the frame size and the delay.

3. The delay is typically lower for low quality presets (-lq, -mq), but that's 
not always the case.

4. The delay is typically lower for 2-fold sample rate conversions (i.e. 48kHz 
<-> 96kHz).

5. The delay varies in a wide range between different sample rate 
combinations. Different quality presets, on the other hand, are not as 
different. There are cases of 20 ms delay on all three -mq, -hq and -vhq 
presets, as well as there are cases of <5 ms.

6. With frame size 20 min/max delay values are:

   -mq: 1.917/20.604 ms
   -hq: 2.708/20.000 ms
   -vhq: 4.208/20.000 ms

  In case of 44.1 kHz, 16 bit, int -> 48 kHz it is 20.604/20.000/20.000 ms in 
the three presets.

7. With frame size 100 min/max delay values are:

   -mq: 2.771/12.336 ms
   -hq: 7.104/16.531 ms
   -vhq: 5.250/27.256 ms

  In case of 44.1 kHz, 16 bit, int -> 48 kHz it is 2.771/7.104/15.292 ms in 
the three presets.

  Note that 27.256 for -vhq in this case is larger than I stated in my initial 
announcement and the docs patch. I had not tested frame size 100 at that time. 
I will update the docs patch accordingly (probably, by describing the delay 
range more loosely).

I do not have an explanation for such diverse range of the delay value, and 
its dependency on the frame size. It doesn't look like the filter is 
"learning" from the input in some way since the delay doesn't depend on the 
content. Perhaps there is some extensive buffering in the implementation.

I can try and perform more tests with different frame sizes in attempt to 
determine the approximate maximum delay. I suspect, even after such testing is 
conducted I won't be absolutely sure that the discovered upper value won't 
ever be exceeded in some other case I did not cover. I can, however, test with 
the frame size that is used in PulseAudio, if such fixed or typical value 
exists (does it?).

For now the bottom line is that the exact delay of the resampler is difficult 
to predict, although it usually does not exceed 20 ms, except some rare cases 
and -vhq. When delay is critical it is better to use another resampler, like 
speex-5, for instance, which consistently stays below 1 ms across the board. 
But I think, such cases are quite specialized, and soxr is still very well 
applicable in general use.


The full results are available here, at the bottom of the page:

http://lastique.github.io/src_test/

The code of the test and the test waves are in git:

https://github.com/Lastique/src_test

If you want to reproduce the results:

1. Checkout the git repository. Warning: it does contain all the data you can 
see on the results page; it's a little short to 7 GiB in total on disk.
2. Build the test project (cmake, C++11, libsndfile-dev, libspeexdsp-dev and 
libsoxr-dev are required).
3. Checkout gh-pages branch. In the data/original folder there are the 
original signals used as input. You can use your own input files as well 
(uncompressed wavs, 16-bit int or 32-bit float).
4. Run the test project:

  ./src_test <input file> <resampler> <output sample rate> <output file>

  For example:

  ./src_test 44kHz_16-bit.wav soxr-hq 48000 soxr-hq-48kHz.wav

There is also test.sh in the master branch that can be used to automatically 
run all tests you can see on the results page.
5. You will see the measured delay value among the output of the test program.



More information about the pulseaudio-discuss mailing list