-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDataSetQuery.scd
More file actions
177 lines (149 loc) · 3.71 KB
/
Copy pathDataSetQuery.scd
File metadata and controls
177 lines (149 loc) · 3.71 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
code::
// Create a DataSet with known data
(
var dict = Dictionary.newFrom([
"cols",5,
"data",Dictionary.newFrom(
100.collect{
arg i;
var point = 5.collect{
arg j;
j+(i/100);
};
[i,point];
}.flatten
)
]);
//the integer part of the value is the dimension, and the fractional part is the identifier.
~ds = FluidDataSet(s).load(dict).print;
~tmpbuf = Buffer.alloc(s,5);
)
// Prepare a FluidDataSetQuery object
(
~query = FluidDataSetQuery(s);
~out = FluidDataSet(s);
// prepare a simple query
// select points where the value in column 0 is less than 0.04
~query.filter(0,"<",0.04);
~query.addColumn(2); // the column we actually want copied into ~out is column 2
~query.transform(~ds, ~out);
// check the result
~out.print;
)
(
//prepare a more complex query
~query.clear;
~query.filter(0,">",0.03);
~query.and(1,"<",1.08);
~query.or(2,">",2.98);
~query.addRange(2,3); // addRange will add 3 columns starting at column index 2
~query.transform(~ds, ~out);
// Check the results
~out.print;
)
::
STRONG:: Joining Datasets::
code::
// this is how to join 2 datasets, adding columns to items with the same identifier
// create 2 datasets
(
~dsA = FluidDataSet(s);
~dsB = FluidDataSet(s);
)
//feed them items with almost overlaping identifier lists but with different dimensions
(
~dsA.load(
Dictionary.newFrom([
\cols, 2,
\data, Dictionary.newFrom([
\zero, [0,0],
\one,[1,11],
\two,[2,22],
\three,[3,33],
\four,[4,44]
])
])
);
~dsB.load
(Dictionary.newFrom([
\cols, 2,
\data, Dictionary.newFrom([
\one,[111,1111],
\two,[222,2222],
\three,[333,3333],
\four,[444,4444],
\five,[555,5555]
])
])
);
~dsA.print;
~dsB.print;
)
// no query/filter defined, copies all with identifiers common to both sources, as well as appending any added column from the first source.
(
~ds_joined = FluidDataSet(s);
~joiner = FluidDataSetQuery(s);
~joiner.transformJoin(~dsA,~dsB,~ds_joined);
~ds_joined.print
)
(
// all the conditions applicable to 'transform' can be done on the first dataset too. Selected columns of the first source are appended to matching items in the second source.
~joiner.clear;
~joiner.filter(0,">",2.1);
~joiner.and(1,"<", 40);
~joiner.addColumn(0);
~joiner.transformJoin(~dsA,~dsB,~ds_joined);
~ds_joined.print;
)
::
strong::Audio Analysis Data::
code::
~src = Buffer.read(s,FluidFilesPath("Tremblay-ASWINE-ScratchySynth-M.wav"));
// take a listen
~src.play;
// make a dataset of pitch anlyses
(
~features = Buffer(s);
FluidBufPitch.processBlocking(s,~src,features:~features);
~ds_pitch = FluidDataSet(s).fromBuffer(~features);
~ds_pitch.print;
)
// select only the pitch analyses where the pitch confidence is > 0.9
(
~ds_filtered = FluidDataSet(s);
~dsq = FluidDataSetQuery(s);
~dsq.filter(1,">",0.9);
~dsq.addColumn(0);
~dsq.transform(~ds_pitch,~ds_filtered);
~ds_filtered.print;
)
// make another dataset of spectral analyses
(
FluidBufSpectralShape.processBlocking(s,~src,features:~features);
~ds_spec = FluidDataSet(s).fromBuffer(~features);
~ds_spec.print;
)
// select only the spectral analyses where the pitch confidence is > 0.9;
(
~ds_selected = FluidDataSet(s);
~dsq.clear;
~dsq.filter(1,">",0.9);
~dsq.transformJoin(~ds_pitch,~ds_spec,~ds_selected);
~ds_selected.print;
)
// or just append it all together to make one big dataset
(
~dsq.clear;
~dsq.addRange(0,2); // starting at column 0 add two columns (both of the columns in ~ds_pitch)
~dsq.transformJoin(~ds_pitch,~ds_spec,~ds_selected);
~ds_selected.print;
)
// or do it all at once:
(
~dsq.clear;
~dsq.filter(1,">",0.9); // only analyses where the pitch conf is high
~dsq.addColumn(0); // we'll take the pitch freq...
~dsq.transformJoin(~ds_pitch,~ds_spec,~ds_selected);// ... and append it to the spectral analyses
~ds_selected.print;
)
::