;Written by Iain McCurdy, 2009
; 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
; Cannot display more than one space in Label, so can't display the schematic shown below:
;Phase Modulation Synthesis: 2 parallel modulators -> carrier
;-------------------------------------------------------------
; +---------+ +---------+
; | MOD. 1 | | MOD. 2 |
; +----+----+ +----+----+
; | |
; +----------+----------+
; |
; +----+----+
; | CARRIER |
; +----+----+
; |
; V
; 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 = 1 ;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,65537,10,1 ;A SINE WAVE THAT CAN BE REFERENCED BY THE GLOBAL VARIABLE 'gisine'
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
gkindex1 invalue "Modulation_Index_1"
gkindex2 invalue "Modulation_Index_2"
gkCarRatio invalue "Carrier_Frequency"
gkModRatio1 invalue "Modulator1_Frequency"
gkModRatio2 invalue "Modulator2_Frequency"
gkCarAmp invalue "Carrier_Amplitude"
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"
kindex1 = iamp * gkindex1
kindex2 = iamp * gkindex2
;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"
kindex1 = gkindex1
kindex2 = gkindex2
endif
iporttime = .025 ;PORTAMENTO FUNCTION (WILL BE USED TO SMOOTH PARAMETER MOVED BY WIDGETS)
kporttime linseg 0,.001,iporttime,1,iporttime ;PORTAMENTO FUNCTION (WILL BE USED TO SMOOTH PARAMETER MOVED BY WIDGETS)
kindex1 portk kindex1, kporttime ;APPLY SMOOTHING PORTAMENTO TO THE VARIABLE 'kindex'
kindex2 portk kindex2, kporttime ;APPLY SMOOTHING PORTAMENTO TO THE VARIABLE 'kindex'
kbasefreq portk kbasefreq, kporttime ;APPLY SMOOTHING PORTAMENTO TO THE VARIABLE 'kbasefreq'
kCarAmp portk kCarAmp, kporttime ;APPLY SMOOTHING PORTAMENTO TO THE VARIABLE 'kCarAmp'
aModPhase1 phasor kbasefreq * gkModRatio1 ;CREATE A MOVING PHASE VALUE THAT WILL BE USED TO CREATE MODULATOR 1
aModulator1 tablei aModPhase1,gisine,1,0,1 ;MODULATOR OSCILLATOR IS CREATED.
aModulator1 = aModulator1*kindex1 ;MODULATOR AMPLITUDE RESCALED
aModPhase2 phasor kbasefreq * gkModRatio2 ;CREATE A MOVING PHASE VALUE THAT WILL BE USED TO CREATE MODULATOR 2
aModulator2 tablei aModPhase2,gisine,1,0,1 ;MODULATOR OSCILLATOR IS CREATED.
aModulator2 = aModulator2 * kindex2 ;MODULATOR AMPLITUDE RESCALED
aCarrPhase phasor kbasefreq * gkCarRatio ;CREATE A MOVING PHASE VALUE THAT WILL BE USED TO READ CREATE THE CARRIER
aCarrPhase = aCarrPhase + aModulator1 +aModulator2 ;MODULATORS 1 & 2 ARE ADDED TO CARRIER PHASE VARIABLE
aCarrier tablei aCarrPhase,gisine,1,0,1 ;CARRIER OSCILLATOR IS CREATED.
aAntiClick linsegr 0,0.001,1,0.01,0 ;ANTI CLICK ENVELOPE
aCarrier = aCarrier*kCarAmp*aAntiClick ;CARRIER AMPLITUDE IS RESCALED
outs aCarrier, aCarrier ;SEND THE AUDIO OUTPUT OF THE CARRIER WAVEFORM *ONLY* TO THE OUTPUTS
endin
;INSTR | START | DURATION
i 10 0 3600 ;GUI
330
280
808
364
true
241
226
185
2
2
513
360
{aa607456-d368-4d59-8497-d16d608404c3}
true
0
0
center
DejaVu Sans
18
3
255
255
255
5
27
150
border
5
2
514
2
287
360
{74928ed2-b701-4668-9a11-74763d317e9b}
true
0
0
center
DejaVu Sans
18
3
255
255
255
5
27
150
border
5
2
524
67
268
236
{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
328
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
305
500
27
{06814721-6151-4baa-84e2-8f39843b07a4}
true
0
0
0.00000000
1.00000000
0.40800000
lin
continuous
-1.00000000
false
8
328
180
30
{c6d7165c-6730-426f-b293-52b411bc73cf}
true
0
0
left
Arial
10
3
255
255
255
255
255
255
noborder
1
1
73
201
358
83
{53a95371-23f7-4d54-a6c6-63bbabdb388d}
true
0
0
left
Arial
10
3
255
255
255
255
255
255
border
1
1
173
203
32
46
{81ded06c-d53f-4a6d-a597-5f1b68b18042}
true
0
0
center
DejaVu Sans
27
3
255
255
255
255
255
255
noborder
1
1
Modulator1_Frequency
89
213
80
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
Modulator2_Frequency
212
213
80
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
89
241
70
50
{d7a84933-3d3a-4adf-8289-84a4413362a7}
true
0
0
center
Liberation Sans
10
3
255
255
255
255
255
255
noborder
1
1
336
241
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
86
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
63
500
27
{eac88081-deaa-45c0-b896-32a3ffedc74a}
true
0
0
0.00000000
1.00000000
0.23295900
lin
continuous
-1.00000000
false
Base_Frequency_Value
448
86
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
129
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
106
500
27
{9cf53cef-488f-4075-b87f-dc2c3e6a21e6}
true
0
0
0.00000000
5.00000000
1.00000000
lin
continuous
-1.00000000
false
Modulation_Index_2
448
171
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
8
148
500
27
{9e41022a-6d97-415e-82ef-dafd223f6de8}
true
0
0
0.00000000
5.00000000
1.00000000
lin
continuous
-1.00000000
false
8
171
180
30
{dd30e1bc-c2a4-4d61-8df6-fafe394c7687}
true
0
0
left
Liberation Sans
10
3
255
255
255
255
255
255
noborder
1
1
213
241
70
50
{a41c9bd7-bf11-4aeb-99d0-39e0949d0da0}
true
0
0
center
Liberation Sans
10
3
255
255
255
255
255
255
noborder
1
1
Carrier_Frequency
336
213
80
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
297
203
32
46
{42146cc9-014a-446b-94e1-296f9c3f8fdb}
true
0
0
center
DejaVu Sans
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
514
28
288
50
{dd72e305-5880-4889-b044-bf9d9333880b}
true
0
0
center
Liberation Sans
18
3
255
255
255
255
255
255
noborder
1
1
530
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
Modulation_Index_1
448
126
60
30
{eb489cb5-93a5-43ca-bd05-14ec2a67e140}
true
0
0
right
Liberation Sans
9
3
255
255
255
255
255
255
noborder
1
1