16. Oscillator예제

{SinOsc.ar(LFNoise0.kr(100, LFNoise0.kr(5,500,550),550),0,0.5)}.scope
//Freq Mod:100*5/sec, random freq range 5000, amp: 0.5

{SinOsc.ar(LFNoise0.kr(100,100,150),0,0.5)}.scope
//Freq Mod: 100/sec, random freq range 100, amp: 0.5

{SinOsc.ar(SinOsc.kr(1,0,100,300),0,0.5)}.scope
//Freq : 1/sec, 250~350  (350-250)/2+300

{LFNoise0.ar(1000.rand,0.5)}.scope

{LFTri.ar(80.midicps,0,-11.dbamp)}.scope

{LFTri.ar(LFNoise0.kr(100,500,1000), mul: 0.1)}.scope
//Freq : 1/sec, Random range 500, from 500~1500 mul:0.1
{LFTri.ar(LFNoise0.kr(MouseY.kr(100,1000,1),500,1000), mul: 0.5)}.scope

{LFTri.ar(SinOsc.kr(LFNoise0.kr(10,100,500),0,500,500),mul: 0.5)}.scope
//Freq : 10,random100/sec(?), range 250~750), mul: 0.5

{LFTri.ar(SinOsc.kr(LFNoise0.kr(10,100,1000),0,500, LFNoise0.kr(1000,500,1000),mul:0.5))}.scope

{Saw.ar(440,Dust.kr(10,0.8))}.scope

{Saw.ar(MouseY.kr(100,1000,exponential),Dust.kr(100,0.8))}.scope
//freq: 100~1000, amp:0.8, Changing Density:100/sec
{SinOsc.ar(Dust.kr(1000,1000,1000),0,0.5)}.scope
//Noise. 1000Density, 1000 pulses

{Dust.ar(SinOsc.kr(10,mul:1000,add:1000),mul:0.8)}.scope
//Density:10/sec,til 1000, mul:0.8

{Dust.ar(100,1)}.scope

{Pulse.ar(10,SinOsc.kr(1,0,0.25,0.25),0.5)}.scope
{Pulse.ar(SinOsc.kr(0.1,0,1000),0.25,0.5)}.scope
{Pulse.ar(SinOsc.kr(0.1,0,100),SinOsc.kr(1,0,0.25,0.25),0.8)}.scope

{Pulse.ar(SinOsc.kr(0.5,0,100,100),SinOsc.kr(1,0,0.25,0.5),0.5)}.scope
//freq: for 2/1/sec til 100,

{LFNoise2.ar(1000,0.1)}.scope

{SinOsc.ar(SinOsc.ar(MouseY.kr(100,1000), 0, LFNoise1.kr(MouseX.kr(100,1000), 100,340)),0.6)}.scope
{SinOsc.ar(Pulse.ar(freq: 15, mul: 200, add: 1000), mul: 0.5)}.scope

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

15.Recording in real time/Buffers

15.Recording sound files in real time/Bufffer
파일에 recording을 하는 방법으로 서버윈도우의 버튼을 이용할수 있다.

(
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
})
)
                        
//서버 윈도우의 다음 버튼을 누른다.
  
   prepare rec
   record
   stop

//텍스트를 이용하여 레코딩을 컨트롤한다.
r.play
r.stop
r.reset.play

//레코딩 포멧 설정하기
(
s.recSampleFormat=”int24″;//”int8″, “int16”, “int24”, “int32”, “float”, “double”, “mulaw”, “alaw”
s.recHeaderFormat=”aidd”;//”aiff”, “next”, “wav”, “ircam””, “raw”
s.recHannels = 1;//mono

//파일이름 설정하기
s.prepareForRecord(“recordings/test1.aif”)
)

//레코딩과 플레이를 동시에

(
s.record;
r.reset.play;   // )

// 멈추기
r.stop;  // 레코딩을 멈추기 전에 플레잉이 끝날때 까지 기다려야 한다.
s.stopRecording;

//——————————————
Buffers

Buffers는 32-bit의 floating point values를 가진 array이다.
Buffers는 서버에 있기 때문에 synths에 의해 사용된다. are on the server so that they can be used by synths.

Buffers는 allocated되거나 filled되거나 freed되어야 한다.
Buffers가 allocated, loaded, freed됨과 동시에 synthesis를 실행시킬수 있다.
Buffers는 wave tables, sample buffers, delay lines등으로 사용될수 있다.
서버한의 buffer의 수는 boot time에 설정된다.

        Server.internal.options.numBuffers

Buffers는 0으로 시작한다.

buffer messages

[Server-Command-Reference] 참고        

다음은 몇개의 buffer command들:

/b_alloc //buffer space를 allocate
   buffer number
   number of frames
   number of channels (optional, default = 1)
   optional OSC message to execute on conclusion
  
/b_allocRead  //buffer space할당하고 sound file를 읽음
   buffer number
   path name of a sound file (as a string)
   starting frame (optional, default = 0)
   number of frames to read (optional, default = 0)
   optional OSC message upon completion
  
/b_free
   buffer number
   optional OSC message upon completion
  
/b_close
   buffer number (to close a soundfile)
  
s.sendMsg(“/b_allocRead”,0,”sounds/a11wlk01-44_1.aiff”)
s.sendMsg(“/b_close”,0)
s.sendMsg(“/b_free”,0)

//——————————————
PlayBuf

PlayBuf : a sample (buffer) playback oscillator
  (numChannels, bufnum, rate, trigger, startPos, loop)
  
  rate = 1 is no change, 2 is one octave up, …
  loop = 1 is true, 0 is false

s.sendMsg(“/b_allocRead”,0,”sounds/a11wlk01-44_1.aiff”) // allocate and read buffer 0

{ PlayBuf.ar(1,0,1,loop: 1) }.scope

s.sendMsg(“/b_allocRead”,0,”sounds/sax1.aiff”) // allocate buffer again and read in a different file (if available)

s.sendMsg(“/b_free”,0)  // free buffer when finished with it
//——————————————

Buffer class

Buffers 는 또한 Buffer class와 함께 접근될수있다. (메세지 스타일보다 편하게 사용될수 있음)

Buffer.read  buffer space할당하고 sound file를 읽음

         b = Buffer.read(s, “sounds/a11wlk01-44_1.aiff”);

        { PlayBuf.ar(1, b.bufnum, 1, loop: 1) }.scope
        
        // Mouse control of rate (transposition)

        { PlayBuf.ar(1, b.bufnum, MouseX.kr(0.5,2), loop: 1) }.scope  
                              
b.bufnum   // returns buffer number
b.numChannels   // returns the number of channels in the buffer

b.free  // return the memory and free buffer ID, IMPORTANT

(Memory 사용량은 Terminal application에서 체크 (using top))
//——————————————

BufRateScale

buffer로 읽혀지고 있는 파일이 SC에서 사용되는 셈플과 다른 rate을 가질때에
BufRateScale.kr(bufnum)는 soundfile의 재생에 맞게 ratio를 바꾸어 준다.

        b = Buffer.read(s, “sounds/a11wlk01.wav”);  // sample rate of this file is 11025
        
to scale the playback:
        { PlayBuf.ar(1, b.bufnum, BufRateScale.kr(b.bufnum), loop: 1) }.scope

     b.free
//——————————————
BufFrames
    
BufFrames.kr(bufnum)는 현재 할당된 frames의 수로 돌아간다.
이것은 버퍼의 중간부분에서 시작하는 설정등을 할때에 유용하다.

        b = Buffer.read(s, “sounds/a11wlk01-44_1.aiff”);
(        
        var start = 1/2;
        { PlayBuf.ar(1, b.bufnum, BufRateScale.kr(b.bufnum),
                startPos: BufFrames.kr(b.bufnum) * start, loop: 1)
     }.scope
)

위의 예제에서의 시작부분으로 돌아가도록 loop

a trigger (<= 0 to > 0) causes the playback to start from startPos

//  using a trigger without looping
Impulse.kr 는 특정 freqyency에서 trigger를 만든다.

(        
        var start = 1/2;
        { PlayBuf.ar(1, b.bufnum, BufRateScale.kr(b.bufnum),
                Impulse.kr(1/3),
                startPos: BufFrames.kr(b.bufnum) * start, loop: 0)
     }.scope
)

// using a trigger with looping:

trigger는 다음 frequency에서 발생:
  (serverSampleRate / numberOfFrames) * rateScale
    
s.sampleRate  // the server’s sample rate

    
(        
        var start = 1/2;
        { PlayBuf.ar(1, b.bufnum, BufRateScale.kr(b.bufnum),
                     Impulse.kr(s.sampleRate / (BufFrames.kr(b.bufnum) * start) *
                            BufRateScale.kr(b.bufnum)),
                startPos: BufFrames.kr(b.bufnum) * start, loop: 1)
     }.scope
)    
    
      b.free
//——————————————
http://csound.x-y.net
Ji Youn Kang,
Csound Max Community

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