androsensor

clean-up: #53

below some code for reading and parsing data from the android app AndroSensor.
with this free app you can record a lot of different sensors in your android phone (like gps, accel, mic, battery, light etc etc) and save it to a comma separated file (csv). later one can copy over the data file from the android phone to a computer and read it in supercollider. the csv files are normally stored on the sd card in a folder called AndroSensor.

by default the app only save and display data at slow update rates, so go into the AndroSensor's settings and change update interval to very fast and recording interval to for example 0.05 seconds (the fastest).

// https://play.google.com/store/apps/details?id=com.fivasim.androsensor

//--read the data - edit the path to your csv file
(
var path= "~/Desktop/Sensor_record_20141018_115750_AndroSensor.csv"; //edit here
var data= CSVFileReader.read(path.standardizePath, delimiter:$;, startRow:1);
var data2= data.flop;
var dict= ();
data2.do{|x|
        var key= x[0];
        var val= x.copyRange(1, x.size-1);
        while({key.last==Char.space or:{key.last==$:}}, {
                key= key.copyRange(0, key.size-2);
        });
        if(val[0].any{|x| #[$:, $/].includes(x)}.not, {
                val= val.asFloat; //make single numbers into floats
        //}, { //else do nothing - keep date and satellites as strings
        });
        dict.put(key.asSymbol, val);
};
~dict= dict; //handle
)

//--list all stored keys...
~dict.keys.do{|x| x.postln}

//--access data stored at keys...
~dict['ACCELEROMETER X (m/s²)']
~dict['ACCELEROMETER Y (m/s²)']
~dict['ACCELEROMETER Z (m/s²)']
~dict['GRAVITY X (m/s²)']
~dict['GRAVITY Y (m/s²)']
~dict['GRAVITY Z (m/s²)']
~dict['GYROSCOPE X (rad/s)']
~dict['GYROSCOPE Y (rad/s)']
~dict['GYROSCOPE Z (rad/s)']
~dict['LIGHT (lux)']
~dict['MAGNETIC FIELD X (μT)']
~dict['MAGNETIC FIELD Y (μT)']
~dict['MAGNETIC FIELD Z (μT)']
~dict['ORIENTATION X (°)']
~dict['ORIENTATION Y (°)']
~dict['ORIENTATION Z (°)']
~dict['PROXIMITY (i)']
~dict['SOUND LEVEL (dB)']
~dict['LOCATION Latitude']
~dict['LOCATION Longitude']
~dict['LOCATION Altitude ( m)']
~dict['LOCATION Speed ( Kmh)']
~dict['LOCATION Accuracy ( m)']
~dict['Satellites in range'] //note as strings
~dict['Temperature (F)']
~dict['Level (%)']
~dict['Voltage (Volt)']
~dict['Time since start in ms'] //timestamps in milliseconds
~dict['YYYY-MO-DD HH-MI-SS_SSS'] //absolute timestamps - note as strings

//--plot the xyz accelerometer data...
(
[
        ~dict['ACCELEROMETER X (m/s²)'],
        ~dict['ACCELEROMETER Y (m/s²)'],
        ~dict['ACCELEROMETER Z (m/s²)']
].plot
)

//--plot the xyz orientation data...
(
[
        ~dict['ORIENTATION X (°)'],
        ~dict['ORIENTATION Y (°)'],
        ~dict['ORIENTATION Z (°)']
].plot
)

//--plot a lot of data (but not all)...
(
[
        'ACCELEROMETER X (m/s²)',
        'ACCELEROMETER Y (m/s²)',
        'ACCELEROMETER Z (m/s²)',
        'GRAVITY X (m/s²)',
        'GRAVITY Y (m/s²)',
        'GRAVITY Z (m/s²)',
        'GYROSCOPE X (rad/s)',
        'GYROSCOPE Y (rad/s)',
        'GYROSCOPE Z (rad/s)',
        'LIGHT (lux)',
        'MAGNETIC FIELD X (μT)',
        'MAGNETIC FIELD Y (μT)',
        'MAGNETIC FIELD Z (μT)',
        'ORIENTATION X (°)',
        'ORIENTATION Y (°)',
        'ORIENTATION Z (°)',
        'SOUND LEVEL (dB)'
].collect{|x| ~dict[x]}.plot;
)

//--sound example mapping accelerometer to simple sound
(
s.waitForBoot{
        var a= {|freq= 500, amp= 0, pan= 0| Pan2.ar(Pulse.ar(freq.lag(0.25), 0.2, amp.lag(0.25)), pan.lag(0.25))}.play;
        s.sync;
        Routine.run({
                var prevTime= 0;
                ~dict['Time since start in ms'].do{|x, i|
                        a.set(
                                \freq, ~dict['ACCELEROMETER Y (m/s²)'][i].linexp(-20, 20, 100, 1000),
                                \amp, ~dict['ACCELEROMETER Z (m/s²)'][i].linlin(-20, 20, 0, 1),
                                \pan, ~dict['ACCELEROMETER X (m/s²)'][i].linlin(-20, 20, -1, 1)
                        );
                        (x-prevTime*0.001).wait;
                        prevTime= x;
                };
                "done".postln;
                a.release;
        });
};
)

attached is a demo csv file of me first keeping the phone still, and then shaking it a bit + turning it around. the data recording is only about eight seconds long.

if you plot for example the 3d accelerometer data it will look like this...

keystroke recorder

clean-up: #51

today a very simple piece of code that takes whatever you're typing in a document and posts it back 2 seconds later. see it as a demonstration. the list is treated as a fifo buffer.
note: only works in supercollider versions with Document support (not 3.6, but 3.4, 3.5, 3.7)

(
var delay= 2; //post 2 seconds later
var l= List.new;

//--record in list l
Document.current.keyDownAction= {|doc, key|
        l.addFirst(
                (key: key, time: Main.elapsedTime)
        );
};

//--playback of list l
Routine({
        inf.do{
                var now= Main.elapsedTime;
                if(l.size>0 and:{now-delay>l.last.time}, {
                        l.pop.postln;
                });
                0.01.wait;
        };
}).play;
)

harmonicism

clean-up: #50

found more old supercollider code laying around... this little lambdoma experiment was based on this Cymatic Music video.

//--8x8 lambdoma matrix
a= [
        1/1, 2/1, 3/1, 4/1, 5/1, 6/1, 7/1, 8/1,
       
        1/2, 2/2, 3/2, 4/2, 5/2, 6/2, 7/2, 8/2,
       
        1/3, 2/3, 3/3, 4/3, 5/3, 6/3, 7/3, 8/3,
       
        1/4, 2/4, 3/4, 4/4, 5/4, 6/4, 7/4, 8/4,
       
        1/5, 2/5, 3/5, 4/5, 5/5, 6/5, 7/5, 8/5,
       
        1/6, 2/6, 3/6, 4/6, 5/6, 6/6, 7/6, 8/6,
       
        1/7, 2/7, 3/7, 4/7, 5/7, 6/7, 7/7, 8/7,
       
        1/8, 2/8, 3/8, 4/8, 5/8, 6/8, 7/8, 8/8
];

//--simplified
a= {|x| {|y| y+1/(x+1)}.dup(8)}.dup(8).flat;

s.boot
Pbind(\dur, 0.25, \freq, 60.midicps*Pseq(a.at((0,1..7)))).play
Pbind(\dur, 0.25, \freq, 60.midicps*Pseq(a.at((0,8..63)))).play
Pbind(\dur, 0.25, \freq, 60.midicps*Pseq(a.at((8,9..15)))).play
Pbind(\dur, 0.25, \freq, 60.midicps*Pseq(a.at((32,33..39)))).play
Pbind(\dur, 0.25, \freq, 60.midicps*Pseq(a.at((48,49..55)))).play
Pbind(\dur, 0.25, \freq, 60.midicps*Pseq(a.at((56,57..63)))).play

Pbind(\dur, 0.125, \freq, 60.midicps*Pseq(a)).play

//--16x16 lambdoma matrix
b= {|x| {|y| y+1/(x+1)}.dup(16)}.dup(16).flat;
Pbind(\dur, 0.125, \freq, 60.midicps*Pseq(b)).play

chipwave

clean-up: #48

here's an old port i did of a pure data patch called chipwave by Phill Phelps.
also see the updated pd version Dan Wilcox made: rc-patches

//after http://www.zenpho.co.uk/chipwave.shtml

s.boot
(
SynthDef(\ioscs, {|out= 0, amp= 0.5, freq= 400, width= 0.25, gate= 1, atk= 0.002, dec= 0, sus= 1, rel= 0.2, ws= #[0, 2, 2, 3, 2, 2, 2, 2, 2], ps= #[0, 12, -12, 0, 7, 0, 7, 0, 7]|
        var e= EnvGen.ar(Env.adsr(atk, dec, sus, rel), gate, amp, doneAction:2);
        var w= Duty.ar(0.025, 0, Dseq(ws));
        var p= Duty.ar(0.025, 0, Dseq(ps));
        var f= freq*p.midiratio;
        var ti= LFTri.ar(f, 0, 0.5, 0.5);
        var sq= LFPulse.ar(f, 0, width*0.5, 2, -1);
        var ns= LFNoise0.ar(f*10);
        var z= Select.ar(w, [DC.ar(0), ti, sq, ns]);
        Out.ar(out, LeakDC.ar(z*e));
}).add;
)

//arp
a= Synth(\ioscs, [\freq, 60.midicps, \amp, 0.5, \width, 0.5]).setn(\ws, #[0, 2, 2, 3, 2, 2, 2, 2, 2], \ps, #[0, 12, -12, 0, 7, 0, 7, 0, 7])
a.release
a= Pbind(\instrument, \ioscs, \midinote, Pseq([60, 60, 70, 60, 65, 63], inf), \amp, 0.5, \dur, 0.25, \width, Pseg(Pseq([0, 1], inf), 5)).play
a.stop

//kick
a= Synth(\ioscs, [\freq, 60.midicps, \amp, 1, \atk, 0.002, \dec, 0, \sus, 1, \rel, 0.3, \width, 0.5]).setn(\ws, #[0, 3, 2, 2, 2, 2, 2, 2, 2], \ps, #[0, 18, -12, 0, 0, -6, -12, -24, -48])
a.release
a= Pbind(\instrument, \ioscs, \midinote, Pseq([40, 48], inf), \amp, 0.5, \rel, 0.3, \legato, 0.3, \dur, 0.5, \width, 0.5, \ws, #[[0, 3, 2, 2, 2, 2, 2, 2, 2]], \ps, #[[0, 18, -12, 0, 0, -6, -12, -24, -48]]).play
a.stop

//snare
a= Synth(\ioscs, [\freq, 60.midicps, \amp, 1, \atk, 0.002, \dec, 0, \sus, 1, \rel, 0.3, \width, 0.5]).setn(\ws, #[0, 3, 2, 3, 3, 3, 3, 3, 3], \ps, #[0, 18, 0, 3, 12, 18, 24, 36, 36])
a.release
a= Pbind(\instrument, \ioscs, \midinote, 70, \amp, Pseq([0, 0.5, 0, 0.25], inf), \rel, 0.3, \dur, 0.5, \width, 0.5, \ws, #[[0, 3, 2, 3, 3, 3, 3, 3, 3]], \ps, #[[0, 18, 0, 3, 12, 18, 24, 36, 36]]).play
a.stop

//bass
a= Synth(\ioscs, [\freq, 60.midicps, \amp, 1, \atk, 0.002, \dec, 0, \sus, 1, \rel, 0.3, \width, 0.5]).setn(\ws, #[0, 1, 1, 1, 1, 1, 1, 1, 1], \ps, #[0, 24, 0, 12, 0, -1, 1, -1, 0])
a.release
a= Pbind(\instrument, \ioscs, \midinote, Pseq([40, 48, 48, 60], inf), \amp, 0.5, \rel, 0.3, \dur, 0.25, \width, 0.5, \ws, #[[0, 1, 1, 1, 1, 1, 1, 1, 1]], \ps, #[[0, 24, 0, 12, 0, -1, 1, -1, 0]]).play
a.stop

(
Ppar([
        Pbind(\instrument, \ioscs, \amp, 0.5, \midinote, Pseq([64, 66, 52], inf), \dur, 0.25),
        Pbind(\instrument, \ioscs, \amp, 0.5, \midinote, Pseq([60, 70], inf), \dur, 0.5),
        Pbind(\instrument, \ioscs, \amp, 0.5, \midinote, 100, \dur, 1/3)
]).play;
)

feedback synths

clean-up: #47

today i found some old code in my supercollider folder that i thought i'd clean up and publish.
experiments in audio feedback.

s.boot

(
SynthDef(\feedback1, {|freq= 400, amp= 0.1|
        var env= EnvGen.kr(Env.perc(1, 4), doneAction:2);
        var lin= LocalIn.ar(1);
        var src= SinOsc.ar(freq, lin*2pi, amp*env);
        LocalOut.ar(src);
        Out.ar(0, Pan2.ar(src));
}).add;
)
Synth(\feedback1)
Synth(\feedback1, [\freq, 300])
Synth(\feedback1, [\freq, 300, \amp, 0.255])

(
SynthDef(\feedback2, {|freq= 400, amp= 0.1, fb= 2, del= 0.1|
        var env= EnvGen.kr(Env.perc(1, 4), doneAction:2);
        var lin= DelayN.ar(LocalIn.ar(1), 1, del);
        var src= SinOsc.ar(freq, lin*2pi*fb, amp)*env;
        LocalOut.ar(src);
        Out.ar(0, Pan2.ar(src));
}).add;
)
Synth(\feedback2)
Synth(\feedback2, [\del, 0.5])
Synth(\feedback2, [\del, 0.01])
Synth(\feedback2, [\del, 0.01, \fb, 3])
Synth(\feedback2, [\freq, 300, \del, 0.1, \fb, 2.5])

(
SynthDef(\feedback3, {|freq= 400, amp= 0.1, fb= 2, del= 0.1, lfo= 1, rate= 2|
        var env= EnvGen.kr(Env.perc(1, 4), doneAction:2);
        var lin= DelayN.ar(LocalIn.ar(1), 1, del);
        var src= SinOsc.ar(freq+SinOsc.ar(rate, 0, lfo), lin*2pi*fb, amp)*env;
        LocalOut.ar(src);
        Out.ar(0, Pan2.ar(src));
}).add;
)
Synth(\feedback3)
Synth(\feedback3, [\del, 0.5])
Synth(\feedback3, [\del, 0.01])
Synth(\feedback3, [\del, 0.01, \fb, 3])
Synth(\feedback3, [\del, 0.01, \fb, 2, \lfo, 15])
Synth(\feedback3, [\del, 0.01, \fb, 3, \lfo, 100, \freq, 100])
Synth(\feedback3, [\del, 0.02, \fb, 3, \lfo, 100, \freq, 100])
Synth(\feedback3, [\del, 0.5, \fb, 201, \lfo, 200, \freq, 200, \rate, 202])
Synth(\feedback3, [\del, 0.5, \fb, 1, \lfo, 200, \freq, 300, \rate, 0.01])

(
SynthDef(\feedback4, {|freq= 400, amp= 0.1, fb= 2, del= 0.1, lfo= 1, rate= 2, cutoff= 500|
        var env= EnvGen.kr(Env.perc(1, 4), doneAction:2);
        var lin= DelayN.ar(HPF.ar(LocalIn.ar(1), cutoff), 1, del);
        var src= SinOsc.ar(freq+SinOsc.ar(rate, 0, lfo), lin*2pi*fb, amp)*env;
        LocalOut.ar(src);
        Out.ar(0, Pan2.ar(src));
}).add;
)
Synth(\feedback4)
Synth(\feedback4, [\del, 0.5])
Synth(\feedback4, [\del, 0.01, \cutoff, 100])
Synth(\feedback4, [\del, 0.01, \fb, 3, \cutoff, 100])
Synth(\feedback4, [\del, 0.01, \fb, 2, \lfo, 15, \cutoff, 100])
Synth(\feedback4, [\del, 0.01, \fb, 3, \lfo, 100, \freq, 100, \cutoff, 100])
Synth(\feedback4, [\del, 0.02, \fb, 3, \lfo, 100, \freq, 100, \cutoff, 100])
Synth(\feedback4, [\del, 0.5, \fb, 201, \lfo, 200, \freq, 200, \rate, 202, \cutoff, 100])
Synth(\feedback4, [\del, 0.5, \fb, 1, \lfo, 200, \freq, 300, \rate, 0.01, \cutoff, 100])

2nd fluid simulator in supercollider

clean-up: #46

here's another supercollider port of msafluid by Memo Akten. it is very similar to the MSAFluidSolver2D i ported from java, but this one is from the c++ version (openframeworks ofxMSAFluid) and has more features and a gui interface.

unfortunately it runs slower than the java port.

classes, helpfiles and an example are attached as a zip archive below.

AttachmentSize
Package icon MSAFluidSolver.zip17.34 KB

Pages

Subscribe to f0blog RSS