Fragments of a Bohlen-Pierce Composition Jacob Joaquin March 1, 2010 jacobjoaquin@gmail.com csound.noisepages.com sr = 44100 kr = 4410 ksmps = 10 nchnls = 2 0dbfs = 1.0 ; Tune Instruments # define TUNE # 264.99816498389697 # ; 440 * 3 ^ (-6 / 13) ; Instruments # define MIDI_Synth # 1 # # define Echo # 2 # # define Capture_Events # 100 # ; F-Tables # define T_Sine # 1 # ; Sine wave ; Sine wave gitemp ftgen $T_Sine, 0, 2 ^ 16, 10, 1 instr $MIDI_Synth ; MIDI input inote_play notnum ; Note number ivelocity veloc 0, 127 ; Velocity ivelocity = ivelocity / 127 ; Normalize velocity kgate madsr 0.05, 0.05, 1, 0.25 ; MIDI envelope ; Frequency ifreq = $TUNE * 3 ^ ((inote_play - 60) / 13) ; FM Synth a1 foscil kgate * ivelocity, ifreq, 1, 2, 6 * ivelocity, $T_Sine ; Outputs a1 = a1 * 0.5 outs a1, a1 chnmix a1, "Send" ; Send event info to $Capture_Event klisten init 1 ; Listen for release time kflag release ; Track release kline line 0, 1, 1 ; For capturing the time of release in seconds if (klisten == 1 && kflag == 1) then event "i", $Capture_Events, 0, 1, p2, kline, inote_play, ivelocity ; Stop listening klisten = 0 endif endin instr $Echo iamp = p4 ; Amplitude itime = p5 ; Time of delay ifb = p6 ; Delay feedback amount iroom_size = p7 ; Size of room, for reverb idamp = p8 ; High frequency dampening of reverb ; Receive send signal from MIDI_Synth a0 chnget "Send" ; Effects adelay delayr itime delayw a0 + adelay * ifb al, ar freeverb adelay, adelay, 0.1, 0.2 ; Outputs outs al * iamp, ar * iamp chnclear "Send" endin instr $Capture_Events istart = p4 irelease = p5 inote = p6 ivelocity = p7 prints "captured -- i 1 %f %f %d %f\n", istart, irelease, inote, \ ivelocity fprints "fragments_10_captured.csd", "i 1 %f %f %d %f\n", istart, \ irelease, inote, ivelocity turnoff endin ; Instruments # define MIDI_Synth # 1 # # define Echo # 2 # # define Capture_Events # 100 # ; Turn on echo effects i $Echo 0 10000 1 0.333 0.333 0.2 0.2