Cabbage Logo
Back to Cabbage Site

Adapting GEN02 for Unity sequencer

hey @iainmccurdy, finally getting around to integrating your GEN02 adaptation into my sequencer and of course i’m getting nowhere fast, despite the fact that i am learning what makes things tick. first off, some code that works properly:

instr inst4
; play from score and midi keyboard

	mididefault	60, p3
	midinoteonkey	p4, p5
inum	init	p4
ivel	init	p5
ivel	init	ivel/127				;make velocity dependent
kamp	linsegr	1, 1, 1, .1, 0
kamp	= kamp/5000				;scale amplitude
kfreq	init	1					;do not change freq from sf

      
a1,a2	sfinstr	ivel, inum, kamp*ivel, kfreq, 15, gisf1
	outs	a1, a2
	
endin

this is the code that the soundfont player uses to play sounds and it works fine. as for the GEN02 example i left out the sequence player instrument and delay and used just the synth and no screen controls since i’m not sure how to make them show up in Unity. that means i initialized them to the values you set earlier on. here’s how that looks:

instr inst2
	kfilt	    init	    0	           ; read filter envelope shift from widget
	kres		init	    .70          ; read in widgets...
	klev		init	    .5
	kfshift	init	    0     ; freq. shift ratio with respect to the frequency of the note played
	idecay     init	    .5    ; read envelope duration from table
							
	inote	init        p4      ; read note number from table (range: 0 - 1)
			p5=p5/127     ;scaling range of p5 to roughly 0-1
	iamp        ampmidi     1  ; read amplitude from table (range: 0 - 1)
	kcf	        expseg	    inote+(60*iamp),idecay,inote,1,inote	; create filter cutoff envelope
	kcf	        limit	    cpsmidinn(kcf+(12*kfilt)),20,20000	    
	kporttime	linseg	    0,0.001,1			                    ; portamento time ramps up quickly from zero, holds at '1'                                 
	a1	        vco2	    iamp*klev,cpsmidinn(inote),0,0.5	    ; VCO audio signal generator
	a1	        moogladder	a1,kcf,kres			                    ; moogladder lowpass filter                                                                                                                                                                                                                
	a1	        FreqShifter	a1,cpsmidinn(inote)*kfshift*0.5,gisine	; frequency shift applied to audio signal (using a UDO: see above). Frequency is a function of note number of the sequence and the on-screen control 'harm.'
	aAntiClick  linsegr     0,0.005,1,0.005,0
	aR	        =	        a1 * klev*aAntiClick			   ; scale audio signal with 'Level' and 'Echo' controls
	aL	        delay	    aR, 0.002				   ; slightly delay audio signal (used to create a stereo effect)
		        outs	    aL, aR					           ; send audio to outputs (left channel slightly delayed)	
endin

p4 is the note number and p5 is the velocity. at the moment i just set amp to 1 so i could hear some sound but i don’t hear any sound currently. i have included the UDO and the gisine table for the freq shift. the code compiles properly, so no syntax errors, but it’s likely my math is off as i get no sound at all.

anything obvious i’m not doing here? would appreciate any tips -thanks!

I think the problem is using ampmidi in an instrument that is not triggered by MIDI. In this case iamp wil equal zero, hence silence. Just set iamp to p5 (divided by 127) and make sure to set 0dbfs to 1. As it stands you weren’t using p5 anyway. It’s better practice to either use “–midi-key=4 --midi-velocity=5” in CsOptions or to use the MIDI opcodes “ampmidi, cpsmidi etc.”, but not a mixture of both.

okay. i can adapt it to use p5. but i’m just a little unclear of what gets changed to 1dbfs instead of 0dbfs. should that be the init value of p5? i may be getting confused…

Iain means:

0dbfs = 1

That should appear in the header section of your orchestra, up there with ksmps and sr

yup - that did it - thank you, gents! i was close but not quite there.