| 1 |
/*Getting started.. 1.3 Basic Elements: Opcodes |
| 2 |
|
| 3 |
The fundamental building blocks of a Csound instrument is the opcode. |
| 4 |
Each opcode can be seen as little program itself, that does a specific task. Opcodes get a bold-blue highlighting in the CsoundQt editor. In this example 'line', 'expon', 'oscil', 'outvalue' and 'outs', are the opcodes used. |
| 5 |
|
| 6 |
The names of opcodes are usually a short form of their functionality. |
| 7 |
'line' - generates a linear changing value between specified points |
| 8 |
'expon' - generates a exponential curve between two points |
| 9 |
'oscil' - is a tone generator (an oscillator) |
| 10 |
'outvalue' - sends a value to a user defined channel, in this case to the widget display |
| 11 |
'outs' - writes stereo audio data to an external audio device |
| 12 |
|
| 13 |
It is important to remember that opcodes receive their input arguments on the right and output their results on the left, like this: |
| 14 |
|
| 15 |
output Opcode input1, input2 |
| 16 |
|
| 17 |
*/ |
| 18 |
|
| 19 |
<CsoundSynthesizer> |
| 20 |
<CsOptions> |
| 21 |
</CsOptions> |
| 22 |
<CsInstruments> |
| 23 |
|
| 24 |
sr = 44100 |
| 25 |
ksmps = 128 |
| 26 |
nchnls = 2 |
| 27 |
0dbfs = 1 |
| 28 |
|
| 29 |
instr 1 |
| 30 |
kFreq line 100, 5, 1000 ; 'line' generates a linear ramp, from 100-1000 Hz, taking 5 seconds |
| 31 |
aOut oscili 0.2, kFreq, 1 ; an oscillator whose frequency is taken from the value produced by 'line' |
| 32 |
outvalue "freqsweep", kFreq ; show the value from 'line' in a widget |
| 33 |
outs aOut, aOut ; send the oscillator's audio to the audio output |
| 34 |
endin |
| 35 |
|
| 36 |
|
| 37 |
instr 2 |
| 38 |
kFreq expon 100, 5, 1000 ; the 'expon' exponential curve is more useful when working with frequencies |
| 39 |
aOut oscili 0.2, kFreq, 1 |
| 40 |
outvalue "freqsweep", kFreq |
| 41 |
outs aOut, aOut |
| 42 |
endin |
| 43 |
|
| 44 |
</CsInstruments> |
| 45 |
<CsScore> |
| 46 |
f 1 0 1024 10 1 ; the basic sine waveform for the oscillator is generated here |
| 47 |
i 1 0 5 |
| 48 |
i 2 5 5 ; the exponential curve goes more even thought the octaves |
| 49 |
e |
| 50 |
</CsScore> |
| 51 |
</CsoundSynthesizer> |
| 52 |
; written by Alex Hofmann (Nov. 2009) - Incontri HMT-Hannover |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
<bsbPanel> |
| 58 |
<label>Widgets</label> |
| 59 |
<objectName/> |
| 60 |
<x>1013</x> |
| 61 |
<y>279</y> |
| 62 |
<width>563</width> |
| 63 |
<height>397</height> |
| 64 |
<visible>true</visible> |
| 65 |
<uuid/> |
| 66 |
<bgcolor mode="background"> |
| 67 |
<r>160</r> |
| 68 |
<g>158</g> |
| 69 |
<b>162</b> |
| 70 |
</bgcolor> |
| 71 |
<bsbObject type="BSBLabel" version="2"> |
| 72 |
<objectName/> |
| 73 |
<x>21</x> |
| 74 |
<y>7</y> |
| 75 |
<width>248</width> |
| 76 |
<height>71</height> |
| 77 |
<uuid>{8a703a13-1bbf-4338-8e0a-993e086a405e}</uuid> |
| 78 |
<visible>true</visible> |
| 79 |
<midichan>0</midichan> |
| 80 |
<midicc>-3</midicc> |
| 81 |
<description/> |
| 82 |
<label>This label displays the current frequency:</label> |
| 83 |
<alignment>left</alignment> |
| 84 |
<valignment>top</valignment> |
| 85 |
<font>Noto Sans</font> |
| 86 |
<fontsize>14</fontsize> |
| 87 |
<precision>3</precision> |
| 88 |
<color> |
| 89 |
<r>0</r> |
| 90 |
<g>0</g> |
| 91 |
<b>0</b> |
| 92 |
</color> |
| 93 |
<bgcolor mode="nobackground"> |
| 94 |
<r>255</r> |
| 95 |
<g>255</g> |
| 96 |
<b>255</b> |
| 97 |
</bgcolor> |
| 98 |
<bordermode>false</bordermode> |
| 99 |
<borderradius>1</borderradius> |
| 100 |
<borderwidth>0</borderwidth> |
| 101 |
</bsbObject> |
| 102 |
<bsbObject type="BSBDisplay" version="2"> |
| 103 |
<objectName>freqsweep</objectName> |
| 104 |
<x>108</x> |
| 105 |
<y>37</y> |
| 106 |
<width>144</width> |
| 107 |
<height>29</height> |
| 108 |
<uuid>{30e5e14c-4c4b-46a1-8584-d8d488ec61e9}</uuid> |
| 109 |
<visible>true</visible> |
| 110 |
<midichan>0</midichan> |
| 111 |
<midicc>-3</midicc> |
| 112 |
<description/> |
| 113 |
<label>409.663</label> |
| 114 |
<alignment>center</alignment> |
| 115 |
<valignment>center</valignment> |
| 116 |
<font>Sans Serif</font> |
| 117 |
<fontsize>16</fontsize> |
| 118 |
<precision>3</precision> |
| 119 |
<color> |
| 120 |
<r>0</r> |
| 121 |
<g>0</g> |
| 122 |
<b>0</b> |
| 123 |
</color> |
| 124 |
<bgcolor mode="background"> |
| 125 |
<r>182</r> |
| 126 |
<g>109</g> |
| 127 |
<b>0</b> |
| 128 |
</bgcolor> |
| 129 |
<bordermode>true</bordermode> |
| 130 |
<borderradius>1</borderradius> |
| 131 |
<borderwidth>1</borderwidth> |
| 132 |
</bsbObject> |
| 133 |
<bsbObject type="BSBScope" version="2"> |
| 134 |
<objectName/> |
| 135 |
<x>22</x> |
| 136 |
<y>365</y> |
| 137 |
<width>255</width> |
| 138 |
<height>150</height> |
| 139 |
<uuid>{3e0a7775-89a7-4f52-85ea-52e3ff2348b1}</uuid> |
| 140 |
<visible>true</visible> |
| 141 |
<midichan>0</midichan> |
| 142 |
<midicc>-3</midicc> |
| 143 |
<description/> |
| 144 |
<value>-255.00000000</value> |
| 145 |
<type>scope</type> |
| 146 |
<zoomx>2.00000000</zoomx> |
| 147 |
<zoomy>1.00000000</zoomy> |
| 148 |
<dispx>1.00000000</dispx> |
| 149 |
<dispy>1.00000000</dispy> |
| 150 |
<mode>0.00000000</mode> |
| 151 |
<triggermode>NoTrigger</triggermode> |
| 152 |
</bsbObject> |
| 153 |
<bsbObject type="BSBLabel" version="2"> |
| 154 |
<objectName/> |
| 155 |
<x>22</x> |
| 156 |
<y>313</y> |
| 157 |
<width>254</width> |
| 158 |
<height>53</height> |
| 159 |
<uuid>{f47b80f1-e5e6-4020-9065-17df4bb3ed44}</uuid> |
| 160 |
<visible>true</visible> |
| 161 |
<midichan>0</midichan> |
| 162 |
<midicc>-3</midicc> |
| 163 |
<description/> |
| 164 |
<label>The scope shows the current output-waveform.</label> |
| 165 |
<alignment>left</alignment> |
| 166 |
<valignment>top</valignment> |
| 167 |
<font>Noto Sans</font> |
| 168 |
<fontsize>14</fontsize> |
| 169 |
<precision>3</precision> |
| 170 |
<color> |
| 171 |
<r>0</r> |
| 172 |
<g>0</g> |
| 173 |
<b>0</b> |
| 174 |
</color> |
| 175 |
<bgcolor mode="nobackground"> |
| 176 |
<r>255</r> |
| 177 |
<g>255</g> |
| 178 |
<b>255</b> |
| 179 |
</bgcolor> |
| 180 |
<bordermode>false</bordermode> |
| 181 |
<borderradius>1</borderradius> |
| 182 |
<borderwidth>0</borderwidth> |
| 183 |
</bsbObject> |
| 184 |
<bsbObject type="BSBGraph" version="2"> |
| 185 |
<objectName/> |
| 186 |
<x>20</x> |
| 187 |
<y>180</y> |
| 188 |
<width>251</width> |
| 189 |
<height>109</height> |
| 190 |
<uuid>{17cbc48e-c1f3-4cae-aabc-d738a68aa532}</uuid> |
| 191 |
<visible>true</visible> |
| 192 |
<midichan>0</midichan> |
| 193 |
<midicc>-3</midicc> |
| 194 |
<description/> |
| 195 |
<value>0</value> |
| 196 |
<objectName2/> |
| 197 |
<zoomx>1.00000000</zoomx> |
| 198 |
<zoomy>1.00000000</zoomy> |
| 199 |
<dispx>1.00000000</dispx> |
| 200 |
<dispy>1.00000000</dispy> |
| 201 |
<modex>auto</modex> |
| 202 |
<modey>auto</modey> |
| 203 |
<showSelector>true</showSelector> |
| 204 |
<showGrid>true</showGrid> |
| 205 |
<showTableInfo>true</showTableInfo> |
| 206 |
<showScrollbars>true</showScrollbars> |
| 207 |
<enableTables>true</enableTables> |
| 208 |
<enableDisplays>true</enableDisplays> |
| 209 |
<all>true</all> |
| 210 |
</bsbObject> |
| 211 |
<bsbObject type="BSBLabel" version="2"> |
| 212 |
<objectName/> |
| 213 |
<x>21</x> |
| 214 |
<y>105</y> |
| 215 |
<width>251</width> |
| 216 |
<height>69</height> |
| 217 |
<uuid>{9e3bc813-428f-4648-b9cd-5084a7fbe634}</uuid> |
| 218 |
<visible>true</visible> |
| 219 |
<midichan>0</midichan> |
| 220 |
<midicc>-3</midicc> |
| 221 |
<description/> |
| 222 |
<label>The pure waveform used by the oscillator is visable in the Graph display.</label> |
| 223 |
<alignment>left</alignment> |
| 224 |
<valignment>top</valignment> |
| 225 |
<font>Noto Sans</font> |
| 226 |
<fontsize>14</fontsize> |
| 227 |
<precision>3</precision> |
| 228 |
<color> |
| 229 |
<r>0</r> |
| 230 |
<g>0</g> |
| 231 |
<b>0</b> |
| 232 |
</color> |
| 233 |
<bgcolor mode="nobackground"> |
| 234 |
<r>255</r> |
| 235 |
<g>255</g> |
| 236 |
<b>255</b> |
| 237 |
</bgcolor> |
| 238 |
<bordermode>false</bordermode> |
| 239 |
<borderradius>1</borderradius> |
| 240 |
<borderwidth>0</borderwidth> |
| 241 |
</bsbObject> |
| 242 |
</bsbPanel> |
| 243 |
<bsbPresets> |
| 244 |
</bsbPresets> |
| 245 |
<EventPanel name="" tempo="60.00000000" loop="8.00000000" x="320" y="218" width="596" height="322" visible="false" loopStart="0" loopEnd="0"> </EventPanel> |