<Cabbage>
form caption("divno elka") size(400, 200), colour(58, 110, 182), pluginid("def1")
keyboard bounds(10, 74, 381, 95)
label bounds(10, 6, 368, 61) text("divno elka")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

giCps init 0
gaMaster init 0

; from http://www.csounds.com/udo/displayOpcode.php?opcode_id=50
opcode freqShift, a, ak
  
	ain, kfreq	xin
	
	; Phase quadrature output derived from input signal.
	areal, aimag hilbert ain
	 
	; Sine table for quadrature oscillator.
	iSineTable ftgen	0, 0, 16384, 10, 1

	; Quadrature oscillator.
	asin oscili 1, kfreq, iSineTable
	acos oscili 1, kfreq, iSineTable, .25
	 
	; Use a trigonometric identity. 
	; See the references for further details.
	amod1 = areal * acos
	amod2 = aimag * asin
	
	; Both sum and difference frequencies can be 
	; output at once.
	; aupshift corresponds to the sum frequencies.
	aupshift = (amod1 + amod2) * 0.7
	; adownshift corresponds to the difference frequencies. 
	adownshift = (amod1 - amod2) * 0.7
	
	; Notice that the adding of the two together is
	; identical to the output of ring modulation.
	
	xout aupshift
endop

;instrument will be triggered by keyboard widget
instr 1
    inotnum notnum
    kcps = cpsmidinn(inotnum)
    kEnv madsr .3, .0001, 0.8, .3
    ; shift freq down by something
    aOut freqShift gaMaster, giCps-kcps
    prints "diff %d Hz\n", giCps-kcps
    aOut2 bqrez aOut, kcps, 1, 2
    outs aOut2*kEnv, aOut2*kEnv
endin


instr 99
    giCps = cpsmidinn(84)
    prints "giCps=%d\n", giCps
    gaMaster vco2 0.8, giCps, 0
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z

; starts master oscilator
i99 0 -1
</CsScore>
</CsoundSynthesizer>
