diskin

diskin — Reads audio data from an external device or stream and can alter its pitch.

Description

Reads audio data from an external device or stream and can alter its pitch.

Syntax

ar1 [, ar2 [, ar3 [, ... arN]]] diskin ifilcod[, kpitch[, iskiptim \
      [, iwraparound[, iformat[, iskipinit]]]]]

Note the N was 24 in versions before 5.14, and 40 after.

ar1[] diskin ifilcod[, kpitch[, iskiptim \
      [, iwraparound[, iformat[, iskipinit]]]]]

(in this version, the number of output channels is not limited.)

Initialization

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) -- time in seconds of input sound to be skipped. The default value is 0.

iformat (optional) -- 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)

iwraparound -- 1 = on, 0 = off (wraps around to end of file either direction, enabling looping)

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

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.

Performance

a1 ... a24 -- output signals, in the range -0dbfs to 0dbfs. Any samples before the beginning (i.e. negative location) and after the end of the file are assumed to be zero, unless iwrap is non-zero. The number of output arguments must be the same as the number of sound file channels - which can be determined with the filenchnls opcode, otherwise an init error will occur.

ar1[] --- output signals, in a-rate array of size N, where N is the number of channels in the file. Arrays are automatically allocated to the correct size.

kpitch -- can be any real number. A negative number signifies backwards playback. The given number is a pitch ratio, where:

  • 1 = normal pitch (default)

  • 2 = 1 octave higher

  • 3 = 12th higher, etc.

  • .5 = 1 octave lower

  • .25 = 2 octaves lower, etc.

  • -1 = normal pitch backwards

  • -2 = 1 octave higher backwards, etc.

[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

Examples

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

Example 195. Example of the diskin opcode.

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

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;RT audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o diskin.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr     = 44100
ksmps  = 32
nchnls = 2
0dbfs  = 1

instr 1

ktrans linseg 1, 5, 2, 10, -2
a1     diskin "beats.wav", ktrans, 0, 1, 0, 32
       outs a1, a1

endin

</CsInstruments>
<CsScore>

i 1 0 15
e

</CsScore>
</CsoundSynthesizer>


See Also

in, inh, ino, inq, ins, soundin and diskin2

Credits

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

New in version 3.46

kpitch optional in version 6.06

Warning to Windows users added by Kevin Conder, April 2002