The Csound Blog By Jacob Joaquin http://csound.noisepages.com/ jacobjoaquin@gmail.com Instruments By Jacob Joaquin and Jean-Luc Sinclair (aka Jean-Luc Cohen) Jean-Luc's Website http://www.jeanlucsinclair.com/ Sample "105 Blanketed Lama.wav" By BT (aka Brian Transeau) http://www.btmusic.com/ Part of the One Laptop Per Child music library http://wiki.laptop.org/go/Sound_samples Download http://www.archive.org/download/BT/BT44.zip License Creative Commons Attribution 3.0 Unported http://creativecommons.org/licenses/by/3.0/ sr = 44100 kr = 44100 ksmps = 1 nchnls = 1 0dbfs = 1.0 # define LoadSample # 1 # # define Basic # 2 # # define Swell # 3 # # define Stutter # 4 # # define RandomPhrase # 5 # # define Random # 6 # # define Flam # 7 # # define SampleEngine # 8 # opcode objcreate_k, 0, SS Sobject, Smember xin Sname sprintf "%s.%s", Sobject, Smember chn_k Sname, 3 endop opcode objcreate_a, 0, SS Sobject, Smember xin Sname sprintf "%s.%s", Sobject, Smember chn_a Sname, 3 endop opcode objcreate_S, 0, SS Sobject, Smember xin Sname sprintf "%s.%s", Sobject, Smember chn_S Sname, 3 endop opcode objset_i, 0, iSS ival, Sobject, Smember xin Sname sprintf "%s.%s", Sobject, Smember chnset ival, Sname endop opcode objset_k, 0, kSS kval, Sobject, Smember xin Sname sprintf "%s.%s", Sobject, Smember chnset kval, Sname endop opcode objset_a, 0, aSS aval, Sobject, Smember xin Sname sprintf "%s.%s", Sobject, Smember chnset aval, Sname endop opcode objget_i, i, SS Sobject, Smember xin Sname sprintf "%s.%s", Sobject, Smember iout chnget Sname xout iout endop opcode objget_k, k, SS Sobject, Smember xin Sname sprintf "%s.%s", Sobject, Smember kout chnget Sname xout kout endop instr $LoadSample ifn = p4 ; Table number to store sample Sfile strget p5 ; Filename ichannel = p6 ; 0 = mixed mono, 1 = left, 2 = right inbeats = p7 ; Number of beats/quarter notes in the sample isamplerate filesr Sfile ; samplerate of file ilength filelen Sfile ilength = ilength * isamplerate ; length of filein samples itempo = isamplerate / ilength * inbeats * 60 ; tempo of soundfile ; Define object variable structure Sobject sprintf "f%d", ifn ; example: "f500", "f500.filename" ; Create software busses objcreate_k Sobject, "ifn" objcreate_k Sobject, "samplerate" objcreate_k Sobject, "length" objcreate_k Sobject, "tempo" objcreate_k Sobject, "nbeats" ; Set Values objset_i ifn, Sobject, "ifn" objset_i ilength, Sobject, "length" objset_i itempo, Sobject, "tempo" objset_i inbeats, Sobject, "nbeats" ; Load sample into Table isize = 1 repeat: isize = isize * 2 if( isize < ilength ) goto repeat gitemp ftgen ifn, 0, isize, 1, Sfile, 0, 0, ichannel ; Write file information to message window Sinfo1 sprintf "\nObject Number = %d\nFile Name = %s\nLength = %d\n", ifn,\ Sfile, ilength Sinfo2 sprintf "Samplerate = %d\nTempo = %0.4f\nTable size = %d\n\n",\ isamplerate, itempo, isize prints Sinfo1 prints Sinfo2 turnoff endin instr $Basic itempo = p3 ; Always set to 1 in score idur = p4 ; Duration in beats iamp = p5 ; Amplitude ifn = p6 ; Table number of stored sample ibeat = p7 ; Where in the loop to play, in beats event_i "i", $SampleEngine, 0, idur * itempo, itempo, iamp, ifn, ibeat, idur, 1, 0 turnoff endin instr $Swell itempo = p3 ; Always set to 1 in score iphrase_dur = p4 ; Duration of phrase in beats iamp = p5 ; Amplitude iamp_mult = p6 ; Amplitude multiplier for successive events ispace = p7 ; Time interval between notes ibeat = p8 ; Where in the loop to play, in beats ifn = p9 ; Table number of stored sample istutter = p10 ; Width of of stutter window, in beats istutter_mult = p11 ; Stutter window width multiplier for successive events itimer = 0 begin_loop: event_i "i", $Stutter, itimer * itempo, itempo, ispace, iamp, ifn,\ ibeat, istutter iamp = iamp * iamp_mult istutter = istutter * istutter_mult itimer = itimer + ispace if itimer < iphrase_dur igoto begin_loop turnoff endin instr $Stutter itempo = p3 ; Always set to 1 in score idur = p4 ; Duration in beats iamp = p5 ; Amplitude ifn = p6 ; Table number of stored sample ibeat = p7 ; Where in the loop to play, in beats istutter = p8 ; Width of of stutter window, in beats event_i "i", $SampleEngine, 0, idur * itempo, itempo, iamp, ifn, ibeat,\ istutter, 1, 0 turnoff endin instr $RandomPhrase itempo = p3 ; Always set to 1 in score iphrase_dur = p4 ; Duration of phrase ispace = p5 ; Time between notes idur = p6 ; Duration in beats of notes iamp = p7 ; Amplitude ifn = p8 ; Table number of stored sample itimer = 0 begin_loop: event_i "i", $Random, itimer * itempo, itempo, idur, iamp, ifn itimer = itimer + ispace if itimer < iphrase_dur igoto begin_loop turnoff endin instr $Random itempo = p3 ; Always set to 1 in score idur = p4 ; Duration in beats iamp = p5 ; Amplitude ifn = p6 ; Table number of stored sample Sobject sprintf "f%d", ifn inbeats objget_i Sobject, "nbeats" ; Randomly select which beat from loop to play irandom random 0, inbeats ibeat = int(irandom) event_i "i", $SampleEngine, 0, idur * itempo, itempo, iamp, ifn, ibeat,\ idur, 1, 0 turnoff endin instr $Flam itempo = p3 ; Always set to 1 in score idur = p4 ; Duration in beats iamp = p5 ; Amplitude ifn = p6 ; Table number of stored sample ibeat = p7 ; Where in the loop to play, in beats ioffset = p8 ; Time interval between the two notes imult = p9 ; Amplitude multiplier for second note ioverlap = p10 ; Overlap samples (Non-zero), or not (0) if ioverlap != 0 then idur_0 = idur * itempo else idur_0 = ioffset * itempo endif event_i "i", $SampleEngine, 0, idur_0, itempo, iamp, ifn, ibeat,\ idur, 1, 0 event_i "i", $SampleEngine, ioffset * itempo, idur * itempo, itempo,\ iamp * imult, ifn, ibeat, idur, 1, 0 turnoff endin ; Sample Engine instr $SampleEngine idur = p3 ; Duration of sample itempo = p4 ; Tempo of score, in beats-per-second iamp = p5 ; Amplitude ifn = p6 ; Function number of sample table ibeat = p7 ; Which beat to play istutter = p8 ; Width of stutter window, in beats ipitch = p9 ; Alter pitch. 1 = no pitch shifting irelative_pitch = p10 ; Is pitch relative to tempo (0) or absolute (!0) ; Get information about original file Sobject sprintf "f%d", ifn ilength objget_i Sobject, "length" inbeats objget_i Sobject, "nbeats" isample_rate objget_i Sobject, "samplerate" isample_tempo objget_i Sobject, "tempo" ; Determine whether to use relative or absolute pitch if irelative_pitch == 0 then ipitch_mod = 1 / itempo ; Relative else ipitch_mod = 1 / (60 / isample_tempo) ; Absolute endif ; Rate to read through sample. Determines pitch. iphasor_freq = ipitch_mod / istutter ; Get the width of the window, in samples. iwindow_length = ilength / inbeats * istutter ; Phasor that reads through sample table a1 phasor iphasor_freq * ipitch ; Play sample atable tablei a1 * iwindow_length, ifn, 0, ilength * ibeat / inbeats, 1 out atable * iamp endin # define LoadSample # 1 # # define Basic # 2 # # define Swell # 3 # # define Stutter # 4 # # define RandomPhrase # 5 # # define Random # 6 # # define Flam # 7 # # define SampleEngine # 8 # ; Set BMP t 0 105 ; Original Tempo ;t 0 170 ; DnB ;t 0 80 ; "Slower's better. Trust me, I'm a doctor." - Dr. Dre ; Load sample into an f-table i $LoadSample 0 1 100 "105 Blanketed Lama.wav" 1 16 ; Measure 1-4 i $Basic 0 1 1 0.5 100 0 i $Basic 1 . . . 100 1 i $Basic 2 . . . 100 1.5 i $Basic 3 . . . 100 3 i $Basic 4 . . . 100 2 i $Stutter 5 1 0.25 0.25 100 1 [1 / 16] i $Stutter 5.25 1 0.25 0.25 100 1 [1 / 12] i $Basic 5.5 1 0.5 0.5 100 2 i $Basic 6 . 1 . 100 14 i $Swell 7 1 1 0.5 0.5 0.25 12 100 [1 / 12] 1 i $Basic 8 1 1 0.5 100 0 i $Basic 9 . . . 100 1 i $Swell 10 1 1 0.06125 2 0.25 12 100 [1 / 12] 1 i $Flam 11 1 0.25 0.6 100 7 0.02 0.3333 0 i $Basic 11.5 1 0.5 0.3 100 7 i $Stutter 12 1 1 0.6 100 3.125 [1 / 6] i $Basic 12.5 1 0.5 0.5 100 0 i $Basic 13 1 1 0.5 100 13 i $Basic 14 . . . 100 14 i $Basic 15 . 0.5 . 100 1 i $Stutter 15.5 1 0.5 0.5 100 3.125 [1 / 8] ; Measures 5-8 i $Basic 16 1 1 0.5 100 0 i $Basic 17 . . . 100 3 i $Basic 18 . . . 100 1.5 i $Basic 19 . . . 100 1 i $Basic 20 . . . 100 2 i $Stutter 21 1 0.25 0.25 100 1 [1 / 12] i $Stutter 21.25 1 0.25 0.25 100 1 [1 / 8] i $Basic 21.5 1 0.5 0.5 100 2 i $Basic 22 . 1 . 100 14 i $Stutter 23 1 0.25 0.5 100 12 [1 / 16] i $Stutter 23.25 1 0.25 0.25 100 . [1 / 16] i $Stutter 23.5 1 0.25 0.125 100 . [1 / 18] i $Stutter 23.75 1 0.25 0.06125 100 . [1 / 22] i $Stutter 24 1 0.3 0.03 100 . [1 / 28] i $Basic 24 1 1 0.5 100 0 i $Basic 25 . . . 100 1 i $Stutter 26 1 0.25 0.06125 100 12 [1 / 28] i $Stutter 26.25 1 0.25 0.125 100 . [1 / 22] i $Stutter 26.5 1 0.25 0.25 100 . [1 / 18] i $Stutter 26.75 1 0.25 0.5 100 . [1 / 16] i $Stutter 27 1 0.25 0.5 100 . [1 / 15] i $Flam 27 1 0.25 0.6 100 7 0.02 0.5 0 i $Basic 27.5 1 0.5 0.4 100 7 i $Basic 27.75 . 0.5 . 100 0 i $Stutter 28 1 1 0.5 100 3.125 [1 / 5] i $Basic 28.5 1 0.5 0.5 100 0 i $Basic 29 1 1 0.5 100 13 i $Basic 30 . . . 100 14 i $Basic 31 . 0.5 . 100 1 i $Basic 31.5 . 0.25 . 100 1 i $Basic 31.75 . 0.25 . 100 1 i $Stutter 31.5 1 0.5 0.5 100 3.125 [1 / 8] ; Measures 9 - 12 i $Basic 32 1 1 0.5 100 0 i $Basic 33 . . . 100 1 i $Basic 34 . . . 100 1.5 i $Basic 35 . . . 100 3 i $Basic 36 . . . 100 2 i $Stutter 37 1 0.25 0.25 100 1 [1 / 16] i $Stutter 37.25 1 0.25 0.25 100 1 [1 / 12] i $Basic 37.5 1 0.5 0.5 100 2 i $Basic 38 . 1 . 100 14 i $Swell 39 1 1 0.5 0.5 0.25 12 100 [1 / 12] 1 i $Basic 40 1 1 0.5 100 0 i $Basic 41 . . . 100 1 i $Swell 42 1 1 0.06125 2 0.25 12 100 [1 / 12] 1 i $Flam 43 1 0.25 0.6 100 7 0.02 0.3333 0 i $Basic 43.5 1 0.5 0.3 100 7 i $Stutter 44 1 1 0.6 100 3.125 [1 / 6] i $Basic 44.5 1 0.5 0.5 100 0 i $Basic 45 1 1 0.5 100 13 i $Basic 46 . . . 100 14 i $Basic 47 . 0.5 . 100 1 i $Stutter 47.5 1 0.5 0.5 100 3.125 [1 / 8] ; Measures 13-16 i $Basic 48 1 1 0.5 100 0 i $Basic 49 . . . 100 3 i $Basic 50 . . . 100 1.5 i $Basic 51 . . . 100 1 i $Basic 52 . . . 100 2 i $Stutter 53 1 0.25 0.25 100 1 [1 / 12] i $Stutter 53.25 1 0.25 0.25 100 1 [1 / 8] i $Basic 53.5 1 0.5 0.5 100 2 i $Basic 54 . 1 . 100 14 i $Stutter 55 1 0.25 0.5 100 12 [1 / 16] i $Stutter 55.25 1 0.25 0.25 100 . [1 / 16] i $Stutter 55.5 1 0.25 0.125 100 . [1 / 18] i $Stutter 55.75 1 0.25 0.06125 100 . [1 / 22] i $Stutter 56 1 0.3 0.03 100 . [1 / 28] i $Basic 56 1 1 0.5 100 0 i $Basic 57 . . . 100 1 i $Stutter 58 1 0.25 0.06125 100 12 [1 / 28] i $Stutter 58.25 1 0.25 0.125 100 . [1 / 22] i $Stutter 58.5 1 0.25 0.25 100 . [1 / 18] i $Stutter 58.75 1 0.25 0.5 100 . [1 / 16] i $Stutter 59 1 0.25 0.5 100 . [1 / 15] i $Flam 59 1 0.25 0.6 100 7 0.02 0.5 0 i $Basic 59.5 1 0.5 0.4 100 7 i $Basic 59.75 . 0.5 . 100 0 i $Stutter 60 1 1 0.5 100 3.125 [1 / 5] i $Basic 60.5 1 0.5 0.5 100 0 i $Basic 61 1 1 0.5 100 13 i $Basic 62 . . . 100 14 i $Basic 63 . 0.5 . 100 1 i $Basic 63.5 . 0.25 . 100 1 i $Basic 63.75 . 0.25 . 100 1 i $Stutter 63.5 1 0.5 0.5 100 3.125 [1 / 8] ; Random hits in Measures 9-16 i $RandomPhrase 32.25 1 32 1 0.25 0.2 100 e