Resample utility

Description

This utility converts the sample rate of sound files. It is similar to the srconv utility included with Csound, however, it can be used in pipes (useful for e.g. downsampling the output of a Csound orchestra, that uses high sample rate to reduce aliasing, without writing large temporary files to disk), sound quality is better (with srconv, the maximum number of samples used for interpolation is 40, and a relatively small table is used with linear interpolation for the window function; by contrast, this utility allows window sizes up to 1024, and tables are used only when it does not reduce quality) and may be more stable. There are some disadvantages though: the range of supported file formats is limited (only raw or IRCAM, 16 bit integer or 32 bit float, and 1, 2, or 4 channels), and speed is considerably lower with non-integer resample ratio, when tables are not used.

Compiling

To compile and install the resample utility, first unpack the source package:

tar -xpzvf resample-1.1.tar.gz ; cd resample-1.1

Then check the makefile for installation settings. The CFLAGS environment variable can be used to set optimization, e.g.

export CFLAGS="-Wall -O2 -march=i686 -fno-gcse -ffast-math \
               -malign-functions=4 -malign-loops=4 -malign-jumps=4"

The program is compiled and installed with these commands:

make ; make install-strip

Command line options

The following command line options are available:

File names
-i <filename> Input file name. Default is to read from stdin.
-o <filename> Output file name. Default is to write to stdout.
Raw input file options
-r <sample rate> Sample rate of input file in Hz (default: 44100).
-s Short int (16 bit) samples.
-f Floating point (32 bit) samples. This is the default.
-cnn nn is the number of channels in input file. The allowed values for nn are 1 (mono), 2 (stereo), and 4 (quad).
Output file options
-R <sample rate> Sample rate of output file in Hz (default: 44100).
-S Write short int (16 bit) samples with dithering.
-F Write floating point (32 bit) samples (the default mode).
-J Write an IRCAM format sound file (the default is raw).
Resample settings
-qnn Set interpolation window size to nn. The allowed values for nn are 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, and 1024. Increasing nn improves quality at the expense of slower calculation. The default (and recommended for most uses) setting is 64.
nn Set resample ratio (output sample rate / input sample rate) to nn. This overrides any -R settings. nn is a floating point value that must be at least 0.0625 and at most 16. Note that an integer nn (or 1/nn) is considerably faster to calculate.
Misc. options
-v Verbose mode. By default, no messages (except errors) are printed.
-h Print program usage and exit.

Examples

Convert the sample rate of 16-bit, stereo raw input file test.pcm from 96 kHz to 44.1 kHz, and write output to test.sf, which is a floating point IRCAM file:

snd_resample -v -s -c2 -r 96000 -J -R 44100 -i test.pcm -o test.sf

Compile test.orc and test.sco with Csound, resample to 48000 Hz with interpolation quality set to 96, and store output in test2.sf (IRCAM, float):

csound -d -f -J -o stdout test.orc test.sco | \
snd_resample -q96 -R 48000 -J -o test2.sf

Download

The source code of the latest version can be downloaded here.

Back to utilities page

Back to home page