loscilx
Prev | Orchestra Opcodes and Operators | Next

## loscilx

loscilx — Read multi-channel sampled sound from a table.

## Description

Read sampled sound (up to 16 channels) from a table, with optional sustain and release looping.

## Syntax

    ar1 [, ar2, ar3, ar4, ar5, ar6, ar7, ar8, ar9, ar10, ar11, ar12, ar13, ar14, \
          ar15, ar16] loscilx xamp, kcps, ifn \
        [, iwsize, ibas, istrt, imod, ibeg, iend]

    ar[] loscilx xamp, kcps, ifn \
        [, iwsize, ibas, istrt, imod, ibeg, iend]

## Initialization

ifn -- function table number, typically denoting an sampled sound segment with prescribed looping points loaded using GEN01. The source file may have up to 16 channels.

iwsize (optional) -- window size used in interpolation. 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.

ibas (optional) -- base frequency in Hz of the recorded sound. This optionally overrides the frequency given in the audio file, but is required if the file did not contain one. The default value is 261.626 Hz, i.e. middle C. (New in Csound 4.03). If this value is not known or not present, use 1 here and in kcps.

istrt (optional, default 0) -- Frame to start reading the data. If this is not an integer the the data is interpolated (see iwsize).

imod (optional, default -1) -- play mode for the sustain and release loops. A value of 1 denotes normal looping, 2 denotes forward & backward looping, 0 denotes no looping. The default value (-1) will defer to the mode and the looping points given in the source file. Make sure you select an appropriate mode if the file does not contain this information.

ibeg, iend (optional, depending on imod) -- begin and end points of the sustain and release loops. These are measured in sample frames from the beginning of the file. If no loop points are specified, and a looping mode (imod is given, the file will be looped for the whole length.

## Performance

ar1, ar2, ... ar[] -- the output at audio-rate. The number of outputs must match the number of channels in the sample file.

xamp -- the amplitude of the output signal.

kcps -- the factor to read the file. For example, a value of 1 has no pitch change, 1.5 is up a fifth and 2 an octave.

loscilx samples the ftable audio at a rate determined by kcps, then multiplies the result by xamp. The sampling increment for kcps is dependent on the table's base-note frequency ibas, and is automatically adjusted if the orchestra sr value differs from that at which the source was recorded. In this unit, ftable is always sampled with interpolation.

If sampling reaches the sustain loop endpoint and looping is in effect, the point of sampling will be modified and loscil will continue reading from within that loop segment. Once the instrument has received a turnoff signal (from the score or from a MIDI noteoff event), the next sustain endpoint encountered will be ignored and sampling will continue towards the release loop end-point, or towards the last sample (henceforth to zeros).

If you want to loop the whole file, specify a looping mode in imod and do not enter any values for ibeg and iend.

## Examples

Here is an example of the loscilx opcode. It uses the files loscil.csd and kickroll.wav.

Example 520. Example of the loscilx 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     ;;;realtime audio out
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o loscil.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    kr = 44100
    ksmps = 1
    nchnls = 2
    0dbfs = 1.0

    gS_loop = "kickroll.wav"
    gisr filesr gS_loop
    gilength filelen gS_loop
    gibeats = 16
    gi_sampleleft ftgen 1, 0, 0, 1, gS_loop, 0, 4, 0

    instr 1
        idur = p3
        iamp = p4
        ibeat = p5
        itune = p6
        ipos = ibeat / gibeats * gilength * gisr

        aenv linseg iamp, idur - 0.01, iamp, 0.01, 0
        a1, a2 loscilx aenv, itune, 1, 0, 1, ipos, 0
        outs a1, a2
    endin

    </CsInstruments>
    <CsScore>

    t 0 170

    ; Measure 1
    i 1 0.0 0.5 0.707 0 1
    i 1 1.0 0.5 0.707 1 1
    i 1 2.5 0.5 0.707 0 1
    i 1 3.0 0.5 0.707 1 1

    ; Measure 2
    i 1 4.0 0.5 0.707 0 1
    i 1 5.0 0.5 0.707 1 1
    i 1 6.5 0.5 0.707 0 1
    i 1 7.0 0.5 0.707 1 1

    ; Measure 3
    i 1 8.0  0.5 0.707 0 1
    i 1 9.0  0.5 0.707 1 1
    i 1 10.5 0.5 0.707 0 1
    i 1 11.0 0.5 0.707 1 1

    ; Measure 4
    i 1 12.0 0.5 0.707 0 1
    i 1 13.0 0.5 0.707 1 1
    i 1 14.5 0.5 0.707 0 1
    i 1 15.0 0.5 0.707 1 1

    </CsScore>
    </CsoundSynthesizer>

## See Also

loscil

## Credits

Written by Istvan Varga.

2006

New in Csound 5.03

Array version new in Csound 6.13 (February 2019)

Prev | Up | Next
loscil3 | Home | lowpass2