%pylab inline
from __future__ import print_function
from __future__ import division
Populating the interactive namespace from numpy and matplotlib
import icsound
cs = icsound.icsound()
cs.start_engine(ksmps=256)
Csound server started.
cs.print_log()
rtaudio: ALSA module enabled rtmidi: ALSA Raw MIDI module enabled WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH (points to rawwaves directory) to use STK opcodes. --Csound version 6.07 (double samples) Apr 14 2016 graphics suppressed, ascii substituted 0dBFS level = 1.0 orch now loaded audio buffered in 256 sample-frame blocks ALSA output: total buffer size: 1024, period size: 256 writing 512 sample blks of 64-bit floats to dac SECTION 1:
%%csound
instr 1
kfreq chnget "freq"
asig oscil 0.1, kfreq
outs asig, asig
endin
%%csound
turnon 1
cs.set_channel("freq", 880)
#make function to turnoff all notes
cs.send_score('i -1 0 0')
Two operator FM.
Possibilities:
%%csound
girgnp ftgen 0, 0, 0, -23, "../shared/rgnp.txt"
giunrate ftgen 0, 0, 0, -23, "../shared/unrate.txt"
gigs10 ftgen 0, 0, 0, -23, "../shared/gs10.txt"
gisine ftgen 0, 0, 4096, 10, 1
%%csound
instr 1
kfreq chnget "freq"
; data reader
ags10 poscil 1, kfreq, gigs10
; modulator
amod poscil ags10 * ags10 * 10, 44 + (16 - ags10)
; phasor + table reader is the carrier
acarr poscil 0.2, 220 + amod
outs acarr* 0.1, acarr * 0.1
endin
cs.set_channel("freq", 1/10.0)
cs.send_score('i 1 0 20')
%%csound
print(giunrate)
cs.print_log()
rtaudio: ALSA module enabled rtmidi: ALSA Raw MIDI module enabled WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH (points to rawwaves directory) to use STK opcodes. --Csound version 6.07 (double samples) Apr 14 2016 graphics suppressed, ascii substituted 0dBFS level = 1.0 orch now loaded audio buffered in 256 sample-frame blocks ALSA output: total buffer size: 1024, period size: 256 writing 512 sample blks of 64-bit floats to dac SECTION 1: rtevent: T 39.259 TT 39.259 M: 0.00000 0.00000 new alloc for instr 1: rtevent: T 47.816 TT 47.816 M: 0.10000 0.10000 rtevent: T 63.321 TT 63.321 M: 0.00000 0.00000 new alloc for instr 1: rtevent: T 75.331 TT 75.331 M: 0.10000 0.10000 ftable 101: ftable 101: error opening ASCII file f101 0.00 0.00 -23.00 "../shared/rgnp.txt" ... INIT ERROR in instr 0: ftgen error girgnp ftgen.iS 0 0 0 -23 "../shared/rgnp.txt" ftable 101: 819 elements in ../shared/unrate.txt ftable 101: 819 points, scalemax 10.800 _ _ ''. '_ ' -_ _ . ' '-. _''_ _ ' _ '- - __ --_ _ -.' -_ ._ ..._ . _ ' -. . '' --_ -_. - _- '__ '-. --._- '-' . ftable 102: 756 elements in ../shared/gs10.txt ftable 102: 756 points, scalemax 15.320 '. - -- ' ' - ._ .' .-'_-_ _ _''. .-' ' - - ._ _ _ ..- ' '' ' -. -__ _. _. - ------' --'' . . '--' ' ' --__'.. ftable 103: ftable 103: 4096 points, scalemax 1.000 .-''''''-._ _-' '. _- '. - '_ .' - - '_ _' . . - - '_ _'_____________________________________._______________________________________ - . - - '_ _' . . - - '. _' -_ - -_ .' -_ _.' '-._____..' WARNING: Buffer underrun in real-time audio output rtevent: T604.119 TT604.119 M: 0.00000 0.00000 new alloc for instr 1: error: Variable 'asig' used before defined error: Variable type for asig could not be determined. Parsing failed to syntax errors Stopping on parser failure rtevent: T1502.482 TT1502.482 M: 0.10000 0.10000 new alloc for instr 1: rtevent: T1513.616 TT1513.616 M: 0.02000 0.02000 rtevent: T1540.423 TT1540.423 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1547.192 TT1547.192 M: 0.02000 0.02000 rtevent: T1554.338 TT1554.338 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1595.019 TT1595.019 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1603.100 TT1603.100 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1613.717 TT1613.717 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1620.550 TT1620.550 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1623.493 TT1623.493 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1630.354 TT1630.354 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1648.025 TT1648.025 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1655.107 TT1655.107 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1685.090 TT1685.090 M: 0.02000 0.02000 new alloc for instr 1: instr 0: gigs10 = 102.000 rtevent: T1826.888 TT1826.888 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1905.435 TT1905.435 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T1939.325 TT1939.325 M: 0.02000 0.02000 rtevent: T2096.663 TT2096.663 M: 0.02000 0.02000 rtevent: T2244.748 TT2244.748 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2258.733 TT2258.733 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2330.773 TT2330.773 M: 0.04000 0.04000 new alloc for instr 1: rtevent: T2372.301 TT2372.301 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2402.122 TT2402.122 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2429.806 TT2429.806 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2439.123 TT2439.123 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2444.005 TT2444.005 M: 0.04000 0.04000 could not find playing instr 1.000000 rtevent: T2462.290 TT2462.290 M: 0.04000 0.04000 rtevent: T2501.155 TT2501.155 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2516.254 TT2516.254 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2596.670 TT2596.670 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2615.705 TT2615.705 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2850.493 TT2850.493 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2871.821 TT2871.821 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2899.069 TT2899.069 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2923.613 TT2923.613 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T2976.740 TT2976.740 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3011.860 TT3011.860 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3067.333 TT3067.333 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3103.324 TT3103.324 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3143.703 TT3143.703 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3159.551 TT3159.551 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3183.589 TT3183.589 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3218.640 TT3218.640 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3250.219 TT3250.219 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3281.966 TT3281.966 M: 0.02000 0.02000 rtevent: T3294.261 TT3294.261 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3320.175 TT3320.175 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3332.267 TT3332.267 M: 0.02000 0.02000 rtevent: T3355.928 TT3355.928 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3409.386 TT3409.386 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3443.287 TT3443.287 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3459.953 TT3459.953 M: 0.02000 0.02000 rtevent: T3515.315 TT3515.315 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3582.514 TT3582.514 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3620.833 TT3620.833 M: 0.02000 0.02000 rtevent: T3650.206 TT3650.206 M: 0.02000 0.02000 rtevent: T3689.784 TT3689.784 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3717.602 TT3717.602 M: 0.02000 0.02000 rtevent: T3741.733 TT3741.733 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3795.406 TT3795.406 M: 0.02000 0.02000 new alloc for instr 1: rtevent: T3921.357 TT3921.357 M: 0.02000 0.02000 rtevent: T3943.044 TT3943.044 M: 0.02000 0.02000 instr 0: giunrate = 101.000
cs.plot_table(102)
import time
cs.start_record("fm.wav")
cs.send_score('i 1 0 20')
time.sleep(20)
cs.stop_record()
!aplay fm.wav
Playing WAVE 'fm.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
from IPython.display import Audio
Audio(filename='fm.wav')
%%csound
instr 1
kfreq chnget "freq"
; data reader
ags10 poscil 1, kfreq, gigs10
aunrate poscil 1, kfreq, giunrate
; modulator
amod poscil 110 + ags10 * ags10 * 20, 55 + (aunrate * 80)
; phasor + table reader is the carrier
acarr poscil 0.2, 220 + amod
outs acarr* 0.1, acarr * 0.1
endin
cs.set_channel("freq", 1/50.0)
cs.send_score('i 1 0 50')
cs.plot_table(102)
cs.plot_table(101, reuse=True)
Parameter space (some possibilities):
What's interesting in granular synthesis is that these parameters often map directly to clear perpectual concepts.
cs.clear_log()
%%csound
gisine ftgen 0, 0, 1024, 10, 1
gihanning ftgen 0, 0, 1024, -20, 1
%%csound
; http://www.csounds.com/manual/html/grain3.html
gisine ftgen 0, 0, 1024, 10, 1
gihanning ftgen 0, 0, 1024, -20, 1
instr 1
kphs = 0
kfmd = 30
kpmd = 0
kgdur = 0.3 ; grain duration
kcps = 440.0 ; frequency of oscillation inside grain
kdens = 3; density, number of grains per second
imaxovr = 100
kfn = gisine
iwfn = gihanning
kfrpow = 0
kprpow = 0
iseed = 1 ; random seed
ares grain3 kcps, kphs, kfmd, kpmd, kgdur, kdens, imaxovr, kfn, iwfn, \
kfrpow, kprpow
outs ares, ares
endin
cs.send_score('i 1 0 5')
cs.send_code('print gisine')
cs.print_log()
cs.plot_table(106)
%%csound
;example by Iain McCurdy from the FLOSS manual
; http://write.flossmanuals.net/csound/preface/
;FUNCTION TABLES STORING DATA FOR VARIOUS VOICE FORMANTS
;BASS
giBF1 ftgen 0, 0, -5, -2, 600, 400, 250, 400, 350
giBF2 ftgen 0, 0, -5, -2, 1040, 1620, 1750, 750, 600
giBF3 ftgen 0, 0, -5, -2, 2250, 2400, 2600, 2400, 2400
giBF4 ftgen 0, 0, -5, -2, 2450, 2800, 3050, 2600, 2675
giBF5 ftgen 0, 0, -5, -2, 2750, 3100, 3340, 2900, 2950
giBDb1 ftgen 0, 0, -5, -2, 0, 0, 0, 0, 0
giBDb2 ftgen 0, 0, -5, -2, -7, -12, -30, -11, -20
giBDb3 ftgen 0, 0, -5, -2, -9, -9, -16, -21, -32
giBDb4 ftgen 0, 0, -5, -2, -9, -12, -22, -20, -28
giBDb5 ftgen 0, 0, -5, -2, -20, -18, -28, -40, -36
giBBW1 ftgen 0, 0, -5, -2, 60, 40, 60, 40, 40
giBBW2 ftgen 0, 0, -5, -2, 70, 80, 90, 80, 80
giBBW3 ftgen 0, 0, -5, -2, 110, 100, 100, 100, 100
giBBW4 ftgen 0, 0, -5, -2, 120, 120, 120, 120, 120
giBBW5 ftgen 0, 0, -5, -2, 130, 120, 120, 120, 120
;TENOR
giTF1 ftgen 0, 0, -5, -2, 650, 400, 290, 400, 350
giTF2 ftgen 0, 0, -5, -2, 1080, 1700, 1870, 800, 600
giTF3 ftgen 0, 0, -5, -2, 2650, 2600, 2800, 2600, 2700
giTF4 ftgen 0, 0, -5, -2, 2900, 3200, 3250, 2800, 2900
giTF5 ftgen 0, 0, -5, -2, 3250, 3580, 3540, 3000, 3300
giTDb1 ftgen 0, 0, -5, -2, 0, 0, 0, 0, 0
giTDb2 ftgen 0, 0, -5, -2, -6, -14, -15, -10, -20
giTDb3 ftgen 0, 0, -5, -2, -7, -12, -18, -12, -17
giTDb4 ftgen 0, 0, -5, -2, -8, -14, -20, -12, -14
giTDb5 ftgen 0, 0, -5, -2, -22, -20, -30, -26, -26
giTBW1 ftgen 0, 0, -5, -2, 80, 70, 40, 40, 40
giTBW2 ftgen 0, 0, -5, -2, 90, 80, 90, 80, 60
giTBW3 ftgen 0, 0, -5, -2, 120, 100, 100, 100, 100
giTBW4 ftgen 0, 0, -5, -2, 130, 120, 120, 120, 120
giTBW5 ftgen 0, 0, -5, -2, 140, 120, 120, 120, 120
;COUNTER TENOR
giCTF1 ftgen 0, 0, -5, -2, 660, 440, 270, 430, 370
giCTF2 ftgen 0, 0, -5, -2, 1120, 1800, 1850, 820, 630
giCTF3 ftgen 0, 0, -5, -2, 2750, 2700, 2900, 2700, 2750
giCTF4 ftgen 0, 0, -5, -2, 3000, 3000, 3350, 3000, 3000
giCTF5 ftgen 0, 0, -5, -2, 3350, 3300, 3590, 3300, 3400
giTBDb1 ftgen 0, 0, -5, -2, 0, 0, 0, 0, 0
giTBDb2 ftgen 0, 0, -5, -2, -6, -14, -24, -10, -20
giTBDb3 ftgen 0, 0, -5, -2, -23, -18, -24, -26, -23
giTBDb4 ftgen 0, 0, -5, -2, -24, -20, -36, -22, -30
giTBDb5 ftgen 0, 0, -5, -2, -38, -20, -36, -34, -30
giTBW1 ftgen 0, 0, -5, -2, 80, 70, 40, 40, 40
giTBW2 ftgen 0, 0, -5, -2, 90, 80, 90, 80, 60
giTBW3 ftgen 0, 0, -5, -2, 120, 100, 100, 100, 100
giTBW4 ftgen 0, 0, -5, -2, 130, 120, 120, 120, 120
giTBW5 ftgen 0, 0, -5, -2, 140, 120, 120, 120, 120
;ALTO
giAF1 ftgen 0, 0, -5, -2, 800, 400, 350, 450, 325
giAF2 ftgen 0, 0, -5, -2, 1150, 1600, 1700, 800, 700
giAF3 ftgen 0, 0, -5, -2, 2800, 2700, 2700, 2830, 2530
giAF4 ftgen 0, 0, -5, -2, 3500, 3300, 3700, 3500, 2500
giAF5 ftgen 0, 0, -5, -2, 4950, 4950, 4950, 4950, 4950
giADb1 ftgen 0, 0, -5, -2, 0, 0, 0, 0, 0
giADb2 ftgen 0, 0, -5, -2, -4, -24, -20, -9, -12
giADb3 ftgen 0, 0, -5, -2, -20, -30, -30, -16, -30
giADb4 ftgen 0, 0, -5, -2, -36, -35, -36, -28, -40
giADb5 ftgen 0, 0, -5, -2, -60, -60, -60, -55, -64
giABW1 ftgen 0, 0, -5, -2, 50, 60, 50, 70, 50
giABW2 ftgen 0, 0, -5, -2, 60, 80, 100, 80, 60
giABW3 ftgen 0, 0, -5, -2, 170, 120, 120, 100, 170
giABW4 ftgen 0, 0, -5, -2, 180, 150, 150, 130, 180
giABW5 ftgen 0, 0, -5, -2, 200, 200, 200, 135, 200
;SOPRANO
giSF1 ftgen 0, 0, -5, -2, 800, 350, 270, 450, 325
giSF2 ftgen 0, 0, -5, -2, 1150, 2000, 2140, 800, 700
giSF3 ftgen 0, 0, -5, -2, 2900, 2800, 2950, 2830, 2700
giSF4 ftgen 0, 0, -5, -2, 3900, 3600, 3900, 3800, 3800
giSF5 ftgen 0, 0, -5, -2, 4950, 4950, 4950, 4950, 4950
giSDb1 ftgen 0, 0, -5, -2, 0, 0, 0, 0, 0
giSDb2 ftgen 0, 0, -5, -2, -6, -20, -12, -11, -16
giSDb3 ftgen 0, 0, -5, -2, -32, -15, -26, -22, -35
giSDb4 ftgen 0, 0, -5, -2, -20, -40, -26, -22, -40
giSDb5 ftgen 0, 0, -5, -2, -50, -56, -44, -50, -60
giSBW1 ftgen 0, 0, -5, -2, 80, 60, 60, 70, 50
giSBW2 ftgen 0, 0, -5, -2, 90, 90, 90, 80, 60
giSBW3 ftgen 0, 0, -5, -2, 120, 100, 100, 100, 170
giSBW4 ftgen 0, 0, -5, -2, 130, 150, 120, 130, 180
giSBW5 ftgen 0, 0, -5, -2, 140, 200, 120, 135, 200
gisine ftgen 0, 0, 4096, 10, 1
giexp ftgen 0, 0, 1024, 19, 0.5, 0.5, 270, 0.5
instr 1
kFund expon p4,p3,p5 ; fundemental
kVow line p6,p3,p7 ; vowel select
kBW line p8,p3,p9 ; bandwidth factor
iVoice = p10 ; voice select
; read formant cutoff frequenies from tables
kForm1 tablei kVow*5,giBF1+(iVoice*15)
kForm2 tablei kVow*5,giBF1+(iVoice*15)+1
kForm3 tablei kVow*5,giBF1+(iVoice*15)+2
kForm4 tablei kVow*5,giBF1+(iVoice*15)+3
kForm5 tablei kVow*5,giBF1+(iVoice*15)+4
; read formant intensity values from tables
kDB1 tablei kVow*5,giBF1+(iVoice*15)+5
kDB2 tablei kVow*5,giBF1+(iVoice*15)+6
kDB3 tablei kVow*5,giBF1+(iVoice*15)+7
kDB4 tablei kVow*5,giBF1+(iVoice*15)+8
kDB5 tablei kVow*5,giBF1+(iVoice*15)+9
; read formant bandwidths from tables
kBW1 tablei kVow*5,giBF1+(iVoice*15)+10
kBW2 tablei kVow*5,giBF1+(iVoice*15)+11
kBW3 tablei kVow*5,giBF1+(iVoice*15)+12
kBW4 tablei kVow*5,giBF1+(iVoice*15)+13
kBW5 tablei kVow*5,giBF1+(iVoice*15)+14
; create resonant formants using fof opcode
koct = 1
aForm1 fof ampdb(kDB1),kFund,kForm1,0,kBW1,0.003,0.02,0.007,\
1000,gisine,giexp,3600
aForm2 fof ampdb(kDB2),kFund,kForm2,0,kBW2,0.003,0.02,0.007,\
1000,gisine,giexp,3600
aForm3 fof ampdb(kDB3),kFund,kForm3,0,kBW3,0.003,0.02,0.007,\
1000,gisine,giexp,3600
aForm4 fof ampdb(kDB4),kFund,kForm4,0,kBW4,0.003,0.02,0.007,\
1000,gisine,giexp,3600
aForm5 fof ampdb(kDB5),kFund,kForm5,0,kBW5,0.003,0.02,0.007,\
1000,gisine,giexp,3600
; formants are mixed
aMix sum aForm1,aForm2,aForm3,aForm4,aForm5
kEnv linseg 0,3,1,p3-6,1,3,0 ; an amplitude envelope
outs aMix*kEnv*0.3, aMix*kEnv*0.3 ; send audio to outputs
endin
cs.send_score('''
; p4 = fundamental begin value (c.p.s.)
; p5 = fundamental end value
; p6 = vowel begin value (0 - 1 : a e i o u)
; p7 = vowel end value
; p8 = bandwidth factor begin (suggested range 0 - 2)
; p9 = bandwidth factor end
; p10 = voice (0=bass; 1=tenor; 2=counter_tenor; 3=alto; 4=soprano)
; p1 p2 p3 p4 p5 p6 p7 p8 p9 p10
i 1 0 10 50 100 0 1 2 0 0
i 1 8 . 78 77 1 0 1 0 1
i 1 16 . 150 118 0 1 1 0 2
i 1 24 . 200 220 1 0 0.2 0 3
i 1 32 . 400 800 0 1 0.2 0 4
''')
First decide on a mapping.
When we look at data, we don't see the values. There is othre important information that we pick up:
Simple rules can make these features audible