diskin2
Prev | Orchestra Opcodes and Operators | Next

## diskin2

diskin2 — Reads audio data from a file, and can alter its pitch using one of several available interpolation types, as well as convert the sample rate to match the orchestra sr setting.

## Description

Reads audio data from a file, and can alter its pitch using one of several available interpolation types, as well as convert the sample rate to match the orchestra sr setting. diskin2 can also read multichannel files with any number of channels in the range 1 to 24. diskin2 allows more control and higher sound quality than diskin, but there is also the disadvantage of higher CPU usage.

## Syntax

    a1[, a2[, ... a24]] diskin2 ifilcod, kpitch[, iskiptim[, iwrap[, iformat [, iwsize[, ibufsize[, iskipinit]]]]]]

## Initialization

ifilcod -- integer or character-string denoting the source soundfile name. An integer denotes the file soundin.ifilcod; 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 those given by the environment variable SSDIR (if defined) then by SFDIR. See also GEN01. Note: files longer than 2^31-1 sample frames may not be played correctly on 32 bit platforms; this means a maximum length about 3 hours with a sample rate of 192000 Hz.

iskiptim (optional, defaults to zero) -- time in seconds of input sound to be skipped, assuming kpitch=1. Can be negative, to add -iskiptim/kpitch seconds of delay instead of skipping sound.

iwrap (optional, defaults to zero) -- if set to any non-zero value, read locations that are negative or are beyond the end of the file are wrapped to the duration of the sound file instead of assuming zero samples. Useful for playing a file in a loop.

| Note
If iwrap is enabled, the file length should not be shorter than the interpolation window size (see below), otherwise there may be clicks in the sound output.

iformat (optional, defaults to zero) -- sample format, for raw (headerless) files only. This parameter is ignored if the file has a header. Allowed values are:

- 0: 16-bit short integers

- 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

- 8: 24-bit int

- 9: 64-bit doubles

iwsize (optional, defaults to zero) -- interpolation window size, in samples. Can be one of the following:

- 1: round to nearest sample (no interpolation, for kpitch=1)

- 2: linear interpolation

- 4: cubic interpolation

- >= 8: iwsize point sinc interpolation with anti-aliasing (slow)

Zero or negative values select the default, which is cubic interpolation.

| Note
If interpolation is used, kpitch is automatically scaled by the ratio of the sample rate of the sound file and the orchestra, so that the file will always be played at the original pitch if kpitch is 1. However, the sample rate conversion is disabled if iwsize is 1.

ibufsize (optional, defaults to 0) -- buffer size in mono samples (not sample frames). This is only the suggested value, the actual setting will be rounded so that the number of sample frames is an integer power of two and is in the range 128 (or iwsize if greater than 128) to 1048576. The default, which is 4096, and is enabled by zero or negative values, should be suitable for most uses, but for non-realtime mixing of many large sound files, a high buffer setting is recommended to improve the efficiency of disk reads. For real time audio output, reading the files from a fast RAM file system (on platforms where this option is available) with a small buffer size may be preferred.

iskipinit (optional, defaults to 0) -- skip initialization if set to any non-zero value.

## 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.

| Note
It is more efficient to read a single file with many channels, than many files with only a single channel, especially with high iwsize settings.

kpitch -- transpose the pitch of input sound by this factor (e.g. 0.5 means one octave lower, 2 is one octave higher, and 1 is the original pitch). Fractional and negative values are allowed (the latter results in playing the file backwards, however, in this case the skip time parameter should be set to some positive value, e.g. the length of the file, or iwrap should be non-zero, otherwise nothing would be played). If interpolation is enabled, and the sample rate of the file differs from the orchestra sample rate, the transpose ratio is automatically adjusted to make sure that kpitch=1 plays at the original pitch. Using a high iwsize setting (40 or more) can significantly improve sound quality when transposing up, although at the expense of high CPU usage.

## Example

    <CsoundSynthesizer>
    <CsOptions>
    ; set this to a directory where beats.aiff can be found
    --env:SSDIR+=/Csound/Documentation/manual/examples
    </CsOptions>
    <CsInstruments>
    sr      =  48000
    ksmps   =  32
    nchnls  =  2

           instr 1

    ktrans  linseg 1, 5, 2, 10, -2
    a1      diskin2 "beats.aiff", ktrans, 0, 1, 0, 32
           outs a1, a1
           endin

    </CsInstruments>
    <CsScore>

    i 1 0 15
    e

    </CsScore>
    </CsoundSynthesizer>

## Credits

Author: Istvan Varga
2005

Prev | Up | Next
diskin | Home | dispfft