Scripts using Csound

A collection of various shell scripts is available in this package. These include:

[+] An utility to play sound files in any format supported by Csound, with floating point data automatically converted to 16 bit integers (rescale and dithering are also available).
[+] Print number of channels, sample rate, or length of sound files.
[+] Convert file (raw, WAVE, AIFF, or IRCAM) and sample (short int, float) formats.
[+] Extract from sound files, or insert silence to the beginning or end of file.
[+] Sample rate converter utilities.

It is recommended to install these scripts, as many other packages use them. Installation can be done with the included install.sh, or manually, by copying the following files to a directory that can be found in PATH:

PlaySound, SoundFileChannels, SoundFileLength, SoundFileSampleRate, SoundFileSamples, cs.sh, float2short, ircam2raw, raw2ircam, raw_snd_convert, raw_snd_extract, snd_convert, snd_downsample, snd_extract, snd_upsample.

In the Resample subdirectory, convolve files can be generated with these commands:

csound -d -f -J -o tmp.sf resamp2.orc resamp.sco
csound -U cvanal tmp.sf resample-2-32000Hz.cv
csound -d -f -J -o tmp.sf resamp4.orc resamp.sco
csound -U cvanal tmp.sf resample-4-32000Hz.cv
csound -d -f -J -o tmp.sf resamp8.orc resamp.sco
csound -U cvanal tmp.sf resample-8-32000Hz.cv
csound -d -f -J -o tmp.sf resamp16.orc resamp.sco
csound -U cvanal tmp.sf resample-16-32000Hz.cv


The resulting .cv files should be copied to SADIR.

Command line options

The usage of each script is described in the following table:

PlaySound <infile> [scale]

Play a sound file in any headered format supported by Csound (AIFF, WAVE, or IRCAM). When playing floating point files, audio data is converted to 16 bit integers with dithering.
<infile> Input file to be played.
[scale] Optional scale value, defaults to 1. If set to "-s", output sound is automatically rescaled to maximum amplitude.
SoundFileChannels <filename>

Print the number of channels in filename, with one leading and trailing space, and no newline character. If the file format cannot be recognized, 1 is printed.
SoundFileLength <filename>

Print the length of filename in seconds, with 6 decimal digits of precision. No leading or trailing space, or newline characters are printed. If the file format cannot be recognized, it is assumed to be raw 16-bit data, with 1 channel, and a sample rate of 44100 Hz.
SoundFileSampleRate <filename>

Print the sample rate of filename as an integer value, with no leading or trailing space, or newline characters. The default sample rate is 44100 Hz, if the file format is not recognized.
SoundFileSamples <filename>

Print the number of samples in filename. No leading or trailing space, or newline characters are printed. Files in unrecognized format are assumed to be 16-bit raw data (1 channel).
cs.sh <name>

Run the following command:
csound -d -m7 -H1 -f -J -b 4096 -B 4096 -o name.sf name.orc name.sco

cs.sh [ s | ms | f | mf ] <name> [infile]

Same as above, but s, or f can be used for short int, or float output, and ms, or mf to use a MIDI file named name.mid. infile is an optional input file to be used with -i.
float2short <infile> <outfile> [scale]

Convert infile to 16 bit WAVE format with dithering, and write to outfile. scale can be used to change amplitude (the default is 1).
ircam2raw <infile> <outfile>

Convert a headered sound file to raw float data.
raw2ircam <infile> <outfile> <nchnls> <sr>

Convert raw float data to IRCAM format sound file.
<infile> Input file name.
<outfile> Output file name.
<nchnls> Number of channels (1, 2, or 4).
<sr> Sample rate in Hz.
raw_snd_convert <infile> <outfile> <o_ffmt> <o_sfmt> <i_sfmt> <nchnls> <sr>

Convert raw sound file.
<infile> Input file name.
<outfile> Output file name.
<o_ffmt> Output file format (J: IRCAM, W: WAV, A: AIFF, h: raw).
<o_sfmt> Output sample format (s: short int, f: float).
<i_sfmt> Input sample format (s: short int, f: float).
<nchnls> Number of channels (1, 2, or 4).
<sr> Sample rate in Hz.
raw_snd_extract <infile> <outfile> <o_ffmt> <o_sfmt> <start_time> <duration> <i_sfmt> <nchnls> <sr>

Extract from raw sound file, and convert to other format.
<infile>, <outfile>, <o_ffmt>, <o_sfmt>, <i_sfmt>, <nchnls>, <sr> These parameters are the same as with raw_snd_convert.
<start_time> Start time in seconds to extract from input file. A negative value is allowed to add delay.
<duration> Length of output file in seconds. To read to the end of input file, set it to e.
snd_convert <infile> <outfile> <o_ffmt> <o_sfmt>

Convert headered sound file. The options are the same as in the case of raw_snd_convert, except the input file format does not have to be specified.
snd_extract <infile> <outfile> <o_ffmt> <o_sfmt> <start_time> <duration>

Extract from headered sound file, and convert to other format. Options are the same as with raw_snd_extract, but input file format is not specified, as it can be read from the header.
snd_downsample <infile> <outfile> <resample_ratio>

snd_upsample <infile> <outfile> <resample_ratio>

Convert sample rate of sound files.
<infile> Input file name.
<outfile> Output file name.
<resample_ratio> This parameter specifies the ratio of output and input sample rate when upsampling, or the ratio of input and output sample rate when downsampling. Allowed values are 2, 4, 8, and 16.

Back to utilities page

Back to home page