Columns

Weekly

Beginners

Synthesis

Processing

Real-Time

Departments

Links

Editorial

Contribute

Back Issues

Simple Sample Input

Hans Mikelson

hans@csounds.com

sample.orc sample.sco limit.wav (398K) algcmp.wav (345K)

Introduction

It is easy to use samples with Csound. In this article I introduce using the soundin and diskin opcodes. I demonstrate some typical sampler effects using these opcodes. Even very simple orchestras can yield interesting results.

Using Soundin

The following instrument illustrates use of the soundin opcode. It includes a declick envelope and panning. This instrument is used to read mono files at the same sample rate as the orchestra.

; Declick envelope
kamp linseg 0, .002, iamp, idur-.004, iamp, .002, 0

asig soundin isamp, iskip ; Sound input

; Declick, amplify, pan and output
outs asig*kamp*ipanl, asig*kamp*ipanr

This instrument can produce interesting results. You can download the samples "limit.wav" and "algcmp.wav" or use some of your own samples in the examples. The following score simply reads the sample file and outputs the result panned to the center.

;  Sta Dur Amp Pan Skip Sample
i1 0   2.0 1   .5  0    "limit.wav"

The next score does some sampler effects repeating a single word and panning it from left to right.

; Sample effects
;   Sta  Dur  Amp  Pan  Skip  Sample
i1  0    .2   1    .5   0     "limit.wav"
i1  +    .    .    1    .     "limit.wav"
i1  .    .    .    0    .     "limit.wav"
i1  .    .    .    1    .     "limit.wav"
i1  .    2.0  .    .5   .     "limit.wav"

i1  .    .1   1    .5   .8    "limit.wav"
i1  .    .    .    1    .     "limit.wav"
i1  .    .    .    0    .     "limit.wav"
i1  .    .    .    1    .     "limit.wav"
i1  .    1.2  .    .5   .     "limit.wav"

The skip time tells soundin at what point in time to start reading the sample. The following score simulates a ping pong echo by repeating a section and decreasing the volume a little each time.

; Simulated echo
;   Sta  Dur  Amp  Pan  Skip  Sample
i1  0    .4   1    .5   1.56  "limit.wav"
i1  +    .    .7   1    .     "limit.wav"
i1  .    .    .5   0    .     "limit.wav"
i1  .    .    .4   1    .     "limit.wav"
i1  .    .    .3   0    .     "limit.wav"
i1  .    .    .2   1    .     "limit.wav"
i1  .    .    .1   0    .     "limit.wav"

The next example is a type of simulated stereo created by delaying the right signal slightly compared to the left signal.

; Simulated stereo
;   Sta  Dur  Amp  Pan  Skip  Sample
i1  0    2.5  1    1    2.13  "limit.wav"
i1  .01  .    1    0    .     "limit.wav"

Using diskin

Diskin is more flexible than soundin because it allows you to change the pitch of the sample as you read it in.

krate oscil     irate, 1/idur, iratab
asig  diskin    isamp, krate, iskip, 1

This instrument reads the sample at the rate specified in the score. A table is used to modulate the base rate.

f10 0 1024 -7 1 1024 1
;   Sta  Dur  Amp  Pan  Skip  Sample       Rate  RtTable
i2  0    2.0  1    1    0     "limit.wav"  0.99  10
i2  0    2.0  1    0    0     "limit.wav"  1.01  10

In the above example a stereo effect is created by detuning the left and right channels. Table 10 is simply a constant 1. The next example plays back the sample at two different rates, first at a high pitch and then at a lower pitch.

;   Sta  Dur   Amp  Pan  Skip  Sample       Rate  RtTable
i2  0    3.09  1    .5   0     "limit.wav"  1.5   10
i2  +    3     1    .5   2     "limit.wav"  .75   10

The next example uses a table to vary the rate at which the sample is played back. When the table goes to a negative value the sample will be read backwards.

f11 0 1024 -7 1 224 1 100 0 50 .01 100 -1 200 -1 25 1 275 1.2 50 .01
;   Sta  Dur   Amp  Pan  Skip  Sample       Rate RtTable
i2  .5   10    1.5  .5   0     "algcmp.wav" 1    11

This can be used to create a sound effect like a record or tape being slowed down, sped up or stopped.

Instrument 3 uses an oscillator to modulate the rate at which the sound is read. At high frequencies this creates a robot voice effect, at medium frequencies it can create a vibrato and at low frequencies it can be used to create a chorus effect.

kfm   oscil     ifm, ifmrt, 1
krate =         kfm + irate
asig  diskin    isamp, krate, iskip, 1  ; Sound input

The following score produces a "robot voice" effect. Notice that the modulation frequencies are set to high values of 410 and 390. This modulates playback of the sample in the audio frequency.

;   Sta  Dur   Amp  Pan  Skip  Sample       Rate  FMAmt  FMFqc
i3  0    2.35  1    1    2.13  "limit.wav"  1     .4     410
i3  0    2.35  1    0    2.13  "limit.wav"  1     .4     390

The last example simulates a chorus effect by using a slow modulating frequency and playing back three signals simultaneously.

;   Sta  Dur   Amp  Pan  Skip  Sample       Rate  FMAmt  FMFqc
i3  0    2.35  .7   1    2.13  "limit.wav"  1     .03    4
i3  0    2.35  .7   0    2.13  "limit.wav"  1     .03    4
i3  0    2.35  .7   .5   2.13  "limit.wav"  1     0      1

Conclusion

The instruments in this section should provide the basis for many interesting effects. With a little effort you should be able to create instruments to slowly fade in and out samples, pan dynamically, pulse the amplitude of the sample and many other cool effects.