Last active
June 21, 2017 10:03
-
-
Save helmholtz/20cc4d8374078bd22754 to your computer and use it in GitHub Desktop.
Dust to Dust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************* | |
DUST TO DUST | |
asStream, 3/14/2015 | |
Proof of Concept for DataCanvas Sonification | |
1. Make synth from Dust UGen | |
2. Get one previous days worth of dust data | |
3. Use routine to step through data at rate of | |
30min every 4 seconds | |
Dependencies: json, wslib, XML | |
********************************************/ | |
s.boot; | |
//SYNTHDEF | |
( | |
SynthDef(\dustSynth, {|out = 0, density| | |
Out.ar(out, Dust.ar(density, 0.5) ! 2) | |
}).add; | |
) | |
//MAIN | |
( | |
var getData, dustArray; | |
getData = {|city = "Shanghai", field = "dust", resolution = "30m"| | |
var date, dateStart, dateEnd, params, paramList, paramString, url, data; | |
paramList = List.new; | |
date = Date.getDate.gmtime; | |
dateEnd = date.format("%FT%H:%M:%SZ"); | |
date.day = date.day - 1; | |
dateStart = date.format("%FT%H:%M:%SZ"); | |
params = ('from': dateStart, | |
'before': dateEnd, | |
'fields': field, | |
'resolution': resolution, | |
'over.city': city); | |
params.keysValuesDo({|key, value| | |
paramList.add(key ++ "=" ++ value); | |
}); | |
paramString = paramList.join("&"); | |
url = "http://sensor-api.localdata.com/api/v1/aggregations/?" ++ paramString; | |
data = url.curl.parseJson.["data"]; | |
data.collect({|item| item[field].asInt}); | |
}; | |
dustArray = getData.value; | |
Routine({ | |
var sound = Synth(\dustSynth); | |
dustArray.do({|value| | |
sound.set("density", value.linlin(0,4000,0,40)); | |
value.postln; | |
4.wait; | |
}); | |
sound.free; | |
}).play; | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment