first commit of data sonification project first day

master
Rob Canning 2023-09-24 22:42:30 +02:00
commit 55596d6c07
1 changed files with 86 additions and 0 deletions

86
sc/witw.scd 100644
View File

@ -0,0 +1,86 @@
/*RUN*/
s.options.numInputBusChannels = 4;
s.options.numOutputBusChannels = 4;
~dataPath = "/home/rob/konS/witw/data/D7-80-BE-2C-63-BD/all-data/"; // CHANGE THIS TO RELATIVE PATH
"echo curl -v -X POST http://3.139.191.80:2537/devices/dev:864475040526732/all-data/2023-09-20T16:52:21Z -H 'Authorization: Bearer token' --output dev:864475040526732.zip".unixCmd;
s.waitForBoot{
// create 8 control busses to pass data between synths
~ctrlBus = 8.collect({arg i; Bus.control(s,1); });
SynthDef(\sgrain, { | out=0, atk=0.01, dcy=0.01, freq=100, pan=0, amp=0.5|
var sig, env;
env = EnvGen.ar(Env.perc(atk, dcy), doneAction: 2);
sig = FSinOsc.ar(freq);
sig = sig * (env * amp);
sig = Pan2.ar(sig, pan);
Out.ar(out, sig);
Out.kr(~ctrlBus[0],freq)
}).add;
SynthDef(\sslew, {
| out = 0, freq=100, amp = 0.05, slewrate = 1|
var sig, z;
// add slew rate on frequency
z = Slew.kr(freq, slewrate, slewrate);
sig = Blip.ar(z, 5, amp).dup;
Out.ar(out, sig)
}).add;
// load and process the data source /////////////////////////////////
// need to strip the header and the date // or the : from datetime and the header
// strip first 6 rows after header to stop gps data spilling
// todo preprocess file with Sed
// growing degree days causes nil in other fields - filter these out
~csvFile=CSVFileReader.readInterpret(~dataPath ++ "sensor_data-notime-noheader-cutrows1.csv",true,true);
// flatten ~data from 2D Array to regular array (per column);
~data = ( ~csvFile[0].size ).collect({ arg itt;
Array.fill( ~csvFile.size,{ arg i;
~csvFile.at(i).asArray.at(itt)});
});
~data[0]; // Temperature C
~data[1]; // F
~data[10]; // wind speed MPH
~data[11]; // wind direction
~data[13]; // wind gusts MPH
~data[5]; // rain bucket capacity
~data[6]; // rain bucket tips per minute?
~data[20]; // LON
~data[21]; // LAT
// normalize data ranges //////
~freq=~data[0].normalize(20, 5000);
~atk=~data[0].normalize(0.02, 0.1);
~dcy=~data[0].normalize(0.05, 0.3);
~dur=~data[0].normalize(0.01, 0.3);
~level=~data[0].normalize(0.01, 0.1);
//start the slewing synth /////////////////////////////
~sslew1 = Synth(\sslew,[\out,0,\freq,220,\amp,0.01,\slewrate,1000]);
~sslew1.map(\freq, ~ctrlBus[0]); // map control bus to freq parameter
// perform the data sonification /////////////////////
( p = Pbind(\instrument, \sgrain,
\freq, Pseq(~freq.round(300),1),
\atk, Pseq(~atk,1),
\dcy, Pseq(~dcy,1),
\pan, Pseq([0,1], inf),
\dur, Pseq(~dur,1),
\amp, Pseq(~level,1)
).play;
);
}; // closes s.waitForBoot
p.stop;