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/ Update (10/25/2009): User-defined opcodes and strings don't mix well on certain platforms. These have been commented out. *Attention* Window users will have to make changes small changes to get this running. See line 269 for details. Sorry for the inconvenience. :( Thanks to everyone on the Csound Mailing List who helped get this working on windows. Especially francibal, who ultimately found the solution. http://www.nabble.com/CSD-error-bug-with-stutter-instrument-on-windows--tt26041900.html sr = 44100 kr = 44100 ksmps = 1 nchnls = 1 0dbfs = 1.0 # define LoadSample # 1 # # define Basic # 2 # # define Stutter # 3 # # define Random # 4 # # define SampleEngine # 5 # 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 objset_S, 0, SSS Sval, Sobject, Smember xin Sname sprintf "%s.%s", Sobject, Smember chnset Sval, 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 opcode objget_a, a, SS Sobject, Smember xin Sname sprintf "%s.%s", Sobject, Smember aout chnget Sname xout aout endop ;opcode objget_S, S, SS ; Sobject, Smember xin ; Sname sprintf "%s.%s", Sobject, Smember ; Sout chnget Sname ; xout Sout ;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_S Sobject, "filename" objcreate_k Sobject, "samplerate" objcreate_k Sobject, "length" objcreate_k Sobject, "tempo" objcreate_k Sobject, "nbeats" ; Set Values objset_i ifn, Sobject, "ifn" ; objset_S Sfile, Sobject, "filename" objset_i isamplerate, Sobject, "samplerate" 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 $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 $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 ; 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 Stutter # 3 # # define Random # 4 # # define SampleEngine # 5 # ; 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 ; *Attention* ; Windows users, comment out the previous i-event, and use this line instead. ; Be sure to modify the name of the file to reflect this change: ;i $LoadSample 0 1 100 "BlanketedLama.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 $Stutter 7 1 0.25 0.5 100 12 [1 / 12] i $Stutter 7.25 1 0.25 0.25 100 . [1 / 12] i $Stutter 7.5 1 0.25 0.125 100 . [1 / 12] i $Stutter 7.75 1 0.25 0.06125 100 . [1 / 12] i $Basic 8 1 1 0.5 100 0 i $Basic 9 . . . 100 1 i $Stutter 10 1 0.25 0.06125 100 12 [1 / 12] i $Stutter 10.25 1 0.25 0.125 100 . [1 / 12] i $Stutter 10.5 1 0.25 0.25 100 . [1 / 12] i $Stutter 10.75 1 0.25 0.5 100 . [1 / 12] i $Basic 11 1 0.5 0.6 100 7 i $Basic 11.02 1 0.5 0.2 100 1 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 $Basic 27 1 0.5 0.6 100 7 i $Basic 27.02 1 0.5 0.3 100 1 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 $Stutter 39 1 0.25 0.5 100 12 [1 / 12] i $Stutter 39.25 1 0.25 0.25 100 . [1 / 12] i $Stutter 39.5 1 0.25 0.125 100 . [1 / 12] i $Stutter 39.75 1 0.25 0.06125 100 . [1 / 12] i $Basic 40 1 1 0.5 100 0 i $Basic 41 . . . 100 1 i $Stutter 42 1 0.25 0.06125 100 12 [1 / 12] i $Stutter 42.25 1 0.25 0.125 100 . [1 / 12] i $Stutter 42.5 1 0.25 0.25 100 . [1 / 12] i $Stutter 42.75 1 0.25 0.5 100 . [1 / 12] i $Basic 43 1 0.5 0.6 100 7 i $Basic 43.02 1 0.5 0.2 100 1 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 $Basic 59 1 0.5 0.6 100 7 i $Basic 59.02 1 0.5 0.3 100 1 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 $Random 32.25 1 0.25 0.333 100 i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . i $Random + . . . . e