CsoundManual - Previous section - Contents - Index - Next

SIGNAL MODIFIERS

     kr   linen         kamp, irise, idur, idec
     ar   linen         xamp, irise, idur, idec
     kr   linenr        kamp, irise, idec, iatdec
     ar   linenr        xamp, irise, idec, iatdec
     kr   envlpx        kamp, irise, idur, idec, ifn, iatss, iatdec[, ixmod]
     ar   envlpx        xamp, irise, idur, idec, ifn, iatss, iatdec[, ixmod]

     kr   port          ksig, ihtim[, isig]
     ar   tone          asig, khp[, istor]
     ar   atone         asig, khp[, istor]
     ar   reson         asig, kcf, kbw[, iscl, istor]
     ar   areson        asig, kcf, kbw[, iscl, istor]

     ar   butterhp      asig, kfreq [,iskip]
     ar   butterlp      asig, kfreq [,iskip]
     ar   butterbp      asig, kfreq, kband [,iskip]
     ar   butterbr      asig, kfreq, kband [,iskip]
   
     ar   nlfilt        ain, ka, kb, kd, kL, kC

krmsr,krmso,kerr,kcps lpread  ktimpnt, ifilcod [, inpoles][,ifrmrate] 
     ar   lpreson       asig 
     ar   lpfreson      asig, kfrqratio 
          lpslot        islot
          lpinterpol    islot1,islot2,kmix

     kr   rms           asig[, ihp, istor]
     nr   gain          asig, krms[, ihp, istor]
     ar   balance       asig, acomp[, ihp, istor]
     kr   follow        asig,  idt

     kr   downsamp      asig[, iwlen]
     ar   upsamp        ksig 
     ar   interp        ksig[, istor]
     kr   integ         ksig[, istor]
     ar   integ         asig[, istor]
     kr   diff          ksig[, istor]
     ar   diff          asig[, istor]
     kr   samphold      xsig, kgate[, ival, ivstor]
     ar   samphold      asig, xgate[, ival, ivstor]

     ar   delayr        idlt[, istor]
          delayw        asig
     ar   delay         asig, idlt[, istor]
     ar   delay1        asig[, istor]
     ar   deltap        kdlt
     ar   deltapi       xdlt
     ar   multitap      asig, itime1, igain1, itime2, igain2... 
     ar   vdelay        asig, adel, imaxdel  [, iskip]

     ar   comb          asig, krvt, ilpt[, istor]
     ar   alpass        asig, krvt, ilpt[, istor]
     ar   reverb        asig, krvt[, istor]
     ar   reverb2       asig, ktime, khdif [,iskip]
ar1[,ar2[,ar3[,ar4]]]  convolve   ain,ifilcod,channel


CsoundManual - Top of this section - Previous - Contents - Index - Next

linen, linenr, envlpx

     kr   linen     kamp, irise, idur, idec
     ar   linen     xamp, irise, idur, idec
     kr   linenr    kamp, irise, idec, iatdec
     ar   linenr    xamp, irise, idec, iatdec
     kr   envlpx    kamp, irise, idur, idec, ifn, iatss, iatdec[,ixmod]
     ar   envlpx    xamp, irise, idur, idec, ifn, iatss, iatdec[,ixmod] 


DESCRIPTION

linen - apply a straight line rise and decay pattern to an input amp signal.

linenr - apply a straight line rise, then an exponential decay while the note is extended in time.

envlpx - apply an envelope consisting of 3 segments: 1) stored function rise shape, 2) modified exponential pseudo steady state, 3) exponential decay

INITIALIZATION

irise - rise time in seconds. A zero or negative value signifies no rise modification.

idur - overall duration in seconds. A zero or negative value will cause initialization to be skipped.

idec - decay time in seconds. Zero means no decay. An idec > idur will cause a truncated decay.

ifn - function table number of stored rise shape with extended guard point.

iatss - attenuation factor, by which the last value of the envlpx rise is modified during the note's pseudo steady state. A factor > l causes an exponential growth, and < l an exponential decay. A 1 will maintain a true steady state at the last rise value. Note that this attenuation is not by fixed rate (as in a piano), but is sensitive to a note's duration. However, if iatss is negative (or if steady state < 4 k-periods) a fixed attenuation rate of abs(iatss) per second will be used. 0 is illegal.

iatdec - attenuation factor by which the closing steady state value is reduced exponentially over the decay period. This value must be positive and is normally of the order of .01. A large or excessively small value is apt to produce a cutoff which is audible. A zero or neg value is illegal.

ixmod (optional, between +- .9 or so) - exponential curve modifier, influencing the steepness of the exponential trajectory during the steady state. Values less than zero will cause an accelerated growth or decay towards the target (e.g. subito piano). Values greater than zero will cause a retarded growth or decay. The default value is zero (unmodified exponential).

PERFORMANCE

Rise modifications are applied for the first irise seconds, and decay from time idur - idec. If these periods are separated in time there will be a steady state during which amp will be unmodified (linen) or modified by the first exponential pattern (envlpx). If linen rise and decay periods overlap then both modifications will be in effect for that time; in envlpx that will cause a truncated decay. If the overall duration idur is exceeded in performance, the final decay will continue on in the same direction, going negative for linen but tending asymptotically to zero in envlpx.

linenr is unique within Csound in containing a note-off sensor and release time extender. When it senses either a score event termination or a MIDI noteoff, it will immediately extend the performance time of the current instrument by idec seconds, then execute an exponential decay towards the factor iatdec. For two or more units in an instrument, extension is by the greatest idec.


CsoundManual - Top of this section - Previous - Contents - Index - Next

port,tone, atone, reson, areson

     kr   port      ksig, ihtim[, isig]
     ar   tone      asig, khp[, istor]
     ar   atone     asig, khp[, istor]
     ar   reson     asig, kcf, kbw[, iscl, istor]
     ar   areson    asig, kcf, kbw[, iscl, istor] 


DESCRIPTION

A control or audio signal is modified by a low- or band-pass recursive filter with variable frequency response.

INITIALIZATION

isig - initial (i.e. previous) value for internal feedback. The default value is 0.

istor - initial disposition of internal data space. Since filtering incorporates a feedback loop of previous output, the initial status of the storage space used is significant. A zero value will clear the space; a non-zero value will allow previous information to remain. The default value is 0.

iscl - coded scaling factor for resonators. A value of 1 signifies a peak response factor of 1, i.e. all frequencies other than kcf are attenuated in accordance with the (normalized) response curve. A value of 2 raises the response factor so that its overall RMS value equals 1. (This intended equalization of input and output power assumes all frequencies are physically present; hence it is most applicable to white noise.) A zero value signifies no scaling of the signal, leaving that to some later adjustment ( see balance). The default value is 0.

PERFORMANCE

port applies portamento to a step-valued control signal. At each new step value, ksig is low-pass filtered to move towards that value at a rate determined by ihtim. ihtim is the "half-time" of the function (in seconds), during which the curve will traverse half the distance towards the new value, then half as much again, etc., theoretically never reaching its asymptote.

tone implements a first-order recursive low-pass filter in which the variable khp (in cps) determines the response curve's half-power point. Half power is defined as peak power / root 2.

reson is a second-order filter in which kcf controls the center frequency, or cps position of the peak response, and kbw controls its bandwidth (the cps difference between the upper and lower half-power points).

atone, areson are filters whose transfer functions are the complements of tone and reson. atone is thus a form of high-pass filter and areson a notch filter whose transfer functions represent the "filtered out" aspects of their complements. Note, however, that power scaling is not normalized in atone, areson, but remains the true complement of the corresponding unit. Thus an audio signal, filtered by parallel matching reson and areson units, would under addition simply reconstruct the original spectrum. This property is particularly useful for controlled mixing of different sources ( see lpreson).

Complex response curves such as those with multiple peaks can be obtained by using a bank of suitable filters in series. (The resultant response is the product of the component responses.) In such cases, the combined attenuation may result in a serious loss of signal power, but this can be regained by the use of balance.


CsoundManual - Top of this section - Previous - Contents - Index - Next

butterhp, butterlp, butterbp, butterbr

        ar      butterhp        asig, kfreq [,iskip]
        ar      butterlp        asig, kfreq [,iskip]
        ar      butterbp        asig, kfreq, kband [,iskip]
        ar      butterbr        asig, kfreq, kband [,iskip]


DESCRIPTION

Implementations of second-order hipass, lopass, bandpass and bandreject Butterworth filters.

PERFORMANCE

These new filters are butterworth second-order IIR filters. They are slightly slower than the original filters in Csound, but they offer an almost flat passband and very good precision and stopband attenuation.

asig - Input signal to be filtered.

kfreq - Cuttoff or center frequency for each of the filters.

kband - Bandwidth of the bandpass and bandreject filters.

iskip - Skip initialisation if present and non zero

EXAMPLE:

asig    rand      10000           ; White noise signal
alpf    butterlp  asig, 1000      ; cutting frequencies above1K
ahpf    butterhp  asig, 500       ; passing frequencies above 500Hz
abpf    butterbp  asig, 2000, 100 ; passing only 1950 to 2050 Hz
abrf    butterbr  asig, 4500, 200 ; cutting only 4400 to 4600 Hz


CsoundManual - Top of this section - Previous - Contents - Index - Next

nlfilt

    ar   nlfilt    ain, ka, kb, kd, kL, kC


DESCRIPTION

Implements the filter Y{n} =a Y{n-1} + b Y{n-2} + d Y^2{n-L} + X{n} - C described in Dobson and Fitch (ICMC'96)

EXAMPLE:

i) Non-linear effect:

        a = b = 0 
        d = 0.8, 0.9, 0.7
        C = 0.4, 0.5, 0.6
        L = 20

This affects the lower register most but there are audible effects over the whole range. We suggest that it may be useful for colouring drums, and for adding arbitrary highlights to notes

ii) Low Pass with non-linear:

        a = 0.4
        b = 0.2
        d = 0.7 
        C = 0.11
        L = 20, ... 200

There are instability problems with this variant but the effect is more pronounced of the lower register, but is otherwise much like the pure comb. Short values of L can add attack to a sound.

iii) High Pass with non-linear: The range of parameters are

        a = 0.35
        b = -0.3
        d = 0.95
        C = 0,2, ... 0.4
        L = 200

iv) High Pass with non-linear: The range of parameters are

        a = 0.7 
        b = -0.2, ... 0.5
        d = 0.9 
        C = 0.12, ... 0.24
        L = 500, 10

The high pass version is less likely to oscillate. It adds scintillation to medium-high registers. With a large delay L it is a little like a reverberation, while with small values there appear to be formant-like regions. There are arbitrary colour changes and resonances as the pitch changes. Works well with individual notes.

Warning: The "useful" ranges of parameters are not yet mapped.


CsoundManual - Top of this section - Previous - Contents - Index - Next

lpread, lpreson, lfreson

krmsr,krmso,kerr,kcps  lpread    ktimpnt, ifilcod[, inpoles][, ifrmrate] 
                   ar  lpreson   asig 
                   ar  lpfreson  asig, kfrqratio 


DESCRIPTION

These units, used as a read/reson pair, use a control file of time-varying filter coefficients to dynamically modify the spectrum of an audio signal.

INITIALIZATION

ifilcod - integer or character-string denoting a control-file (reflection coefficients and four parameter values) derived from n-pole linear predictive spectral analysis of a source audio signal. An integer denotes the suffix of a file lp.m; a character-string (in double quotes) gives a filename, optionally a full pathname. If not fullpath, the file is sought first in the current directory, then in that of the environment variable SADIR (if defined). Memory usage depends on the size of the file, which is held entirely in memory during computation but shared by multiple calls (see also adsyn, pvoc).

inpoles, ifrmrate (optional) - number of poles, and frame rate per second in the lpc analysis. These arguments are required only when the control file does not have a header; they are ignored when a header is detected. The default value for both is zero.

PERFORMANCE

lpread accesses a control file of time-ordered information frames, each containing n-pole filter coefficients derived from linear predictive analysis of a source signal at fixed time intervals (e.g. 1/100 of a second), plus four parameter values:

krmsr - root-mean-square (rms) of the residual of analysis, 
krmso - rms of the original signal, 
kerr  - the normalized error signal, 
kcps  - pitch in cps. 

lpread gets its values from the control file according to the input value ktimpnt (in seconds). If ktimpnt proceeds at the analysis rate, time-normal synthesis will result; proceeding at a faster, slower, or variable rate will result in time-warped synthesis. At each K-period, lpread interpolates between adjacent frames to more accurately determine the parameter values (presented as output) and the filter coefficient settings (passed internally to a subsequent lpreson).

The error signal kerr (between 0 and 1) derived during predictive analysis reflects the deterministic/random nature of the analyzed source. This will emerge low for pitched (periodic) material and higher for noisy material. The transition from voiced to unvoiced speech, for example, produces an error signal value of about .3. During synthesis, the error signal value can be used to determine the nature of the lpreson driving function: for example, by arbitrating between pitched and non-pitched input, or even by determining a mix of the two. In normal speech resynthesis, the pitched input to lpreson is a wideband periodic signal or pulse train derived from a unit such as buzz, and the nonpitched source is usually derived from rand. However, any audio signal can be used as the driving function, the only assumption of the analysis being that it has a flat response.

lpfreson is a formant shifted lpreson, in which kfrqratio is the (cps) ratio of shifted to original formant positions. This permits synthesis in which the source object changes its apparent acoustic size. lpfreson with kfrqratio = 1 is equivalent to lpreson.

Generally, lpreson provides a means whereby the time-varying content and spectral shaping of a composite audio signal can be controlled by the dynamic spectral content of another. There can be any number of lpread/lpreson (or lpfreson) pairs in an instrument or in an orchestra; they can read from the same or different control files independently.


CsoundManual - Top of this section - Previous - Contents - Index - Next

lpslot, lpinterpol

        lpslot     islot
        lpinterpol islot1,islot2,kmix


DESCRIPTION

Interpolate between two lpc analysis files.

INITIALIZATION

islot - number of slot to be selected [0<islot<20]

lpslot selects the slot to be use by further lp opcodes. This is the way to load and reference several analysis at the same time.

islot1 - slot where the first analysis was stored

islot2 - slot where the second analysis was stored

kmix - mix value between the two analysis. Should be between 0 and 1. 0 means analysis 1 only. 1 means analysis 2 only. Any value inbetween will produce interpolation between the filters.

lpinterpol computes a new set of poles from the interpolation between two analysis. The poles will be stored in the current lpslot and used by the next lpreson opcode.

EXAMPLE:

Here is a typical orc using the opcodes:

    ipower  init      50000          ; Define sound generator
    ifreq   init      440 
    asrc    buzz      ipower,ifreq,10,1

    ktime   line      0,p3,p3        ; Define time lin
            lpslot    0              ; Read square data poles
krmsr,krmso,kerr,kcps lpread  ktime,"square.pol"                     
            lpslot  1                ; Read triangle data poles
krmsr,krmso,kerr,kcps lpread  ktime,"triangle.pol"
    kmix    line      0,p3,1         ; Compute result of mixing
            lpinterp  0,1,kmix       ; and balance power
    ares    lpreson   asrc
    aout    balance   ares,asrc
            out       aout


CsoundManual - Top of this section - Previous - Contents - Index - Next

rms, gain, balance

     kr   rms       asig[, ihp, istor]
     nr   gain      asig, krms[, ihp, istor]
     ar   balance   asig, acomp[, ihp, istor] 


DESCRIPTION

The rms power of asig can be interrogated, set, or adjusted to match that of a comparator signal.

INlTlALIZATlON

ihp (optional) - half-power point (in cps) of a special internal low-pass filter. The default value is 10.

istor (optional) - initial disposition of internal data space ( see reson). The default value is 0.

PERFORMANCE

rms output values kr will trace the rms value of the audio input asig. This unit is not a signal modifier, but functions rather as a signal power-guage.

gain provides an amplitude modification of asig so that the output ar has rms power equal to krms. rms and gain used together (and given matching ihp values) will provide the same effect as balance.

balance outputs a version of asig, amplitude-modified so that its rms power is equal to that of a comparator signal acomp. Thus a signal that has suffered loss of power (eg., in passing through a filter bank) can be restored by matching it with, for instance, its own source. It should be noted that gain and balance provide amplitude modification only - output signals are not altered in any other respect.

EXAMPLE:

  asrc  buzz      10000,440, sr/440, 1   ; band-limited pulse train
  a1    reson     asrc, 1000,100         ; sent through
  a2    reson     a1,3000,500            ; 2 filters
  afin  balance   a2, asrc               ; then balanced with source


CsoundManual - Top of this section - Previous - Contents - Index - Next

follow

      kr   follow   asig,  idt


DESCRIPTION

Envelope follower unit generator.

INITIALIZATION

idt - This is the period, in seconds, that the average amplitude of asig is reported. If the frequency of asig is low then idt must be large (more than half the period of asig )

PERFORMANCE

asig - This is the signal from which to extract the envelope.

EXAMPLE:

   k1      line    0, p3, 30000    ; Make k1 a simple envelope
   a1      oscil   k1, 1000, 1     ; Make a simple signal using k1
   ak1     follow  a1, .02         ; ak1 is now like k1
   a2      oscil   ak1, 1000, 1    ; Make a simple signal using ak1
           out     a2              ; Both a1 and a2 are the same

To avoid zipper noise, by discontinuities produced from complex envelope tracking, a lowpass filter could be used, to smooth the estimated envelope.


CsoundManual - Top of this section - Previous - Contents - Index - Next

samphold downsamp, upsamp, interp, integ, diff, samphold

     kr   downsamp  asig[, iwlen]
     ar   upsamp    ksig 
     ar   interp    ksig[, istor]
     kr   integ     ksig[, istor]
     ar   integ     asig[, istor]
     kr   diff      ksig[, istor]
     ar   diff      asig[, istor]
     kr   samphold  xsig, kgate[, ival, ivstor]
     ar   samphold  asig, xgate[, ival, ivstor] 


DESCRIPTION

Modify a signal by up- or down-sampling, integration, and differentiation.

INITIALIZATION

iwlen (optional) - window length in samples over which the audio signal is averaged to determine a downsampled value. Maximum length is ksmps; 0 and 1 imply no window averaging. The default value is 0.

istor (optional) - initial disposition of internal save space ( see reson). The default value is 0.

ival, ivstor (optional) - controls initial disposition of internal save space. If ivstor is zero the internal "hold" value is set to ival ; else it retains its previous value. Defaults are 0,0 (i.e. init to zero)

PERFORMANCE

downsamp converts an audio signal to a control signal by downsampling. It produces one kval for each audio control period. The optional window invokes a simple averaging process to suppress foldover.

upsamp, interp convert a control signal to an audio signal. The first does it by simple repetition of the kval, the second by linear interpolation between successive kvals. upsamp is a slightly more efficient form of the assignment, `asig = ksig'.

integ, diff perform integration and differentiation on an input control signal or audio signal. Each is the converse of the other, and applying both will reconstruct the original signal. Since these units are special cases of low-pass and high-pass filters, they produce a scaled (and phase shifted) output that is frequency-dependent. Thus diff of a sine produces a cosine, with amplitude 2 * sin(pi * cps / sr) that of the original (for each component partial); integ will inversely affect the magnitudes of its component inputs. With this understanding, these units can provide useful signal modification.

samphold performs a sample-and-hold operation on its input according to the value of gate. If gate > 0, the input samples are passed to the output; If gate >= 0, the last output value is repeated. The controlling gate can be a constant, a control signal, or an audio signal.

EXAMPLE:

  asrc   buzz      10000,440,20, 1     ; band-limited pulse train
  adif   diff      asrc                ; emphasize the highs
  anew   balance   adif, asrc          ;   but retain the power
  agate  reson     asrc,0,440          ; use a lowpass of the original
  asamp  samphold  anew, agate         ;   to gate the new audiosig
  aout   tone      asamp,100           ; smooth out the rough edges


CsoundManual - Top of this section - Previous - Contents - Index - Next

delayr, delayw, delay, delay1

     ar   delayr    idlt[, istor]
          delayw    asig
     ar   delay          asig, idlt[, istor]
     ar   delay1    asig[, istor] 


DESCRIPTION

A signal can be read from or written into a delay path, or it can be automatically delayed by some time interval.

INITIALIZATION

idlt - requested delay time in seconds. This can be as large as available memory will permit. The space required for n seconds of delay is 4n * sr bytes. It is allocated at the time the instrument is first initialized, and returned to the pool at the end of a score section.

istor (optional) - initial disposition of delay-loop data space ( see reson). The default value is 0.

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.

delayw writes asig into the delay area established by the preceding delayr unit. Viewed as a pair, these two units permit the formation of modified feedback loops, etc. However, there is a lower bound on the value of idlt, which must be at least 1 control period (or 1/kr).

delay is a composite of the above two units, both reading from and writing into its own storage area. It can thus accomplish signal time-shift, although modified feedback is not possible. There is no minimum delay period.

delay1 is a special form of delay that serves to delay the audio signal asig by just one sample. It is thus functionally equivalent to "delay asig, 1/sr" but is more efficient in both time and space. This unit is particularly useful in the fabrication of generalized non-recursive filters.

EXAMPLE:

        tigoto    contin         ; except on a tie,
   a2   delay     a1, .05, 0     ; begin 50 msec clean delay of sig
   contin:


CsoundManual - Top of this section - Previous - Contents - Index - Next

deltap, deltapi

     ar   deltap    kdlt
     ar   deltapi   xdlt 


DESCRIPTION

Tap a delay line at variable offset times.

PERFORMANCE

These units can tap into a delayr/delayw pair, extracting delayed audio from the idlt seconds of stored sound. There can be any number of deltap and/or deltapi units between a read/write pair. Each receives an audio tap with no change of original amplitude.

deltap extracts sound by reading the stored samples directly; deltapi extracts sound by interpolated readout. By interpolating between adjacent stored samples deltapi represents a particular delay time with more accuracy, but it will take about twice as long to run.

The arguments kdlt, xdlt specify the tapped delay time in seconds. Each can range from 1 Control Period to the full delay time of the read/write pair; however, since there is no internal check for adherence to this range, the user is wholly responsible. Each argument can be a constant, a variable, or a time-varying signal; the xdlt argument in deltapi implies that an audio-varying delay is permitted there.

These units can provide multiple delay taps for arbitrary delay path and feedback networks. They can deliver either constant-time or time-varying taps, and are useful for building chorus effects, harmonizers, and doppler shifts. Constant-time delay taps (and some slowly changing ones) do not need interpolated readout; they are well served by deltap. Medium-paced or fast varying dlt's, however, will need the extra services of deltapi.

N.B. K-rate delay times are not internally interpolated, but rather lay down stepped time-shifts of audio samples; this will be found quite adequate for slowly changing tap times. For medium to fastpaced changes, however, one should provide a higher resolution audio-rate timeshift as input.

EXAMPLE:

  asource   buzz      1, 440, 20, 1 
  atime     linseg    1, p3/2,.01, p3/2,1 ; trace a distance in secs
  ampfac    =         1/atime/atime  ;     and calc an amp factor
  adump     delayr    1              ; set maximum distance 
  amove     deltapi   atime          ; move sound source past
            delayw    asource        ;     the listener
            out       amove * ampfac


CsoundManual - Top of this section - Previous - Contents - Index - Next

multitap

   ar   multitap   asig, itime1, igain1, itime2, igain2 . . . 


DESCRIPTION

Multitap delay line implementation.

INITIALIZATION

The arguments itime and igain set the position and gain of each tap.

The delay line is fed by asig.

EXAMPLE:

        a1      oscil        1000, 100, 1
        a2      multitap     a1, 1.2, .5, 1.4, .2
                out          a2

This results in two delays, one with length of 1.2 and gain of .5, and one with length of 1.4 and gain of .2.


CsoundManual - Top of this section - Previous - Contents - Index - Next

vdelay

        ar      vdelay  asig, adel, imaxdel  [, iskip]


DESCRIPTION

This is an interpolating variable time delay, it is not very different from the existing implementation (deltapi), it is only easier to use.

INITIALIZATION

imaxdel - Maximum value of delay in samples. If adel gains a value greater than imaxdel it is folded around imaxdel. This should not happen.

iskip - Skip initialisation if present and non zero

PERFORMANCE

With this unit generator it is possible to do Doppler effects or chorusing and flanging.

asig - Input signal.

adel - Current value of delay in samples. Note that linear functions have no pitch change effects. Fast changing values of adel will cause discontinuities in the waveform resulting noise.

EXAMPLE:

  f1 0 8192 10 1
  ims  =       100             ; Maximum delay time in msec
  a1   oscil   10000, 1737, 1  ; Make a signal
  a2   oscil   ims/2, 1/p3, 1  ; Make an LFO
  a2   =       a2 + ims/2      ; Offset the LFO so that it is positive
  a3   vdelay  a1, a2, ims     ; Use the LFO to control delay time
       out     a3

Two important points here. First, the delay time must be always positive. And second, even though the delay time can be controlled in k-rate, it is not advised to do so, since sudden time changes will create clicks.


CsoundManual - Top of this section - Previous - Contents - Index - Next

comb, alpass, reverb

     ar   comb      asig, krvt, ilpt[, istor]
     ar   alpass    asig, krvt, ilpt[, istor]
     ar   reverb    asig, krvt[, istor]


DESCRIPTION

An input signal is reverberated for krvt seconds with "colored" (comb), flat (alpass), or "natural room" (reverb) frequency response.

INITIALIZATION

ilpt - loop time in seconds, which determines the "echo density" of the reverberation. This in turn characterizes the "color" of the comb filter whose frequency response curve will contain ilpt * sr/2 peaks spaced evenly between 0 and sr/2 (the Nyquist frequency). Loop time can be as large as available memory will permit. The space required for an n second loop is 4n* sr bytes. comb and alpass delay space is allocated and returned as in delay.

istor (optional) - initial disposition of delay-loop data space ( cf. reson). The default value is 0.

PERFORMANCE

These filters reiterate input with an echo density determined by loop time ilpt. The attenuation rate is independent and is determined by krvt, the reverberation time (defined as the time in seconds for a signal to decay to 1/1000, or 60dB down from its original amplitude). Output from a comb filter will appear only after ilpt seconds; alpass output will begin to appear immediately.

A standard reverb unit is composed of four comb filters in parallel followed by two alpass units in series. Looptimes are set for optimal "natural room response." Core storage requirements for this unit are proportional only to the sampling rate, each unit requiring approximately 3K words for every 10KC. The comb, alpass, delay, tone and other Csound units provide the means for experimenting with alternate reverberator designs

Since output from the standard reverb will begin to appear only after 1/20 second or so of delay, and often with less than three-fourths of the original power, it is normal to output both the source and the reverberated signal. Also, since the reverberated sound will persist long after the cessation of source events, it is normal to put reverb in a separate instrument to which sound is passed via a global variable, and to leave that instrument running throughout the performance.

EXAMPLE:

     ga1  init 0              ; init an audio receiver/mixer
          instr     1         ; instr (there may be many copies)
     a1   oscili    8000, cpspch(p5), 1 ; generate a source signal
          out       a1        ; output the direct sound
     ga1  =         ga1 + a1  ; and add to audio receiver
          endin
          instr     99        ; (highest instr number executed last)
     a3   reverb    ga1, 1.5  ; reverberate whatever is in ga1
          out       a3        ; and output the result
     ga1  =         0         ; empty the receiver for the next pass
          endin


CsoundManual - Top of this section - Previous - Contents - Index - Next

reverb2

        ar      reverb2 asig, ktime, khdif [,iskip]


DESCRIPTION

This is a reverberator consisting of 6 parallel comb-lowpass filters being fed into a series of 5 allpass filters.

INITIALISATION

iskip - Skip initialisation if present and non zero

PERFORMANCE

The input signal asig is reverberated for ktime seconds. The parameter khdif controls the high frequency diffusion amount. The values of khdif should be from 0 to 1. If khdif is set to 0 the all the frequencies decay with the same speed. If khdif is 1, high frequencies decay faster that lower ones.

EXAMPLE:

        a1   oscil   10000, 100, 1
        a2   reverb2 a1, 2.5, .3
             out     a1 + a2 * .2

This results in a 2.5 sec reverb with faster high frequency attenuation.


CsoundManual - Top of this section - Previous - Contents - Index - Next

convolve

        ar1[,ar2[,ar3[,ar4]]]  convolve  ain, ifilcod, ichannel


DESCRIPTION

Output is the convolution of signal ain and the impulse response contained in ifilcod. If more than one output signal is supplied, each will be convolved with the same impulse response. Note that it is considerably more efficient to use one instance of the operator when processing a mono input to create stereo, or quad, outputs.

INITIALIZATION

ifilcod - integer or character-string denoting an impulse response data file. An integer denotes the suffix of a file convolve.m; a character string (in double quotes) gives a filename, optionally a full pathname. If not a fullpath, the file is sought first in the the current directory, then in the one given by the environment variable SADIR (if defined). The data file contains the Fourier transform of an impulse response. Memory usage depends on the size of the data file, which is read and held entirely in memory during computation, but which is shared by multiple calls.

PERFORMANCE

CONVOLVE implements Fast Convolution. The output of this operator is delayed with respect to the input. The following formulas should be used to calculate the delay:

For (1/kr) <= IRdur:
        Delay = ceil(IRdur * kr) / kr
For (1/kr) > IRdur: 
        Delay = IRdur * ceil(1/(kr*IRdur))
Where:
        kr  = Csound control rate
        IRdur = duration, in seconds, of impulse response
        ceil(n) = smallest integer not smaller than n

One should be careful to also take into account the initial delay, if any, of the impulse response. For example, if an impulse response is created from a recording, the soundfile may not have the initial delay included. Thus, one should either ensure that the soundfile has the correct amount of zero padding at the start, or, preferably, compensate for this delay in the orchestra. (the latter method is more efficient). To compensate for the delay in the orchestra, _subtract_ the initial delay from the result calculated using the above formula(s), when calculating the required delay to introduce into the 'dry' audio path.

For typical applications, such as reverb, the delay will be in the order of 0.5 to 1.5 seconds, or even longer. This renders the current implementation unsuitable for real time applications. It could conceivably be used for real time filtering however, if the number of taps is is small enough.

The author intends to create a higher-level operator at some stage, that would mix the wet & dry signals, using the correct amount of delay automatically.

EXAMPLE:

- Create frequency domain impulse response file:

  c:\> csound -Ucvanal l1_44.wav l1_44.cv

- Determine duration of impulse response. For high accuracy, determine the number of sample frames in the impulse response soundfile, and then compute the duration with:

  duration = (sample frames)/(sample rate of soundfile)

This is due to the fact that the SNDINFO utility only reports the duration to the nearest 10ms. If you have a utility that reports the duration to the required accuracy, then you can simply use the reported value directly.

  c:\> sndinfo l1_44.wav 
  length = 60822 samples, sample rate = 44100
 
  Duration = 60822/44100 = 1.379s.

- Determine initial delay, if any, of impulse response. If the impulse response has not had the initial delay removed, then you can skip this step. If it has been removed, then the only way you will know the initial delay is if the information has been provided separately. For this example, let's assume that the initial delay is 60ms. (0.06s)

- Determine the required delay to apply to the dry signal, to align it with the convolved signal:

 
  If kr = 441:
        1/kr = 0.0023, which is <= IRdur (1.379s), so:
        Delay1  = ceil(IRdur * kr) / kr
                = ceil(608.14) / 441
                = 609/441
                = 1.38s
        
  Accounting for the initial delay:
        Delay2  = 0.06s
  Total delay   = delay1 - delay2
                = 1.38 - 0.06
                = 1.32s

- Create .orc file, e.g:

 ; Simple demonstration of CONVOLVE operator, to apply reverb.
        sr = 44100
        kr = 441
        ksmps = 100
        nchnls = 2
        instr   1
imix = 0.22 ; Wet/dry mix. Vary as desired.
            ; NB: 'Small' reverbs often require a much higher
            ; percentage of wet signal to sound interesting. 'Large'
            ; reverbs seem require less. Experiment! The wet/dry mix is
            ; very important - a small change can make a large difference. 
ivol = 0.9  ; Overall volume level of reverb. May need to adjust 
            ; when wet/dry mix is changed, to avoid clipping.
idel = 1.32 ; Required delay to align dry audio with output of convolve.
            ; This can be automatically calculated within the orc file, 
            ; if desired.
adry            soundin "anechoic.wav"      ; input (dry) audio
awet1,awet2     convolve adry,"l1_44.cv"    ; stereo convolved (wet) audio
adrydel         delay   (1-imix)*adry,idel  ; Delay dry signal, to align it with 
                                          ; convolved signal. Apply level 
                                          ; adjustment here too.
                outs    ivol*(adrydel+imix*awet1),ivol*(adrydel+imix*awet2) 
                                          ; Mix wet & dry signals, and output
        endin


CsoundManual - Top of this section - Previous - Contents - Index - Next