Friday, July 21, 2017

ex3A05. Audio Vector

# ex3A05.py
# Audio vector

from moduleCsound import *

tags(1)

header(ksmps=5)

add(r"""
instr 1
aSine      oscils     1, 2205, 0
kVec1      vaget      0, aSine
kVec2      vaget      1, aSine
kVec3      vaget      2, aSine
kVec4      vaget      3, aSine
kVec5      vaget      4, aSine
           printks    "kVec1 = %f, kVec2 = %f, kVec3 = %f, kVec4 = %f, kVec5 = %f\n",\
                      0, kVec1, kVec2, kVec3, kVec4, kVec5
endin
""")

tags(2)

add("i 1 0 [1/2205]")

tags(3)

writeRun(__file__)

ex3A04. Performance pass no increment

# ex3A04.py
# Performance pass no increment

from moduleCsound import *

tags(1)

header(ksmps=4410)

add("""
instr 1
kcount    =         0; sets kcount to 0 at each k-cycle
kcount    =         kcount + 1; does not really increase ...
          printk    0, kcount; print the value
endin
""")

tags(2)

add("i 1 0 1")

tags(3)

writeRun(__file__)

ex3A03. Performance pass increment listen

# ex3A03.py
# Performance pass increment listen

from moduleCsound import *

tags(1)

header(ksmps=441)

add("""
;build a table containing a sine wave
giSine     ftgen      0, 0, 2^10, 10, 1
""")

add("""
instr Rise
kFreq      init       100
aSine      poscil     .2, kFreq, giSine
           outs       aSine, aSine
;increment frequency by 10 Hz for each k-cycle
kFreq      =          kFreq + 10
;print out the frequency for the last k-cycle
kLast      release
 if kLast == 1 then
           printk     0, kFreq
 endif
endin

instr Partials
;initialize kCount
kCount     init       100
;get new frequency if kCount equals 100, 200, ...
 if kCount % 100 == 0 then
kFreq      =          kCount
 endif
aSine      poscil     .2, kFreq, giSine
           outs       aSine, aSine
;increment kCount
kCount     =          kCount + 1
;print out kFreq whenever it has changed
           printk2    kFreq
endin
""")

tags(2)

add("""
i "Rise" 0 3
i "Partials" 4 31
""")

tags(3)

writeRun(__file__)

Output (Spectrograph view):


ex3A02. Performance pass increment

# ex3A02.py
# Performance pass increment

from moduleCsound import *

tags(1)

# Each k-time is 0.1 sec

header(ksmps=4410)

add("""
instr 1
kCount    init      0; set kcount to 0 first
kCount    =         kCount + 1; increase at each k-pass
          printk    0, kCount; print the value
endin
""")

tags(2)

# There are 10 k-passes in 1 sec

add("i 1 0 1")

tags(3)

writeRun(__file__)

ex3A01. Initialization pass

# ex3A01.py
# Initialization pass

from moduleCsound import *

tags(1)

header(ksmps=32)

# global

add("giGlobal   =          1/2")

# instruments

add("""
instr 1
iLocal     =          1/4
           print      giGlobal, iLocal
endin

instr 2
iLocal     =          1/5
           print      giGlobal, iLocal
endin
""")

tags(2)

# Only Initialization of instr 1 and instr 2

add("""
i 1 0 0
i 2 0 0
""")

tags(3)

writeRun(__file__)

Thursday, July 13, 2017

ex2E02. Record Realtime

# ex2E02.py
# Record RealTime

from moduleCsound import *

add(startSyn)

add(startOpt)
add("-odac")
add(stopOpt)

add(startIns)

header(ksmps=32)

add("seed      0 ;each time different seed for random")

add("""
  instr 1
kFreq     randomi   400, 800, 1 ;random sliding frequency
aSig      poscil    .2, kFreq ;sine with this frequency
kPan      randomi   0, 1, 1 ;random panning
aL, aR    pan2      aSig, kPan ;stereo output signal
          outs      aL, aR ;live output
          fout      "live_record.wav", 18, aL, aR ;write to soundfile
  endin
""")

tags(2)

add("i 1 0 10")
tags(3)

writeRun(__file__)

ex2E01. Render

Because we give a filename from the command prompt, it will take greater precedence than the one in CsOptions.


# ex2E01.py
# Render

from moduleCsound import *

add(startSyn)

add(startOpt)
add("-o Render.wav")
add(stopOpt)

add(startIns)

header(ksmps=32, nch=1)

add("""
instr 1
aSin      poscil    0dbfs/4, 440
          out       aSin
endin
""")

tags(2)

add("i 1 0 1")
tags(3)

writeRun(__file__)

ex3A05. Audio Vector