14 NoiseWindow,Score

14 NoiseWindow,Score

-Noise Window
;filtered noise with window

//window;
Env.sine(1,1).plot

//SynthDef
(
SynthDef(noiseWindow, {
        |dur = 1, cf = 1000, rq= 0.01, amp = 0.4|
        Out.ar(0,
                BPF.ar(WhiteNoise.ar,
                                cf,rq)
                                *
                EnvGen.kr(Env.sine(dur,amp), doneAction:2))
        }).load(s)
)

// instance
Synth(noiseWindow)
// routine

(
r = Routine({
        {Synth(noiseWindow,
                [cf,rrand(500,1500), rq, rrand(0.008, 0.02),
                amp, rrand(0.1,0.9), dur,rrand(0.6,2)]);
        rrand(0.5,5).yield;
        }.loop
})
)
r.play;
r.stop;
r.reset.play;

// another Routine

(
r = Routine({
        {Synth(noiseWindow,
                [cf, rrand(500,2500), rq, 0.005,
                amp,1, dur, rrand(0.5,3)]);
                rrand(0.01, 0.1).yield;
        }.loop
})
)
//——————————————

-Routine as a score

// sine1 SynthDef

(
SynthDef(“sine1”,{arg freq = 440, amp = 0.2, dur = 2.0, attack = 0.25, decay = 0.25;
        var ssTime = dur * (1- attack – decay);
        var attackTime = dur * attack;
        var decayTime = dur * decay;
        Out.ar(0,
                SinOsc.ar(freq, 0, amp)
                        * EnvGen.kr(Env.linen(attackTime, ssTime, decayTime,1), doneAction: 2)
                        )
}).load(s)
)
//one instance
Synth(sine1)

//several instances (to be evaluated in sequence)
Synth(sine1,[freq,62.midicps]);
Synth(sine1, [freq,67.midicps]);
Synth(sine1, [freq,67.midicps]);
Synth(sine1, [freq,69.midicps, dur,1]);
Synth(sine1, [freq,71.midicps,dur,1]);
Synth(sine1, [freq,72.midicps,dur,1]);
Synth(sine1, [freq,69.midicps,dur,1]);
Synth(sine1, [freq,71.midicps,dur,2]);
Synth(sine1, [freq,69.midicps,dur,1]);
Synth(sine1, [freq,71.midicps,dur,1]);
Synth(sine1, [freq,72.midicps,dur,2]);
Synth(sine1, [freq,71.midicps,dur,2]);
Synth(sine1, [freq,69.midicps,dur,1]);
Synth(sine1, [freq,67.midicps,dur,1]);
Synth(sine1, [freq,69.midicps,dur,2]);
Synth(sine1, [freq,67.midicps,dur,4]);
// in a Routine, things can happen with a wait before the next event

(
Routine({
Synth(sine1,[freq,62.midicps]);
2.yield;
Synth(sine1, [freq,67.midicps]);
2.yield;
Synth(sine1, [freq,67.midicps]);
2.yield;
Synth(sine1, [freq,69.midicps, dur,1]);
1.yield;
Synth(sine1, [freq,71.midicps,dur,1]);
1.yield;
Synth(sine1, [freq,72.midicps,dur,1]);
1.yield;
Synth(sine1, [freq,69.midicps,dur,1]);
1.yield;
Synth(sine1, [freq,71.midicps,dur,2]);
2.yield;
Synth(sine1, [freq,69.midicps,dur,1]);
1.yield;
Synth(sine1, [freq,71.midicps,dur,1]);
1.yield;
Synth(sine1, [freq,72.midicps,dur,2]);
2.yield;
Synth(sine1, [freq,71.midicps,dur,2]);
2.yield;
Synth(sine1, [freq,69.midicps,dur,1]);
1.yield;
Synth(sine1, [freq,67.midicps,dur,1]);
1.yield;
Synth(sine1, [freq,69.midicps,dur,2]);
2.yield;
Synth(sine1, [freq,67.midicps,dur,4]);
}).play(SystemClock)
)

참고: events가 위에서는 같은 synthDef를 사용했으나 다른것들을 사용해도 된다.

//——————————————
-Score object
score object는 non-realtime computing에 주로 사용되나 realtime으로도 사용가능하다.
score object는 OSC메세지를 사용해야하며 the various convenience methods사용을 할수 없다.

OSC message
/s_new, synthdef, node, action, target
        
        action (0 is add to head, 1 is add to tail)
        targett is target ID (e.g. 0)

/c_set, bus index, control value
        
        this message should conclude the messages for non-realtime use
        
Score object는 메세지를 보내기 위해 beet단위의 메세지 리스트를 포함한다.

그 리스트는 non-realtime에서는 /c_set을 사용해야하며, realtime에서는 unnecessary.

// make an instance
z =Score.new

//define a list of timed OSC commands
(
x = [
[0,[s_new,sine1,1000,0,0,freq,62.midicps]],
[2,[s_new,sine1,1000,0,0,freq,67.midicps]],
[4,[s_new,sine1,1000,0,0,freq,67.midicps]],
[6,[s_new,sine1,1000,0,0,freq,69.midicps,dur,1]],
[7,[s_new,sine1,1000,0,0,freq,71.midicps,dur,1]],
[8,[s_new,sine1,1000,0,0,freq,72.midicps,dur,1]],
[9,[s_new,sine1,1000,0,0,freq,69.midicps,dur,1]],
[10,[s_new,sine1,1000,0,0,freq,71.midicps,dur,2]],
[12,[s_new,sine1,1000,0,0,freq,69.midicps,dur,1]],
[13,[s_new,sine1,1000,0,0,freq,71.midicps,dur,1]],
[14,[s_new,sine1,1000,0,0,freq,72.midicps,dur,2]],
[16,[s_new,sine1,1000,0,0,freq,71.midicps,dur,2]],
[18,[s_new,sine1,1000,0,0,freq,69.midicps,dur,1]],
[19,[s_new,sine1,1000,0,0,freq,67.midicps,dur,1]],
[20,[s_new,sine1,1000,0,0,freq,69.midicps,dur,2]],
[22,[s_new,sine1,1000,0,0,freq,67.midicps,dur,4]],
[26,[c_set,0,0]] // finish
]
)

// assign list to score
z.score = x;

// score is played using TempoClock, time is in beats;

// to play or stop

z.play
z.stop

If there is a node problem, all nodes on the server can be
released with

s.freeAll

//——————————————
-Sound file rendering(non-realtime synthesis)
Score.write(x, “recordings/score-test.osc”);//write score list to file
//render osc file using the server(scsynth)
“./scsynth -N recordings/score-test.osc _ recordings/score-test.aiff 44100 AIFF int16 -o 1”.unixCmd;

위의 string은 (“”빼고) a terminal command line로서 enter될수도 있다.

Calls scsynth
-N : nonreal time
recordings/score-test.osc : the path for the binary file with osc commands
-no audio input file
recordings/score-test.aiff : the name of the sample rate
sample format
option:1 (mono)
더 많은정보는 여기에 Non-Realtime-Synthesis

//——————————————
http://csound.x-y.net
Ji Youn Kang,
Csound Max Community

13 Synthdefs/Routines

13 Synthdefs Routines

1. Frequency Modulation

envelope 없는 간단한 FM의 예제
(
var carrierFreq = 400, modFreq = 50, deviation = 100;
{        SinOsc.ar(carrierFreq + SinOsc.ar(modFreq, mul: deviation),
                        mul: 0.3);
}.scope
)

같은것을 다음과 같이 간단화 시킬수 있다.
(
var carrierFreq = 400, modFreq = 50, deviation = 100;
{        SinOsc.ar(SinOsc.ar(modFreq, mul:deviation, add: carrierFreq),
                        mul:0.3);
}.scope
)

2. Phase Modulation

PM은 FM과 비슷하지만, frequency 대신 Phase가 modulate된다.

PMOsc가 사용된다;
PMOsc.ar(carfreq, modfreq, index, modphase, mul, add)
        index는 radian에서의  modulation index
        modphase는 radians에서 modulator를 위한 modulation input.

{ PMOsc.ar(Line.kr(600, 900, 5), 600, 3, 0, 0.1)}.play// modulation carfreq
{ PMOsc.ar(300, Line.kr(600, 900, 5),3,0,0.1)}.play// modulate modfreq
{ PMOsc.ar(300, 550, Line.ar(0,20,8), 0, 0.1)}.scope// modulate index

(
var carrierFreq = 400, modFreq = 50, index = 3, decayTime = 5;
{ EnvGen.kr(Env.perc(0.001, decayTime, 0.2), 1, doneAction:2) * PMOsc.ar(carrierFreq, modFreq, index,0);
}.scope
)

calculate modFreq from cmRatio:
(
var carrierFreq = 400, modFreq, cmRatio = 1.5, index = 3, decayTime = 5;
modFreq = (carrierFreq * cmRatio.reciprocal).postln;
{        EnvGen.kr(Env.perc(0.001, decayTime, 0.2), 1, doneAction: 2) *
        PMOsc.ar(carrierFreq, modFreq, index, 0);
}.scope
)

– as SynthDef

SynthDef(name, {function})
load, send, writeDef, play

SynthDef는 반드시 Output bus 에 무엇인가를 보내야 한다;
Out.ar(bus, value)

(
SynthDef(pmgrain, {
        |carrierFreq = 400, cmRatio = 1.5, index = 3, decayTime = 0.01, amp = 1|
        
        var signal, modFreq;
        
        modFreq = (carrierFreq * cmRatio.reciprocal);
        signal =
                EnvGen.kr(Env.perc(0.001, decayTime, 0.2),1,amp, doneAction: 2) *
                PMOsc.ar(carrierFreq, modFreq, index, 0);
        
        Out.ar(0, signal)
}).load(s)
)

//위의 구문을 실행햐여 정의를 내린다.
//아래와 같은 방법으로 불러낸다.
//definition내의 arguments들의 값을 다음과 같이 변경시킬수 있다.

Synth(pmgrain, [decayTime, 5])
Synth(pmgrain, [decayTime, 1, carrierFreq, 200])

-with Routines

Routine({function})
//random carrierFreqs and random offset between events
//loops indefinitely

(
Routine({
        {Synth(pmgrain, [carrierFreq, rrand(1000.0,5100)]);
                rrand(0.001,0.1).wait;
        }.loop
        }).play(SystemClock)
)
        
//with more layers
(
a= {Routine({
        {Synth(pmgrain, [carrierFreq, rrand(1000.0,5100)]);
                rrand(0.5,0.8).wait;
        }.loop
        })
        } ! 10// be careful how many layers are used
)

play the array of routines
a.do({|i| i.play(SystemClock)})
stop the array of routines:
a.do({|i| i.stop})
reset and play the array of routines
   a.do({|i| i.reset.play(SystemClock)})

//——————————————
http://csound.x-y.net
Ji Youn Kang,
Csound Max Community

참고 : SC3의 crash

SC3에서 이유없는 crash와 이유없이 서버 작동이 아주 간단한 작업에서도 멎어버리는 현상은 주로 한글시스템의 이용과 한글사용에 있습니다.

안정적으로 사용하시려면 시스템을 영문으로 바꾸고
스크립트에 한글을 사용하지 않는것이 좋더군요!
참고하시라구요~ ^-^