Debian Codegraph @

examples/serialWrite.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 ; Select audio/midi flags here according to platform
4 -n ;;;no output
5 ;-iadc ;;;uncomment -iadc if realtime audio input is needed too
6 ; For Non-realtime ouput leave only the line below:
7 ; -o serialWrite.wav -W ;;; for file output any platform
8 </CsOptions>
9 <CsInstruments>
10
11 sr = 44100
12 ksmps = 500 ; the default krate can be too fast for the arduino to handle
13 nchnls = 2
14 0dbfs = 1
15
16 instr 1
17
18 iPort serialBegin "/dev/cu.usbmodemfa131", 9600 ;connect to the arduino with baudrate = 9600
19
20 kGain init 16 ;read our knob value
21 kVal serialRead iPort
22 if (kVal != -1) then
23 kGain = kVal/128
24 endif
25
26 aSig in ;get our audio input and get its rms
27 kRms rms aSig*kGain
28
29 kRms = kRms*kRms*255 ;scale the rms to a good value for the LED and send it out
30 serialWrite iPort, (kRms < 255 ? kRms : 255) ;must be in range: 0-255
31
32 endin
33 </CsInstruments>
34 <CsScore>
35 f 1 0 1024 10 1 1 1 1 1 1
36
37 i 1 0 200
38 e
39 </CsScore>
40 </CsoundSynthesizer>
41