Debian Codegraph @

src/Examples/McCurdy Collection/Modulation/SimpleModulatorCarrier.csd

raw
1 ;Written by Iain McCurdy, 2006
2
3
4 ; Modified for QuteCsound by René, November 2010
5 ; Tested on Ubuntu 10.04 with csound-double cvs August 2010 and QuteCsound svn rev 733
6
7 ;Notes on modifications from original csd:
8 ; Cannot display more than one space in Label, so can't display the schematic shown below:
9
10 ; SIMPLIFIED SCHEMATIC FOR A MODULATOR AND CARRIER FM PAIR
11 ;----------------------------------------------------------
12 ;
13 ; +-----------+
14 ; | oscil |
15 ; |(modulator)|
16 ; +-----+-----+
17 ; |
18 ; |
19 ; |
20 ; |
21 ; |
22 ; +-----------+
23 ; | oscil |
24 ; | (carrier) |
25 ; +-----+-----+
26 ; |
27 ; |
28 ; OUT
29
30
31 ;my flags on Ubuntu: -iadc -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
32 <CsoundSynthesizer>
33 <CsOptions>
34
35 </CsOptions>
36 <CsInstruments>
37 sr = 44100 ;SAMPLE RATE
38 ksmps = 1 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
39 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
40
41
42 gisine ftgen 0, 0, 129, 10, 1 ;A SINE WAVE (INTERPOLATING OSCILLATOR OPCODES ARE USED THEREFORE A SMALL TABLE SIZE (+1) CAN BE USED)
43
44
45 instr 1 ;GUI
46 ktrig metro 10
47 if (ktrig == 1) then
48 gkModAmp invalue "Modulator_Amplitude"
49 gkCarrAmp invalue "Carrier_Amplitude"
50
51 gkModFreq invalue "Modulator_Frequency"
52 gkCarrFreq invalue "Carrier_Frequency"
53 endif
54 endin
55
56 instr 2
57 kporttime linseg 0,0.001,0.005,1,0.005 ;CREATE A VARIABLE FUNCTION THAT RAPIDLY RAMPS UP TO A SET VALUE
58 kModAmp portk gkModAmp, kporttime ;SMOOTH SLIDER VARIABLE
59 aModAmp interp kModAmp ;INTERPOLATE AND CREATE AN AUDIO RATE VERSION OF K-RATE VARIABLE
60
61 ;OUTPUT OPCODE AMPLITUDE |FREQUENCY |FUNCTION_TABLE
62 aModulator oscili aModAmp, gkModFreq, gisine ;DEFINE THE MODULATOR WAVEFORM
63 aCarrier oscili gkCarrAmp, gkCarrFreq+aModulator, gisine ;DEFINE THE CARRIER WAVEFORM (NOTE HOW ITS FREQUENCY IS MODULATED (THROUGH ADDITION) BY THE AUDIO OUTPUT OF THE MODULATOR WAVEFORM)
64 outs aCarrier, aCarrier ;SEND THE AUDIO OUTPUT OF THE CARRIER WAVEFORM *ONLY* TO THE OUTPUTS
65 dispfft aCarrier * 2, 0.1, 2048
66 endin
67 </CsInstruments>
68 <CsScore>
69 ;INSTR | START | DURATION
70 i 1 0 3600 ;GUI
71 </CsScore>
72 </CsoundSynthesizer>
73
74 <bsbPanel>
75 <label>Widgets</label>
76 <objectName/>
77 <x>463</x>
78 <y>221</y>
79 <width>1032</width>
80 <height>570</height>
81 <visible>true</visible>
82 <uuid/>
83 <bgcolor mode="background">
84 <r>241</r>
85 <g>226</g>
86 <b>185</b>
87 </bgcolor>
88 <bsbObject version="2" type="BSBLabel">
89 <objectName/>
90 <x>2</x>
91 <y>2</y>
92 <width>514</width>
93 <height>566</height>
94 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
95 <visible>true</visible>
96 <midichan>0</midichan>
97 <midicc>0</midicc>
98 <label> FM Synthesis: Simple Modulator->Carrier</label>
99 <alignment>center</alignment>
100 <font>Liberation Sans</font>
101 <fontsize>18</fontsize>
102 <precision>3</precision>
103 <color>
104 <r>255</r>
105 <g>255</g>
106 <b>255</b>
107 </color>
108 <bgcolor mode="background">
109 <r>5</r>
110 <g>27</g>
111 <b>150</b>
112 </bgcolor>
113 <bordermode>border</bordermode>
114 <borderradius>5</borderradius>
115 <borderwidth>2</borderwidth>
116 </bsbObject>
117 <bsbObject version="2" type="BSBLabel">
118 <objectName/>
119 <x>515</x>
120 <y>2</y>
121 <width>517</width>
122 <height>568</height>
123 <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
124 <visible>true</visible>
125 <midichan>0</midichan>
126 <midicc>0</midicc>
127 <label>FM Synthesis: Simple Modulator->Carrier</label>
128 <alignment>center</alignment>
129 <font>Liberation Sans</font>
130 <fontsize>18</fontsize>
131 <precision>3</precision>
132 <color>
133 <r>255</r>
134 <g>255</g>
135 <b>255</b>
136 </color>
137 <bgcolor mode="background">
138 <r>5</r>
139 <g>27</g>
140 <b>150</b>
141 </bgcolor>
142 <bordermode>border</bordermode>
143 <borderradius>5</borderradius>
144 <borderwidth>2</borderwidth>
145 </bsbObject>
146 <bsbObject version="2" type="BSBLabel">
147 <objectName/>
148 <x>519</x>
149 <y>20</y>
150 <width>510</width>
151 <height>547</height>
152 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
153 <visible>true</visible>
154 <midichan>0</midichan>
155 <midicc>0</midicc>
156 <label>----------------------------------------------------------------------------------------------------------------------------
157 This example demonstrates FM (frequency modulation) synthesis in its simplest form. Two oscillators are used (one will be referred to as the 'carrier' and the other as the 'modulator'). Both oscillators employ a sine wave shape (as is most often the case in FM synthesis). The frequency (pitch) of the carrier is modulated (through addition) by the audio output of the modulator. Only the audio output of the carrier will be present at the final audio outputs of the FM synthesis algorithm. (The modulator is heard indirectly through its influence upon the frequency of the carrier.) In this example the user is given direct control over the amplitudes and frequencies of the modulator and carrier oscillators. This is probably not the most useful design for FM synthesis but should provide a clearer idea of how the modulator and carrier interact. First of all adjust the carrier amplitude. Notice how this functions as a simple volume control. It has no effect on timbre. Next adjust the modulator amplitude. Notice how this varies the brightness or spectral intensity of the sound. When this is set at zero we are left with a pure sine tone (not silence!). When we vary the modulator and carrier frequencies this changes the nature of the timbre. (These parameters are adjusted by either clicking and dragging left and right on the values displayed or by clicking a cursor into the box and typing in a new value.) Notice how when the modulator and carrier frequencies are in simple ratio with one another harmonic spectra are produced. For example when M.F. (modulator frequency) is 300 Hz and when C.F. (carrier frequency) is 200. Notice how when M.F. and C.F. are not in simple ratio with one another inharmonic spectra are produced. For example when M.F. is 277 and C.F. is 200. Notice how when one frequency is slowly detuned away from a simple ratio with respect to the other a kind of timbral 'beating' is heard. As the amount of detuning increases the rate of beating increases until it is no longer perceivable. In general the modulator amplitude should be quite low in order to produce more interesting timbres that are not excessively shrill. As M.F. and C.F. are lowered the modulator amplitude should be also be lowered to maintain a constant spectral intensity. This is why in conventionally implemented FM synthesis a new parameter called 'the index of modulation' is derived that is directly proportional to the peak deviation (amplitude) of the modulator and inversely proportional to carrier modulator frequency. The next example makes use of the 'index of modulation' formula.</label>
158 <alignment>left</alignment>
159 <font>Arial</font>
160 <fontsize>14</fontsize>
161 <precision>3</precision>
162 <color>
163 <r>255</r>
164 <g>255</g>
165 <b>255</b>
166 </color>
167 <bgcolor mode="nobackground">
168 <r>255</r>
169 <g>255</g>
170 <b>255</b>
171 </bgcolor>
172 <bordermode>noborder</bordermode>
173 <borderradius>1</borderradius>
174 <borderwidth>1</borderwidth>
175 </bsbObject>
176 <bsbObject version="2" type="BSBButton">
177 <objectName/>
178 <x>8</x>
179 <y>6</y>
180 <width>100</width>
181 <height>30</height>
182 <uuid>{24979132-c53f-4414-ac6b-6b4f503ecfe8}</uuid>
183 <visible>true</visible>
184 <midichan>0</midichan>
185 <midicc>0</midicc>
186 <type>event</type>
187 <pressedValue>1.00000000</pressedValue>
188 <stringvalue/>
189 <text> ON / OFF</text>
190 <image>/</image>
191 <eventLine>i 2 0 -1</eventLine>
192 <latch>true</latch>
193 <latched>false</latched>
194 </bsbObject>
195 <bsbObject version="2" type="BSBDisplay">
196 <objectName>Modulator_Amplitude</objectName>
197 <x>448</x>
198 <y>63</y>
199 <width>60</width>
200 <height>30</height>
201 <uuid>{745d6bee-b951-4a03-9fe8-9e10d5ae4556}</uuid>
202 <visible>true</visible>
203 <midichan>0</midichan>
204 <midicc>0</midicc>
205 <label>668.000</label>
206 <alignment>right</alignment>
207 <font>Arial</font>
208 <fontsize>9</fontsize>
209 <precision>3</precision>
210 <color>
211 <r>255</r>
212 <g>255</g>
213 <b>255</b>
214 </color>
215 <bgcolor mode="nobackground">
216 <r>255</r>
217 <g>255</g>
218 <b>255</b>
219 </bgcolor>
220 <bordermode>noborder</bordermode>
221 <borderradius>1</borderradius>
222 <borderwidth>1</borderwidth>
223 </bsbObject>
224 <bsbObject version="2" type="BSBHSlider">
225 <objectName>Modulator_Amplitude</objectName>
226 <x>8</x>
227 <y>46</y>
228 <width>500</width>
229 <height>27</height>
230 <uuid>{06814721-6151-4baa-84e2-8f39843b07a4}</uuid>
231 <visible>true</visible>
232 <midichan>0</midichan>
233 <midicc>0</midicc>
234 <minimum>0.00000000</minimum>
235 <maximum>2000.00000000</maximum>
236 <value>668.00000000</value>
237 <mode>lin</mode>
238 <mouseControl act="jump">continuous</mouseControl>
239 <resolution>-1.00000000</resolution>
240 <randomizable group="0">false</randomizable>
241 </bsbObject>
242 <bsbObject version="2" type="BSBLabel">
243 <objectName/>
244 <x>8</x>
245 <y>63</y>
246 <width>180</width>
247 <height>30</height>
248 <uuid>{c6d7165c-6730-426f-b293-52b411bc73cf}</uuid>
249 <visible>true</visible>
250 <midichan>0</midichan>
251 <midicc>0</midicc>
252 <label>Modulator Amplitude</label>
253 <alignment>left</alignment>
254 <font>Arial</font>
255 <fontsize>10</fontsize>
256 <precision>3</precision>
257 <color>
258 <r>255</r>
259 <g>255</g>
260 <b>255</b>
261 </color>
262 <bgcolor mode="nobackground">
263 <r>255</r>
264 <g>255</g>
265 <b>255</b>
266 </bgcolor>
267 <bordermode>noborder</bordermode>
268 <borderradius>1</borderradius>
269 <borderwidth>1</borderwidth>
270 </bsbObject>
271 <bsbObject version="2" type="BSBLabel">
272 <objectName/>
273 <x>8</x>
274 <y>101</y>
275 <width>160</width>
276 <height>30</height>
277 <uuid>{f9f4369b-a39e-45aa-ba99-7457a534535f}</uuid>
278 <visible>true</visible>
279 <midichan>0</midichan>
280 <midicc>0</midicc>
281 <label>Carrier Amplitude</label>
282 <alignment>left</alignment>
283 <font>Arial</font>
284 <fontsize>10</fontsize>
285 <precision>3</precision>
286 <color>
287 <r>255</r>
288 <g>255</g>
289 <b>255</b>
290 </color>
291 <bgcolor mode="nobackground">
292 <r>255</r>
293 <g>255</g>
294 <b>255</b>
295 </bgcolor>
296 <bordermode>noborder</bordermode>
297 <borderradius>1</borderradius>
298 <borderwidth>1</borderwidth>
299 </bsbObject>
300 <bsbObject version="2" type="BSBHSlider">
301 <objectName>Carrier_Amplitude</objectName>
302 <x>8</x>
303 <y>84</y>
304 <width>500</width>
305 <height>27</height>
306 <uuid>{42fe25e5-e98f-4f00-872c-f791822a1b3e}</uuid>
307 <visible>true</visible>
308 <midichan>0</midichan>
309 <midicc>0</midicc>
310 <minimum>0.00000000</minimum>
311 <maximum>10000.00000000</maximum>
312 <value>3360.00000000</value>
313 <mode>lin</mode>
314 <mouseControl act="jump">continuous</mouseControl>
315 <resolution>-1.00000000</resolution>
316 <randomizable group="0">false</randomizable>
317 </bsbObject>
318 <bsbObject version="2" type="BSBDisplay">
319 <objectName>Carrier_Amplitude</objectName>
320 <x>448</x>
321 <y>101</y>
322 <width>60</width>
323 <height>30</height>
324 <uuid>{a8f35453-f236-447d-88d9-1a0b135383b6}</uuid>
325 <visible>true</visible>
326 <midichan>0</midichan>
327 <midicc>0</midicc>
328 <label>3360.000</label>
329 <alignment>right</alignment>
330 <font>Arial</font>
331 <fontsize>9</fontsize>
332 <precision>3</precision>
333 <color>
334 <r>255</r>
335 <g>255</g>
336 <b>255</b>
337 </color>
338 <bgcolor mode="nobackground">
339 <r>255</r>
340 <g>255</g>
341 <b>255</b>
342 </bgcolor>
343 <bordermode>noborder</bordermode>
344 <borderradius>1</borderradius>
345 <borderwidth>1</borderwidth>
346 </bsbObject>
347 <bsbObject version="2" type="BSBLabel">
348 <objectName/>
349 <x>47</x>
350 <y>187</y>
351 <width>150</width>
352 <height>30</height>
353 <uuid>{03adbcba-e8ca-4c98-9109-2ac9886e0a8e}</uuid>
354 <visible>true</visible>
355 <midichan>0</midichan>
356 <midicc>0</midicc>
357 <label>Carrier Frequency</label>
358 <alignment>right</alignment>
359 <font>Arial</font>
360 <fontsize>10</fontsize>
361 <precision>3</precision>
362 <color>
363 <r>255</r>
364 <g>255</g>
365 <b>255</b>
366 </color>
367 <bgcolor mode="nobackground">
368 <r>255</r>
369 <g>255</g>
370 <b>255</b>
371 </bgcolor>
372 <bordermode>noborder</bordermode>
373 <borderradius>1</borderradius>
374 <borderwidth>1</borderwidth>
375 </bsbObject>
376 <bsbObject version="2" type="BSBLabel">
377 <objectName/>
378 <x>47</x>
379 <y>149</y>
380 <width>150</width>
381 <height>30</height>
382 <uuid>{f8a79186-e423-4ebd-a512-4913282530b6}</uuid>
383 <visible>true</visible>
384 <midichan>0</midichan>
385 <midicc>0</midicc>
386 <label>Modulator Frequency</label>
387 <alignment>right</alignment>
388 <font>Arial</font>
389 <fontsize>10</fontsize>
390 <precision>3</precision>
391 <color>
392 <r>255</r>
393 <g>255</g>
394 <b>255</b>
395 </color>
396 <bgcolor mode="nobackground">
397 <r>255</r>
398 <g>255</g>
399 <b>255</b>
400 </bgcolor>
401 <bordermode>noborder</bordermode>
402 <borderradius>1</borderradius>
403 <borderwidth>1</borderwidth>
404 </bsbObject>
405 <bsbObject version="2" type="BSBSpinBox">
406 <objectName>Modulator_Frequency</objectName>
407 <x>198</x>
408 <y>150</y>
409 <width>70</width>
410 <height>28</height>
411 <uuid>{4a5191df-8241-43b7-a5ea-179231af25a4}</uuid>
412 <visible>true</visible>
413 <midichan>0</midichan>
414 <midicc>0</midicc>
415 <alignment>left</alignment>
416 <font>Liberation Sans</font>
417 <fontsize>14</fontsize>
418 <color>
419 <r>0</r>
420 <g>0</g>
421 <b>0</b>
422 </color>
423 <bgcolor mode="nobackground">
424 <r>255</r>
425 <g>255</g>
426 <b>255</b>
427 </bgcolor>
428 <resolution>0.50000000</resolution>
429 <minimum>0</minimum>
430 <maximum>20000</maximum>
431 <randomizable group="0">false</randomizable>
432 <value>200</value>
433 </bsbObject>
434 <bsbObject version="2" type="BSBSpinBox">
435 <objectName>Carrier_Frequency</objectName>
436 <x>198</x>
437 <y>188</y>
438 <width>70</width>
439 <height>28</height>
440 <uuid>{20d8a2f6-4a04-4050-8317-8e56207e9fe5}</uuid>
441 <visible>true</visible>
442 <midichan>0</midichan>
443 <midicc>0</midicc>
444 <alignment>left</alignment>
445 <font>Arial</font>
446 <fontsize>14</fontsize>
447 <color>
448 <r>0</r>
449 <g>0</g>
450 <b>0</b>
451 </color>
452 <bgcolor mode="nobackground">
453 <r>255</r>
454 <g>255</g>
455 <b>255</b>
456 </bgcolor>
457 <resolution>0.50000000</resolution>
458 <minimum>0</minimum>
459 <maximum>20000</maximum>
460 <randomizable group="0">false</randomizable>
461 <value>200</value>
462 </bsbObject>
463 <bsbObject version="2" type="BSBScope">
464 <objectName/>
465 <x>9</x>
466 <y>224</y>
467 <width>501</width>
468 <height>164</height>
469 <uuid>{221c0462-6fc0-482d-ba46-cf43d3b19d9c}</uuid>
470 <visible>true</visible>
471 <midichan>0</midichan>
472 <midicc>-3</midicc>
473 <value>-255.00000000</value>
474 <type>scope</type>
475 <zoomx>2.00000000</zoomx>
476 <zoomy>1.00000000</zoomy>
477 <dispx>1.00000000</dispx>
478 <dispy>1.00000000</dispy>
479 <mode>0.00000000</mode>
480 </bsbObject>
481 <bsbObject version="2" type="BSBGraph">
482 <objectName/>
483 <x>10</x>
484 <y>391</y>
485 <width>500</width>
486 <height>172</height>
487 <uuid>{2139f04b-aa23-4fd9-9a75-051daddbcb58}</uuid>
488 <visible>true</visible>
489 <midichan>0</midichan>
490 <midicc>0</midicc>
491 <value>0</value>
492 <objectName2/>
493 <zoomx>3.00000000</zoomx>
494 <zoomy>1.00000000</zoomy>
495 <dispx>1.00000000</dispx>
496 <dispy>1.00000000</dispy>
497 <modex>lin</modex>
498 <modey>lin</modey>
499 <all>true</all>
500 </bsbObject>
501 </bsbPanel>
502 <bsbPresets>
503 </bsbPresets>
504 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel>