sndloop
Prev | Orchestra Opcodes and Operators | Next

## sndloop

sndloop — A sound looper with pitch control.

## Description

This opcode records input audio and plays it back in a loop with user-defined duration and crossfade time. It also allows the pitch of the loop to be controlled, including reversed playback.

## Syntax

    asig, krec sndloop ain, kpitch, ktrig, idur, ifad

## Initialization

idur -- loop duration in seconds

ifad -- crossfade duration in seconds

## Performance

asig -- output sig

krec -- 'rec on' signal, 1 when recording, 0 otherwise

kpitch -- pitch control (transposition ratio); negative values play the loop back in reverse

ktrig -- trigger signal: when 0, processing is bypassed. When switched on (ktrig >= 1), the opcode starts recording until the loop memory is full. It then plays the looped sound until it is switched off again (ktrig = 0). Another recording can start again with ktrig >= 1.

## Examples

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

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

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

    instr 1

    itrig  = p4
    asig   diskin2 "beats.wav", 1, 0, 1		;get the signal in, loop it
    ktrig  line 0, itrig, 1				;when to trigger signal = p4
    kpitch line 1.2, p3, .5				;vary pitch of recorded signal
    aout,krec sndloop asig, kpitch, ktrig, .4, 0.05	;rec starts at p4 sec, for .4 secs and 0.05 crossfade
           printk2 krec               	  	; prints the recording signal
           outs    aout, aout

    endin

    </CsInstruments>
    <CsScore>

    i1 0 5 .5	;trigger in seconds (=p4)
    i1 + 5 .8
    i1 + 10 1.2

    e
    </CsScore>
    </CsoundSynthesizer>

The example above shows the basic operation of sndloop. Pitch can be controlled at the k-rate, recording is started as soon as the trigger value is >= 1. Recording can be restarted by making the trigger 0 and then 1 again.

## Credits

Author: Victor Lazzarini
April 2005

New in Version 5.00

Prev | Up | Next
sndload | Home | sndwarp