Skip to content

delayr

Reads from an automatically established digital delay line.

Syntax

ares = delayr(idlt [, iskip])
ares, indx = delayr(idlt [, iskip])
ares delayr idlt [, iskip]
ares, indx delayr idlt [, iskip]

Initialization

idlt -- requested delay time in seconds, rounded to the nearest whole sample. The buffer must hold at least ksmps samples. Its size is limited by available memory and uses floatsize bytes per sample.

iskip (optional, default=0) -- when zero, clear the buffer and reset its position at initialization. A nonzero value preserves an existing buffer and its position during reinitialization, ignoring changes to idlt. The first initialization still allocates a buffer.

indx (optional output) -- an i-rate index for selecting this reader with a delay tap. See Selecting a delay line.

Performance

delayr reads from an automatically established digital delay line, in which the signal retrieved has been resident for idlt seconds. This unit must be paired with and precede an accompanying delayw unit. Any other Csound statements can intervene.

Examples

Selecting a delay line

The optional second output lets a tap select an earlier delayr even after another reader has appeared. Pass it as the optional final argument to deltap, deltapi, deltapn, deltap3, deltapx or deltapxw.

Tap indices select among readers that have initialized but have not yet paired with a delayw. The default index 0 selects the newest reader. Positive indices count back from it, so 1 selects the previous reader. Negative indices count from the oldest reader, with -1 selecting the oldest and -2 the next. An out-of-range index causes an initialization error.

delayr returns a negative index. That index records its position among the pending readers, rather than a permanent buffer identifier. Initializing a delayw removes the oldest reader from that list and changes the remaining negative indices. Initialize taps that use the returned indices before any intervening delayw. Each tap keeps its chosen reader during performance.

The example below opens two delay lines, then selects each with its returned index. Both taps come before the writers. The first delayw writes to the first delayr, and the second writes to the second. The index only selects a tap's reader and does not change writer order.

It uses the file delayr-index.csd.

Selecting two delay lines by index.
<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
  aEnv expon 0.2, p3, 0.00001
  aSource poscil aEnv, 220

  ; Keep both readers pending until all taps have initialized.
  aFullLeft, iLeft delayr 1
  aFullRight, iRight delayr 1
  ; Without the indices, both taps would select the second reader.
  aLeft deltapi 0.25, iLeft
  aRight deltapi 0.375, iRight

  ; Writers pair with readers in the order the readers appeared.
  delayw aSource + 0.5 * aLeft
  delayw aSource + 0.5 * aRight
  aFade linseg 1, p3 - 0.1, 1, 0.1, 0
  outs (aSource + aLeft) * aFade, (aSource + aRight) * aFade
endin
</CsInstruments>
<CsScore>
i 1 0 6
e
</CsScore>
</CsoundSynthesizer>

Feedback delay

Here is an example of the delayr opcode. It uses the file delayr.csd.

Example of the delayr opcode.
<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 delayr.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

gasig  init 0   
gidel  = 1              ;delay time in seconds

instr 1

ain  pluck .7, 440, 1000, 0, 1
     outs ain, ain

vincr gasig, ain        ;send to global delay
endin

instr 2 

ifeedback = p4  

abuf2   delayr  gidel
adelL   deltap  .4              ;first tap (on left channel)
adelM   deltap  1               ;second tap (on middle channel)
        delayw  gasig + (adelL * ifeedback)

abuf3   delayr  gidel
kdel    line    1, p3, .01      ;vary delay time
adelR   deltap  .65 * kdel      ;one pitch changing tap (on the right chn.)
        delayw  gasig + (adelR * ifeedback)
;make a mix of all deayed signals       
        outs    adelL + adelM, adelR + adelM

clear   gasig
endin

</CsInstruments>
<CsScore>

i 1 0 1
i 1 3 1
i 2 0 3  0      ;no feedback
i 2 3 8 .8      ;lots of feedback
e
</CsScore>
</CsoundSynthesizer>

See also

Delay