‹ extMasterEQ Separate Noisy and Pitched Sounds ›

system.log

2014-10-01 21:01 supercollider

clean-up: #39

Since long I had this idea of sonifying what my laptop is doing. Before, when laptops had spinning hard drives, one could at least hear the faint little noises when there was disk activity. But today with the SD disks, this insight is gone.

Below is a draft of how it could work. It tracks activity in the system.log file. To try it start SuperCollider and run the code. Then launch some apps, save files, disconnect network etc. It's quite fun to have it running in the background for a while.

One day I plan to do a more thorough sonification, tracking many more things. Here is a good reference for what to tap into in the future.

/*
sudo iosnoop
sudo execsnoop -v
sudo opensnoop -ve
sudo dtruss -n SuperCollider
sudo errinfo -c
sudo iotop -CP 1
man -k dtrace
*/

//osx only
(
s.latency= 0.05;
s.waitForBoot{
  var num= 10;
  var delta= 0.1;
  var maxlen= 256;
  var rate= 0.5;
  var curr= List.new;
  var mySplit= {|str|
    var res= "";
    var arr= [];
    var separator= Char.nl.ascii;
    var tab= Char.tab.ascii;
    str.do{|chr, i|
      if(chr.ascii!=separator or:{str.clipAt(i+1).ascii==tab}, {
        res= res++chr;
      }, {
        arr= arr.add(res);
        res= "";
      });
    };
    arr.add(res);
  };
  var read= Routine({
    var res, arr, last, new;
    inf.do{
      res= ("tail -n"+num+"/var/log/system.log").unixCmdGetStdOut;
      if(res!=last, {
        last= res;
        arr= mySplit.value(res);
        new= arr.select{|x| curr.indexOfEqual(x).isNil};
        new.do{|x|
          curr.addFirst(x);
        };
      });
      delta.wait;  //time between checking system log
    };
  });
  var play= Routine({
    var data;
    inf.do{
      if(curr.size>0, {
        data= curr.pop;
        ("buf"++curr.size++": ").post;
        data.postln;
        s.bind{
          Synth(\log, [\data, data.ascii.extend(maxlen, 0)]);
        };
        (data.size/maxlen*rate).wait;
      }, {
        delta.wait;
      });
    };
  });
  SynthDef(\log, {|out= 0, amp= 0.5, minFreq= 300, maxFreq= 14400|
    var data= Control.names([\data]).ir(Array.fill(maxlen, 0));
    var freq= Duty.ar(1/maxlen*rate, 0, Dseq(data), 2);
    var src= SinOsc.ar(freq.linexp(0, 255, minFreq, maxFreq), 0, (freq>0).lag(0.02));
    OffsetOut.ar(out, Pan2.ar(src, 0, amp));
  }).add;
  s.sync;
  read.play(AppClock);
  play.play;
};
)

‹ extMasterEQ Separate Noisy and Pitched Sounds ›