-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.scd
More file actions
162 lines (127 loc) · 3.5 KB
/
tests.scd
File metadata and controls
162 lines (127 loc) · 3.5 KB
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
s.quit
s.boot
// allocates a 16-sample buffer and fills it with ascending values
b = Buffer.alloc(s,16);
b.setn(0, Array.series(16,1,1));
// read to check
b.getn(0,16, {|msg| msg.postln});
// apply gain
b.mul(-0.1)
// read to check (and appreciate the imprecision of 32bit float
b.getn(0,16, {|msg| msg.postln});
// apply reverse
b.reverse
// read to check
b.getn(0,16, {|msg| msg.postln});
// apply reverse
b.add(3.5)
// read to check
b.getn(0,16, {|msg| msg.postln});
////////////////////////////////////////////////////////////
// trying odd numbers of addresses, and odd number of samples
d = Buffer.alloc(s,15,3)
d.setn(0,Array.series(45,1,1))
d.getn(0,45, {|m| m.postln});
// reverse and observe the interleaved channels stay in line
d.reverse
d.getn(0,45, {|m| m.postln});
////////////////////////////////////////////////////////////
// trying audio
// load your favourite sound
b=Buffer.read(s,Platform.resourceDir +/+ "sounds/a11wlk01.wav")
// play it not too loud
b.play(true, 0.1)
// reverse it. there is a click when the buffer is updated
b.reverse
// stop
b.free
///////////////////////////////////////////////////////////
// adding dc offset
//load a file
b=Buffer.read(s,Platform.resourceDir +/+ "sounds/a11wlk01.wav")
// add DC for testing purpose
b.add(0.1)
// play and plot (nasty tick at the end)
b.play; b.plot
// remove DC
b.removeDC
// play and plot (nasty tick at the end)
b.play; b.plot
////////////////////////////////////////////////////////////
// chunk swapping
// allocates a 16-sample buffer and fills it with ascending values
b = Buffer.alloc(s,16);
b.setn(0, Array.series(16,0,1));
// read to check
b.getn(0,16, {|msg| msg.postln});
// apply chunkSwap method with default values (same as reverse)
b.chunkSwap
// read to check
b.getn(0,16, {|msg| msg.postln});
// apply on full range = changes nothing!
b.chunkSwap(0,b.numFrames-1,(b.numFrames * -1))
// read to check - tada!
b.getn(0,16, {|msg| msg.postln});
// reset to ascending values
b.setn(0, Array.series(16,0,1));
// apply with other values - indices are counting from 0
b.chunkSwap(3,7,3)
// read to check
b.getn(0,16, {|msg| msg.postln});
// reset to ascending values
b.setn(0, Array.series(16,0,1));
// apply with negative quantities (will read backwards and write frontwards)
b.chunkSwap(3,11,-3)
// read to check (and meditate on the result)
b.getn(0,16, {|msg| msg.postln});
// trying odd channel count.
c = Buffer.alloc(s,15,3)
c.setn(0,Array.series(45,0,1))
c.getn(0,45, {|m| m.postln});
// same as the mono example, respecting the interleaved channels
c.chunkSwap(3,7,3)
c.getn(0,45, {|m| m.postln});
// reset
c.setn(0,Array.series(45,0,1))
// same as the reverse mono example
c.chunkSwap(3,11,-3)
c.getn(0,45, {|m| m.postln});
////////////////////////////////////////////////////////////
// test in benchmarking
b=Buffer.read(s,Platform.resourceDir +/+ "sounds/a11wlk01.wav")
b.play(loop:true)
(
f = { |msg, time, replyAddr, recvPort|
if(msg[0] == '/done') {
c = time;
}
};
thisProcess.addOSCRecvFunc(f);
d = Main.elapsedTime;
100.do({b.reverse});
)
(
thisProcess.removeOSCRecvFunc(f);
(c-d);
)
////////////////////////////////////////////////////////////
//temp files version
(
d = Main.elapsedTime;
b.loadToFloatArray(action: {
arg array;
b.loadCollection(array.reverse, action:{c = Main.elapsedTime;});
});
)
(c-d);
////////////////////////////
// via osc (too slow for big file)
(
d = Main.elapsedTime;
b.getToFloatArray(action:{
arg array;
array.postln;
b.sendCollection(array.reverse, action:{c = Main.elapsedTime;});
});
)
(c-d);