soundin — Reads audio data from an external device or stream.


Reads audio data from an external device or stream. Up to 24 channels may be read.


ar1[, ar2[, ar3[, ... a24]]] soundin ifilcod [, iskptim] [, iformat] \
      [, iskipinit] [, ibufsize]


ifilcod -- integer or character-string denoting the source soundfile name. An integer denotes the file soundin.filcod; a character-string (in double quotes, spaces permitted) gives the filename itself, optionally a full pathname. If not a full path, the named file is sought first in the current directory, then in that given by the environment variable SSDIR (if defined) then by SFDIR. See also GEN01.

iskptim (optional, default=0) -- time in seconds of input sound to be skipped. The default value is 0. In csound 5.00 and later, this may be negative to add a delay instead of skipping time.

iformat (optional, default=0) -- specifies the audio data file format:

  • 1 = 8-bit signed char (high-order 8 bits of a 16-bit integer)

  • 2 = 8-bit A-law bytes

  • 3 = 8-bit U-law bytes

  • 4 = 16-bit short integers

  • 5 = 32-bit long integers

  • 6 = 32-bit floats

  • 7 = 8-bit unsigned int (not available in Csound versions older than 5.00)

  • 8 = 24-bit int (not available in Csound versions older than 5.00)

  • 9 = 64-bit doubles (not available in Csound versions older than 5.00)

iskipinit -- switches off all initialisation if non zero (default=0). This was introduced in 4_23f13 and csound5.

ibufsize -- buffer size in mono samples (not sample frames). Not available in Csound versions older than 5.00. The default buffer size is 2048.

If iformat = 0 it is taken from the soundfile header, and if no header from the Csound -o command-line flag. The default value is 0.


soundin is functionally an audio generator that derives its signal from a pre-existing file. The number of channels read in is controlled by the number of result cells, a1, a2, etc., which must match that of the input file. A soundin opcode opens this file whenever the host instrument is initialized, then closes it again each time the instrument is turned off.

There can be any number of soundin opcodes within a single instrument or orchestra. Two or more of them can read simultaneously from the same external file.

[Caution] Note to Windows users

Windows users typically use back-slashes, “\”, when specifying the paths of their files. As an example, a Windows user might use the path “c:\music\samples\loop001.wav”. This is problematic because back-slashes are normally used to specify special characters.

To correctly specify this path in Csound, one may alternately:

  • Use forward slashes: c:/music/samples/loop001.wav

  • Use back-slash special characters, “\\: c:\\music\\samples\\loop001.wav


Here is an example of the soundin opcode. It uses the file soundin.csd, beats.wav.

Example 433. Example of the soundin opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

; Select audio/midi flags here according to platform
; Audio out   Audio in    No messages
-odac           -iadc     -d     ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o soundin.wav -W ;;; for file output any platform

; Initialize the global variables.
sr = 44100
kr = 44100
ksmps = 1
nchnls = 1

; Instrument #1 - play an audio file.
instr 1
  asig soundin "beats.wav"
  out asig


; Play Instrument #1, the audio file, for three seconds.
i 1 0 3


See Also

diskin, in, inh, ino, inq, ins


Authors: Barry L. Vercoe, Matt Ingalls/Mike Berry
MIT, Mills College

Example written by Kevin Conder.

Warning to Windows users added by Kevin Conder, April 2002