-
Notifications
You must be signed in to change notification settings - Fork 0
/
atktry2.scd
172 lines (146 loc) · 3.42 KB
/
atktry2.scd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
(
var decoder;
decoder = FoaDecoderMatrix.newStereo((131/2).degrad,0.5);
SynthDef(\foaEncode1,{
var src,theta,phi,foa,out;
src = PinkNoise.ar(-6.dbamp);
// phi: azimuth theta: elevation
phi = MouseX.kr(pi,-pi);
theta=0;
foa = FoaPanB.ar(src,phi,theta);
out = FoaDecode.ar(foa,decoder);
//out.numChannels.postln;
Out.ar(0,out);
}).add;
)
(
var decoder,encoder;
decoder = FoaDecoderMatrix.newStereo((131/2).degrad,0.5);
encoder = FoaEncoderMatrix.newOmni;
SynthDef(\foaEncode2,{
var src,angle,azim,foa,out;
src = PinkNoise.ar(-6.dbamp);
/*phi: azimuth theta: elevation
phi = MouseX.kr(pi,-pi);
theta=0;*/
angle = MouseY.kr(pi/2,0);
azim = MouseX.kr(pi,-pi);
// foa = FoaPanB.ar(src,phi,theta);
foa = FoaEncode.ar(src,encoder);
foa = FoaTransform.ar(foa,'pushX',angle);
foa = FoaTransform.ar(foa,'rotate',azim);
out = FoaDecode.ar(foa,decoder);
//out.numChannels.postln;
Out.ar(0,out);
}).add;
)
a = Synth(\foaEncode2);
a.free;
(
var decoder;
decoder = FoaDecoderMatrix.newStereo((131/2).degrad,0.5);
a = Bus.audio(s,4);
SynthDef(\foaEncode3,{
arg outBus,duration=0.05,theta,phi;
var src,foa,env;
src = PinkNoise.ar(-6.dbamp);
env = EnvGen.kr(Env([0,1,0],[0.5,0.5],\sin),timeScale:duration,doneAction:2);
foa = FoaPanB.ar(src,phi,theta,env);
Out.ar(outBus,foa);
}).add;
SynthDef(\foaDecode,{arg inBus;
var foa,out;
foa = In.ar(inBus,4);
out = FoaDecode.ar(foa,decoder);
Out.ar(0,out);
}).add;
)
(
b = Synth(\foaDecode,[\inBus,a],1,\addToTail);
Routine.run({
20.do({
Synth(\foaEncode3,[\outBus,a,\theta,0,\phi,pi.rand2]);
0.1.wait;
})
});
b.free;
)
Routine{arg inval;
inval.postln;
}.value("hello routine");
(
r = Routine{
arg inval;
inval.postln;
inval = 123.yield;
111.postln;
inval.postln;
}
)
r.value("goodbyeroutine");
r.reset("reset");
r.stop("stop");
(
f = {"foo".postln };
g = {"bar".postln };
CmdPeriod.add(f);
CmdPeriod.add(g);
)
(
w = Window("close on cmd-.").front;
CmdPeriod.doOnce({w.close})
)
(
var score, bufnum, sndPath, duration, decoder, sampleRate, headerFormat, sampleFormat, numChannels;
var offset = 0.1;
score = Score.new;
bufnum = Server.default.bufferAllocator.alloc(1);
sndPath = Atk.userSoundsDir ++ "/b-format/Pampin-On_Space.wav";
SoundFile.use(
sndPath,
{arg soundFile;
headerFormat = soundFile.headerFormat;
sampleFormat = soundFile.sampleFormat;
sampleRate = soundFile.sampleRate;
numChannels = soundFile.numChannels;
duration = soundFile.duration;
}
);
decoder = FoaDecoderKernel.newUHJ(
sampleRate:sampleRate,
score:score
);
SynthDef(\kernelDecode,{arg buffer;
var out,src;
src = PlayBuf.ar(numChannels,buffer,BufRateScale.kr(buffer));
out = FoaDecode.ar(src,decoder);
Out.ar(0,out);
}).load;
score.add(
[0.0,
['b_allocRead',bufnum,sndPath,0,0],
['s_new','kernelDecode',1001,0,1,'buffer',bufnum]
],
);
score.add([duration,['n_free',1001]],);
score.add([duration+0.1,['b_free',bufnum]],);
// free the kernel buffers
decoder.kernel.do({arg bufs;
bufs.do({arg buf;
offset = offset + 0.1;
score.add([ duration + offset, [ 'b_free', buf.bufnum ]])
});
});
// add the needed dummy command to stop NRT
score.add([offset + duration + 0.2, [0]] );
// render our score to a sound file
o=ServerOptions.new.numOutputBusChannels=decoder.numChannels;
score.recordNRT("~/Desktop/abc.osc".standardizePath,
"~/Desktop/myDecode.wav".standardizePath,
sampleRate: sampleRate,
headerFormat: headerFormat,
sampleFormat: sampleFormat,
options: o
);
)
s.quit