Libsamplerate 2016

From HPC users
Revision as of 17:54, 15 March 2022 by Schwietzer (talk | contribs) (Created page with "== Introduction == Secret Rabbit Code (aka '''libsamplerate''') is a Sample Rate Converter for audio. One example of where such a thing would be useful is converting audio from the CD sample rate of 44.1kHz to the 48kHz sample rate used by DAT players. SRC is capable of arbitrary and time varying conversions, from downsampling by a factor of 256 to upsampling by the same factor. Arbitrary in this case means that the ratio of input and output sample rates can be an irrat...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction

Secret Rabbit Code (aka libsamplerate) is a Sample Rate Converter for audio. One example of where such a thing would be useful is converting audio from the CD sample rate of 44.1kHz to the 48kHz sample rate used by DAT players.

SRC is capable of arbitrary and time varying conversions, from downsampling by a factor of 256 to upsampling by the same factor. Arbitrary in this case means that the ratio of input and output sample rates can be an irrational number. The conversion ratio can also vary with time for speeding up and slowing down effects.

SRC provides a small set of converters to allow quality to be traded off against computation cost. The current best converter provides a signal-to-noise ratio of 145dB with -3dB passband extending from DC to 96% of the theoretical best bandwidth for a given pair of input and output sample rates. 1

In this Wiki article, we will refer to SRC always as libsamplerate.

Additionally to libsamplerate, this Wiki article contains information about sndfile-tools. They can be seen as an addition to libsamplerate and some tools were part of it before version 0.2.x.

Installed version(s)

The following versions are installed and currently available...

... on environment hpc-env/8.3:

  • libsamplerate/0.1.9-GCCcore-8.3.0
  • libsamplerate/0.2.2-GCCcore-8.3.0


  • sndfile-tools/1.5-GCCcore-8.3.0


Loading libsamplerate & sndfile-tools

To load the desired version of the module, use the module load command, e.g.

module load hpc-env/8.3
module load libsamplerate
module load sndfile-tools

Always remember: this commands are case sensitive!

Using libsamplerate

A side note first: Since libsamplerate can makle use of FLAC, you might be also interested in reading about our FLAC module, which is automatically loaded with libsamplerate and sndfile-tools and therefore can be also dedicately used.


Since libsamplerate itself does not have any binaries, it is mostly used as a library by other packages and tools, e.g. sndfile-tools. It might be worth mentioning though, that after loading the software module, you have access to an examples folder which might be of help for you:

ls $EBROOTLIBSAMPLERATE/examples

Using sndfile-tools

To find out on how to use the different sndfile-tools you can call the help function of every single tool. The tools are as follows (as of version 1.5):

  • sndfile-generate-chirp
  • sndfile-mix-to-mono
  • sndfile-resample
  • sndfile-spectrogram
  • sndfile-waveform


For example, just type in sndfile-generate-chirp --help after loading the module to print out a help text for this specific tool to get you started:

$ sndfile-generate-chirp --help

Create a sound file containing a swept sine wave (ie a chirp).

Usage :

    sndfile-generate-chirp  [options] <sample rate> <length in seconds> <sound file>

    Options include:

        -from <start>    Sweep start frequency in Hz (default 200Hz).
        -to <end>        Sweep end frequency in Hz (default fs/2).
        -amp <value>     Amplitude of generated sine (default 1.0).
        <sweep type>     One of (default -log):
                             -log     logarithmic sweep
                             -quad    quadratic sweep
                             -linear  linear sweep

        The <lengths in seconds> parameter can be a decimal like 1.5.

    The output file will contain floating point samples in the range [-1.0, 1.0].
    The output file type is determined by the file name extension which should be one
    of 'wav', 'aifc', 'aif', 'aiff', 'au', 'caf' and 'w64'.

Documentation

The full documentation of libsamplerate (aka Secret Rabbit Code) can be found here or at the github page.
The full documentation of sndfile-tools can be found here or at the github page.