1<CsoundSynthesizer>
2<CsOptions>
3; Select audio/midi flags here according to platform
4-odac    ;;;realtime audio out
5;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
6; For Non-realtime ouput leave only the line below:
7; -o opcode_example.wav -W ;;; for file output any platform
8</CsOptions>
9<CsInstruments>
10
11sr = 44100
12ksmps = 32
13nchnls = 2
140dbfs  = 1
15
16/* example opcode 1: simple oscillator */
17
18        opcode Oscillator, a, kk
19
20kamp, kcps      xin             ; read input parameters
21a1      vco2 kamp, kcps         ; sawtooth oscillator
22        xout a1                 ; write output
23
24        endop
25
26/* example opcode 2: lowpass filter with local ksmps */
27
28        opcode Lowpass, a, akk
29
30        setksmps 1              ; need sr=kr
31ain, ka1, ka2   xin             ; read input parameters
32aout    init 0                  ; initialize output
33aout    =  ain*ka1 + aout*ka2   ; simple tone-like filter
34        xout aout               ; write output
35
36        endop
37
38/* example opcode 3: recursive call */
39
40        opcode RecursiveLowpass, a, akkpp
41
42ain, ka1, ka2, idep, icnt       xin     ; read input parameters
43        if (icnt >= idep) goto skip1    ; check if max depth reached
44ain     RecursiveLowpass ain, ka1, ka2, idep, icnt + 1
45skip1:
46aout    Lowpass ain, ka1, ka2           ; call filter
47        xout aout                       ; write output
48
49        endop
50
51/* example opcode 4: de-click envelope */
52
53        opcode DeClick, a, a
54
55ain     xin
56aenv    linseg 0, 0.02, 1, p3 - 0.05, 1, 0.02, 0, 0.01, 0
57        xout ain * aenv         ; apply envelope and write output
58
59        endop
60
61/* instr 1 uses the example opcodes */
62
63        instr 1
64
65kamp    =  .7                ; amplitude
66kcps    expon 50, p3, 500       ; pitch
67a1      Oscillator kamp, kcps                   ; call oscillator
68kflt    linseg 0.4, 1.5, 0.4, 1, 0.8, 1.5, 0.8  ; filter envelope
69a1      RecursiveLowpass a1, kflt, 1 - kflt, 10 ; 10th order lowpass
70a1      DeClick a1
71        outs a1, a1
72
73        endin
74
75
76</CsInstruments>
77<CsScore>
78
79i 1 0 4
80e5		;extra second before quitting
81
82</CsScore>
83</CsoundSynthesizer>
84