Thursday, July 13, 2017

ex2D02. Live Input

# ex2D02.py
# Live Input

from moduleCsound import *

add(startSyn)

add(startOpt)
add("-iadc -odac -B512 -b128")
add(stopOpt)

add(startIns)

header(ksmps=32)

add("""
instr 1
aIn       inch      1   ;take input from channel 1
kInLev    downsamp  aIn ;convert audio input to control signal
          printk    .2, abs(kInLev)
;make modulator frequency oscillate 200 to 1000 Hz
kModFreq  poscil    400, 1/2
kModFreq  =         kModFreq+600
aMod      poscil    1, kModFreq ;modulator signal
aRM       =         aIn * aMod ;ring modulation
          outch     1, aRM, 2, aRM ;output to channel 1 and 2
endin
""")

tags(2)

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

writeRun(__file__, False)

ex2D01. Get Device List

# ex2D01.py
# Get Device List

from moduleCsound import *

add(startSyn)

add(startOpt)
add("-iadc999 -odac999")
add(stopOpt)

add(startIns)

header(ksmps=32)

add("""
instr 1
endin
""")

tags(2)

tags(3)

writeRun(__file__, False)

ex2C03. Midi All In

# ex2C03.py
# Midi All In

from moduleCsound import *

add(startSyn)

add(startOpt)
add("-+rtmidi=virtual -Ma -odac")
add(stopOpt)

add(startIns)

header(ksmps=32)

add("""
instr 1
kStatus, kChan, kData1, kData2 midiin

if kStatus != 0 then ;print if any new MIDI message has been received
    printk 0, kStatus
    printk 0, kChan
    printk 0, kData1
    printk 0, kData2
endif

endin
""")

tags(2)

add("i1 0 3600")

tags(3)

writeRun(__file__, False)

ex2C02. Midi Controller In

# ex2C02.py
# Midi Controller In

from moduleCsound import *

add(startSyn)

add(startOpt)
add("-+rtmidi=virtual -M1 -odac")
add(stopOpt)

add(startIns)

header(ksmps=32)

add("""
instr 1
; --- receive controller number 1 on channel 1 and scale from 220 to 440
kFreq ctrl7  1, 1, 220, 440
; --- use this value as varying frequency for a sine wave
aOut  poscil 0.2, kFreq
      outs   aOut, aOut
endin
""")

tags(2)

add("i 1 0 60")

tags(3)

writeRun(__file__, False)

ex2C01. Midi Keyboard In

A MIDI Keyboard can be read acting as score for instrument 1. Note I have changed writeRun to change run parameter to False. This will only create csound .csd file.


# ex2C01.py
# Midi Keyboard In

from moduleCsound import *

add(startSyn)

add(startOpt)
add("-+rtmidi=portmidi -Ma -odac")
add(stopOpt)

add(startIns)

header(ksmps=32)

add("massign   0, 1 ;assign all MIDI channels to instrument 1")

add("""
instr 1
iCps    cpsmidi   ;get the frequency from the key pressed
iAmp    ampmidi   0dbfs * 0.3 ;get the amplitude
aOut    poscil    iAmp, iCps ;generate a sine tone
        outs      aOut, aOut ;write it to the output
endin
""")

tags(2)

tags(3)

writeRun(__file__, False)

ex2B01. Document Structure

# ex2B01.py
# Document Structure

from moduleCsound import *

tags(1)

header(ksmps=32, nch=1)

# --- instrument (440 Hz sig of 1 sec dur at 0.25 amp)

add("""
instr 1 ; a 440 Hz Sine Wave
aSin      poscil    0dbfs/4, 440
          out       aSin
endin
""")

tags(2)

add("i 1 0 1")

tags(3)

writeRun(__file__)

Output: (spectrograph view with setting of 8192 points, Blackmann-Harris window, and showing frequencies from 0 to 1000.



The reason for the lines at end is because it can not determine frequency there.

Tuesday, July 11, 2017

ex2A02. Hello Cabbage

This example requires the csound frontend called Cabbage be installed.


# ex2A02.py
# Hello Cabbage

from moduleCsound import *

add("""
<Cabbage>
form size(420,100)
keyboard bounds(10,10,300,80)
rslider bounds(325,15,80,80), channel("level"), text("Level"), range(0,1,0.3)
</Cabbage>
""")

tags(1)

header(ksmps=32)

# --- instrument

add("""
instr    1
 icps cpsmidi
 klev chnget  "level"
 a1   poscil klev*0.2,icps
      outs   a1,a1
endin
""")

add(stopIns, stopSyn)

writeRun(__file__)

ex3A05. Audio Vector