;Written by Iain McCurdy, 2006 ; Modified for QuteCsound by René, November 2010 ; Tested on Ubuntu 10.04 with csound-double cvs August 2010 and QuteCsound svn rev 733 ;Notes on modifications from original csd: ; Add table(s) for exp slider ; Instrument 1 is activated by MIDI and by the GUI ; Removed presets (included in QuteCsound) ; Cannot display more than one space in Label, so can't display the schematic shown below: ; 2 MODULATORS AND A CARRIER FM SYNTHESIS ALGORITHM ; ------------------------------------------------- ; ; +-------------+ +-------------+ ; | oscil | | oscil | ; |(modulator 1)| |(modulator 2)| ; +-----+-------+ +-----+-------+ ; | | ; | | ; +---------+-------+ ; | ; | ; +-----+-----+ ; | oscil | ; | (carrier) | ; +-----+-----+ ; | ; | ; OUT ;my flags on Ubuntu: -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=alsa -Ma -m0 --midi-key-oct=4 --midi-velocity-amp=5 sr = 44100 ;SAMPLE RATE ksmps = 10 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO) 0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH gisine ftgen 0, 0, 4096, 10, 1 ;FUNCTION TABLE THAT STORES A SINGLE CYCLE OF A SINE WAVE giExp20000 ftgen 0, 0, 129, -25, 0, 20.0, 128, 20000.0 ;TABLES FOR EXP SLIDER instr 10 ;GUI ktrig metro 10 if (ktrig == 1) then kbasefreq invalue "Base_Frequency" gkbasefreq tablei kbasefreq, giExp20000, 1 outvalue "Base_Frequency_Value", gkbasefreq gkindex invalue "Modulation_Index_1" gkindex2 invalue "Modulation_Index_2" gkCarRatio invalue "Carrier_Frequency" gkModRatio invalue "Modulator1_Frequency" gkModRatio2 invalue "Modulator2_Frequency" gkCarAmp invalue "Carrier_Amplitude" gkndxatt invalue "Index1_Attack" gkndxdec invalue "Index1_Decay" gkndxslev invalue "Index1_Sustain" gkndxrel invalue "Index1_Release" gkndxdel invalue "Index1_Delay" gkndxatt2 invalue "Index2_Attack" gkndxdec2 invalue "Index2_Decay" gkndxslev2 invalue "Index2_Sustain" gkndxrel2 invalue "Index2_Release" gkndxdel2 invalue "Index2_Delay" gkampatt invalue "Amp_Attack" gkampdec invalue "Amp_Decay" gkampslev invalue "Amp_Sustain" gkamprel invalue "Amp_Release" gkampdel invalue "Amp_Delay" endif endin instr 1 ;FM INSTRUMENT if p4!=0 then ;MIDI ioct = p4 ;READ OCT VALUE FROM MIDI INPUT iamp = p5 ;READ midi-velocity-amp FROM MIDI INPUT kCarAmp = iamp * gkCarAmp ;SET AMPLITUDE TO RECEIVED p5 (I.E. MIDI VELOCITY) MULTIPLIED BY SLIDER "Carrier_Amplitude" ;PITCH BEND=========================================================================================================================================================== iSemitoneBendRange = 4 ;PITCH BEND RANGE IN SEMITONES imin = 0 ;EQUILIBRIUM POSITION imax = iSemitoneBendRange * .0833333 ;MAX PITCH DISPLACEMENT (IN oct FORMAT) kbend pchbend imin, imax ;PITCH BEND VARIABLE (IN oct FORMAT) kbasefreq = cpsoct(ioct + kbend) ;SET FUNDEMENTAL FROM MIDI ;===================================================================================================================================================================== else ;GUI kbasefreq = gkbasefreq ;SET FUNDEMENTAL FROM GUI SLIDER "Base_Frequency" kCarAmp = gkCarAmp ;SET kamp TO SLIDER VALUE "Carrier_Amplitude" endif kporttime linseg 0,0.001,0.02 ;CREATE A VARIABLE FUNCTION THAT RAPIDLY RAMPS UP TO A SET VALUE kbasefreq portk kbasefreq, kporttime kndxenv madsr i(gkndxatt), i(gkndxdec), i(gkndxslev) + .0000001, i(gkndxrel) , i(gkndxdel) ;LINE SEGMENT ENVELOPE WITH MIDI RELEASE MECHANISM kndxenv2 madsr i(gkndxatt2), i(gkndxdec2), i(gkndxslev2) + .0000001, i(gkndxrel2) , i(gkndxdel2) ;LINE SEGMENT ENVELOPE WITH MIDI RELEASE MECHANISM kpeakdeviation = kbasefreq * gkindex * kndxenv ;DERIVE PEAK DEVIATION FOR MODULATOR 1 kpeakdeviation2 = kbasefreq * gkindex2 * kndxenv2 ;DERIVE PEAK DEVIATION FOR MODULATOR 1 aModulator oscili kpeakdeviation, kbasefreq * gkModRatio, gisine ;CREATE MODULATOR 1 aModulator2 oscili kpeakdeviation2, kbasefreq * gkModRatio2, gisine ;CREATE MODULATOR 2 aampenv mxadsr i(gkampatt), i(gkampdec), i(gkampslev) + .0000001, i(gkamprel) , i(gkampdel) ;EXPONENTIAL SEGMENT ENVELOPE WITH MIDI RELEASE MECHANISM aCarrier oscili kCarAmp * aampenv, (kbasefreq * gkCarRatio) + aModulator + aModulator2, gisine ;CREATE CARRIER (ADD MODULATOR OUTPUTS TO FREQUENCY INPUT) outs aCarrier, aCarrier ;SEND AUDIO TO OUTPUTS endin instr 2 ;INIT ;OPCODE DESTINATION | VALUE outvalue "Base_Frequency", 0.4035705 ;325 Hz outvalue "Modulation_Index_1", 5.0 outvalue "Modulation_Index_2", 0.702 outvalue "Carrier_Frequency", 1.0 outvalue "Modulator1_Frequency", 1.377 outvalue "Modulator2_Frequency", 1.3853 outvalue "Carrier_Amplitude", 0.8 outvalue "Index1_Attack", 0.002 outvalue "Index1_Decay", 3.0 outvalue "Index1_Sustain", 0.0 outvalue "Index1_Release", 0.5 outvalue "Index1_Delay", 0.0 outvalue "Index2_Attack", 0.002 outvalue "Index2_Decay", 3.0 outvalue "Index2_Sustain", 0.0 outvalue "Index2_Release", 0.5 outvalue "Index2_Delay", 0.0 outvalue "Amp_Attack", 0.002 outvalue "Amp_Decay", 7.0 outvalue "Amp_Sustain", 0.0 outvalue "Amp_Release", 0.5 outvalue "Amp_Delay", 0.0 endin ;INSTR | START | DURATION i 10 0 3600 ;GUI ;INIT i 2 0.1 0 ;INIT 460 196 774 620 true 241 226 185 2 2 512 618 {aa607456-d368-4d59-8497-d16d608404c3} true 0 0 514 2 260 618 {74928ed2-b701-4668-9a11-74763d317e9b} true 0 0 520 80 250 503 {d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a} true 0 0 left Liberation Sans 14 3 255 255 255 255 255 255 noborder 1 1 8 6 124 30 {24979132-c53f-4414-ac6b-6b4f503ecfe8} true 0 0 event 1.00000000 ON / OFF (MIDI) / i 1 0 -1 true false Carrier_Amplitude 448 291 60 30 {745d6bee-b951-4a03-9fe8-9e10d5ae4556} true 0 0 right Arial 9 3 255 255 255 255 255 255 noborder 1 1 Carrier_Amplitude 8 268 500 27 {06814721-6151-4baa-84e2-8f39843b07a4} true 0 0 0.00000000 1.00000000 0.80000001 lin continuous -1.00000000 false 8 291 180 30 {c6d7165c-6730-426f-b293-52b411bc73cf} true 0 0 left Arial 10 3 255 255 255 255 255 255 noborder 1 1 75 182 358 83 {53a95371-23f7-4d54-a6c6-63bbabdb388d} true 0 0 174 184 32 46 {81ded06c-d53f-4a6d-a597-5f1b68b18042} true 0 0 center Arial Black 27 3 255 255 255 255 255 255 noborder 1 1 Carrier_Frequency 95 194 70 28 {6f8fc775-201d-40f9-931b-687c9b3ef417} true 0 0 left Liberation Sans 14 0 0 0 255 255 255 0.00010000 0.125 8 false 0.125 Modulator1_Frequency 218 194 70 28 {fd4b783c-f008-4a1c-b2e6-50340aad9093} true 0 0 left Liberation Sans 14 0 0 0 255 255 255 0.00010000 0.125 8 false 0.125 218 223 70 50 {d7a84933-3d3a-4adf-8289-84a4413362a7} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 95 223 70 50 {7723878b-fcac-4444-84a2-a4ba87008431} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 8 104 180 30 {541ace1b-b1de-4c04-8d84-1de90288dded} true 0 0 left Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Base_Frequency 8 81 500 27 {eac88081-deaa-45c0-b896-32a3ffedc74a} true 0 0 0.00000000 1.00000000 0.40357050 lin continuous -1.00000000 false Base_Frequency_Value 448 104 60 30 {3be43919-ad18-4aef-b554-03c4b4d991c3} true 0 0 right Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 8 147 180 30 {0c691576-66a5-4aa6-a82c-48f930da9708} true 0 0 left Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Modulation_Index_1 8 124 250 27 {9cf53cef-488f-4075-b87f-dc2c3e6a21e6} true 0 0 0.00000000 20.00000000 10.88000011 lin continuous -1.00000000 false 8 321 500 96 {edbaff47-a52a-4733-801b-10e207571428} true 0 0 left Liberation Sans 14 3 255 255 255 255 255 255 border 1 1 Index1_Attack 189 330 45 45 {7020c475-84e1-497d-abcc-1651846cd081} true 0 0 0.00500000 8.00000000 0.00500000 lin continuous 0.01000000 false 177 374 70 31 {2bc5a26f-6ed1-497f-9cc9-372067fc74a0} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Index1_Attack 182 394 60 30 {39ac87aa-d118-4cee-98a5-30005f1b85b9} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 Index1_Decay 232 394 60 30 {e4a41d1d-7b92-4910-a33f-0505d9b85493} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 227 374 70 31 {738e097b-25dd-4f34-8279-6c7e03e83210} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Index1_Decay 239 330 45 45 {a92eed39-9f56-4cb4-bb3d-20f8c9ab692e} true 0 0 0.00000000 15.00000000 3.00000000 lin continuous 0.01000000 false Index1_Sustain 283 393 60 30 {c44e6e8e-a319-4ad7-936f-1dbad8fe5d88} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 278 373 70 31 {7fb72d6d-f804-4eed-8eec-03489eef4f54} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Index1_Sustain 290 329 45 45 {1256d78b-64b4-4a33-b1a2-c6e147788a64} true 0 0 0.00000000 1.00000000 0.00000000 lin continuous 0.01000000 false Index1_Release 334 393 60 30 {aede005f-af85-4a2e-826f-3b03c1a663a7} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 329 373 70 31 {84305d1c-9695-47f1-8536-0be4b8783ca7} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Index1_Release 341 329 45 45 {bd1488b8-dfc0-48f8-80db-21f899f3408a} true 0 0 0.00000000 15.00000000 2.70000005 lin continuous 0.01000000 false Index1_Delay 385 393 60 30 {80742be8-4ca4-4e7c-b845-5e6f911ce892} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 380 373 70 31 {70fbe521-a69d-45de-b056-52358ef4539f} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Index1_Delay 392 329 45 45 {ad8b5897-aaca-485d-b0f4-12723d84012a} true 0 0 0.00000000 8.00000000 0.00000000 lin continuous 0.01000000 false 8 517 500 96 {ebccfe0c-c88a-475f-8960-eb0c68dc0465} true 0 0 left Liberation Sans 14 3 255 255 255 255 255 255 border 1 1 Amp_Delay 392 525 45 45 {ba22dd34-221f-4885-be63-0227b478280f} true 0 0 0.00000000 8.00000000 0.00000000 lin continuous 0.01000000 false 380 569 70 31 {cd2e5022-9b80-4261-b2cf-1327ea35b419} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Amp_Delay 385 589 60 30 {0ae5e1b4-46bc-456b-a7b6-d91b2d4196f9} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 Amp_Release 341 525 45 45 {f94fee0f-a85f-49bc-92bb-1b449b5524b8} true 0 0 0.00000000 15.00000000 5.40000010 lin continuous 0.01000000 false 329 569 70 31 {da15df18-48b8-43ab-a879-b4da10429f3a} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Amp_Release 334 589 60 30 {ab141074-a7d2-4397-9da2-71162ac152c2} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 Amp_Sustain 290 525 45 45 {a629f388-497b-45cd-a7d6-232a4699a56c} true 0 0 0.00000000 1.00000000 0.93000001 lin continuous 0.01000000 false 278 569 70 31 {c109df79-b140-4292-bbb1-ae448090e932} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Amp_Sustain 283 589 60 30 {ad993d2c-666e-4e49-8edc-b890b66c4b6a} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 Amp_Decay 239 526 45 45 {d9a06f46-e411-492d-9402-3cb584ef32c4} true 0 0 0.00000000 15.00000000 7.00000000 lin continuous 0.01000000 false 227 570 70 31 {eefade2c-bcf8-4fa7-83bd-e4d449daf2cd} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Amp_Decay 232 590 60 30 {d366e403-6bae-49e9-90b7-920e1ff2e8f0} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 Amp_Attack 182 590 60 30 {a8c5f4b0-7281-4c50-af8d-28fde5ff3d72} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 177 570 70 31 {ccdc65d8-5b7e-4745-96ef-5bb738bc55f3} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Amp_Attack 189 526 45 45 {5971a2e0-a072-46fb-ba71-f5cf75fb8e71} true 0 0 0.00100000 8.00000000 0.72091001 lin continuous 0.01000000 false Modulation_Index_1 198 147 60 30 {c80205fb-7ad4-4b4e-878c-8bf7bf8737c0} true 0 0 right Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 Modulation_Index_2 448 147 60 30 {c03c8ac7-b287-4328-8e07-bbf81f16291a} true 0 0 right Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 Modulation_Index_2 258 124 250 27 {9e41022a-6d97-415e-82ef-dafd223f6de8} true 0 0 0.00000000 20.00000000 3.83999991 lin continuous -1.00000000 false 258 147 180 30 {dd30e1bc-c2a4-4d61-8df6-fafe394c7687} true 0 0 left Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 342 223 70 50 {a41c9bd7-bf11-4aeb-99d0-39e0949d0da0} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Modulator2_Frequency 342 194 70 28 {4613a393-76fd-495c-8e3b-95f1257e8326} true 0 0 left Liberation Sans 14 0 0 0 255 255 255 0.00010000 0.125 8 false 0.125 298 184 32 46 {42146cc9-014a-446b-94e1-296f9c3f8fdb} true 0 0 center Arial Black 27 3 255 255 255 255 255 255 noborder 1 1 155 5 305 35 {c35c6c13-7799-4395-9775-f3006b3eafcb} true 0 0 center Liberation Sans 18 3 255 255 255 255 255 255 noborder 1 1 114 28 387 31 {20b81ac9-e24a-4a60-bdb1-2c3bc2c578cf} true 0 0 center Liberation Sans 18 3 255 255 255 255 255 255 noborder 1 1 519 29 250 55 {dd72e305-5880-4889-b044-bf9d9333880b} true 0 0 center Liberation Sans 18 3 255 255 255 255 255 255 noborder 1 1 517 5 250 35 {28873f9f-f41a-4961-9ae9-c3948ecc50f0} true 0 0 center Liberation Sans 18 3 255 255 255 255 255 255 noborder 1 1 8 419 500 96 {2b908e19-7b7a-4099-abf4-3e060fa656e4} true 0 0 left Liberation Sans 14 3 255 255 255 255 255 255 border 1 1 Index2_Attack 189 428 45 45 {70c1e395-5dc8-42c3-923c-7b6b04588cf5} true 0 0 0.00500000 8.00000000 0.24484999 lin continuous 0.01000000 false 177 472 70 31 {d284520a-164a-4154-8970-243ef73a20c4} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Index2_Attack 182 492 60 30 {73bb721b-c83a-4160-8f97-b42f630f0a22} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 Index2_Decay 232 492 60 30 {3442268c-7bc6-453c-bbcd-1f7905129062} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 227 472 70 31 {2ff653e2-2cda-4b35-a23d-fd4e5a930335} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Index2_Decay 239 428 45 45 {be98d863-e324-4d93-9707-37e2a0cfa0a4} true 0 0 0.00000000 15.00000000 3.00000000 lin continuous 0.01000000 false Index2_Sustain 283 491 60 30 {f40d9c14-a210-42bc-b14d-aadfd20aef98} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 278 471 70 31 {1ffb88b9-70cb-4cfe-843b-1770af84f0d4} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Index2_Sustain 290 427 45 45 {ce5c7dd7-4e42-4a83-a5eb-5038b38c32f8} true 0 0 0.00000000 1.00000000 0.97000003 lin continuous 0.01000000 false Index2_Release 334 491 60 30 {46dd58b4-4123-45d0-a987-2dd91b62fd7d} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 329 471 70 31 {8d6e0855-4fdb-4515-a62e-766fe44774bd} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Index2_Release 341 427 45 45 {e1c1697e-7895-4abd-b00d-f793cb7c156a} true 0 0 0.00000000 15.00000000 2.54999995 lin continuous 0.01000000 false Index2_Delay 385 491 60 30 {3fcd62b4-c140-44ee-9c42-8fdb4d4f2a93} true 0 0 center Liberation Sans 9 3 255 255 255 255 255 255 noborder 1 1 380 471 70 31 {df3ad43d-3389-4e0a-bfee-f056a7f9f6a3} true 0 0 center Liberation Sans 10 3 255 255 255 255 255 255 noborder 1 1 Index2_Delay 392 427 45 45 {33e5ac1d-ccdb-4c7b-ae3f-1193d7c9cae3} true 0 0 0.00000000 8.00000000 0.00000000 lin continuous 0.01000000 false 0.00000000 0 0.80000001 0.800 0.80000001 1.00000000 1.34480000 0.40357050 324.99987793 325.000 10.88000011 0.00500000 0.00500000 0.005 3.00000000 3.000 3.00000000 0.00000000 0.000 0.00000000 2.70000005 2.700 2.70000005 0.00000000 0.000 0.00000000 0.00000000 0.00000000 0.000 5.40000010 5.40000010 5.400 0.93000001 0.93000001 0.930 7.00000000 7.00000000 7.000 0.72091001 0.721 0.72091001 10.88000011 10.880 3.83999991 3.840 3.83999991 1.38530004 0.24484999 0.24484999 0.245 3.00000000 3.000 3.00000000 0.97000003 0.970 0.97000003 2.54999995 2.550 2.54999995 0.00000000 0.000 0.00000000