arduino livecoding

so here's some more in depth info on my performance at the live.code.festival / algorave in karlsruhe.

being fascinated since long by the sound of serial transmission, i got into trying to make music out of it in some way. by trial-and-error i figured out that if i connect a small speaker to the tx line of an arduino, i could upload programs that send serial data and listen to the sound of it.
it is all very basic: if i make the arduino program send data with delays in between, it play click rhythms. and programs with faster streams of data play tones. more elaborate combinations of delays and patterns of data produce chords, melodies and a variety of noises. so it works like some sort of one-bit music system that is nice and challenging to play with.

the programs i [live]code can look like this...

byte cnt= 0;
void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.write(cnt);
  delay(5);
  cnt++;
}

and the resulting sound is this... (raw and unfiltered)


and a more elaborate program...

byte cnt= 0;
void setup() {
  Serial.begin(9600);
}
void loop() {
  for(int i= 0; i<100; i++) {
    Serial.write(cnt++%5+10);
    delay(random(4));
  }
  for(int i= 0; i<200; i++) {
    Serial.write(cnt++%5+10);
    delay(2);
  }
  for(int i= 0; i<100; i++) {
    Serial.write(cnt++%5+10);
    delay(random(4));
  }
  for(int i= 0; i<100; i++) {
    Serial.write(cnt++%5+10);
    delay(3);
  }
  for(int i= 0; i<100; i++) {
    Serial.write(cnt++%5+10);
    delay(4);
  }
  if(random(2)==0) {
    Serial.begin(random(10000));
  }
}

sounds like this...

and of course the sound of the uploading (verification really) is great in it self. it typically sounds like this... (raw and unfiltered)

i think the uploading sound changes subtly depending on program length and i also guess it will change with different arduino bootloaders and whatever baudrate they are using.

and you also have a bit of control over the timbre of the sounds. certain 8bit numbers are more square-wave like than others e.g. 170 (0b10101010), and 85 (0b01010101) sound more 'clean' and 15 (0b00001111) and 240 (0b11110000) also have a more distinct pitch.
different baudrates have a huge effect on the sound - mainly working as frequency transposition.

but the real fun starts when one connects five arduinos to a mixer and start playing with volumes, panning and filters. by having five arduinos connected to an usb hub while running five copies of the arduino ide software, i can write little programs on the fly that will address the different boards and play different sounds on the tx lines. (listening to the rx line also works but then the upload process fails. it'll require extra circuitry to tap into this data without disrupting the uploading).

the reason i used five arduinos is because that's all i could connect to my laptop (2x usb) with my 4-port usb hub. that in combination with the limitation of computer screen space. it is hard to have more than five arduino ide programs open and visible at the same time.

anyway, as the voltage of the standard arduino is 5v and really a bit too much for audio equipment, i bring this down a bit with a simple voltage divider. i'm using a 10k and a 1k resistor.

here are some pictures of the setup. i'm using the arduino clone red board from sparkfun.

the complete setup (without mixer and laptop)...

one issue with the setup is that one can't trust the arduino ide to remember which serial port it was connected to. so every time i start the program i need to double check that the five arduino ide programs are set to the right arduino board. and as i like to know which board is connected to which mixer channel, i also need to check that and possibly reconnect the sound cables.

live at the live.code.festival in karlsruhe (algorave night 20apr, 2013). five arduino boards all with their serial port (tx line) connected to a mixer (with simple protective circuitry in between). so all sound are generated from what the arduino boards are programmed to transmit serially. note that the sound is heavily distorted. sorry.

ström

since the category 'visuals' is underrepresented in this blog and i don't like to embed video in my standard [html] pages, i thought i'd include this old piece here. this is the shorter abridged version of the full piece. the quality isn't the best - it's pixelated and stuttering. one day i should re-render it in 60fps at a higher resolution. it looks a lot better when running in realtime from a computer.

Ström by Mattias Petersson (music) and Fredrik Olofsson (video) is, in its full version, a 45 minute minimalistic piece for five loudspeakers, live-electronics and live-video, based on an open-minded, artistic approach towards electricity. The piece is an attempt to transfer electric currents via sound to the audience. The five speakers in the surround system struggles to take over the sonic stream like electro-magnets. Sine waves and noise rotates with breakneck speeds around the listeners, tries to charge them with static electricity and, as an ultimate goal, even make them levitate. The video part is in direct connection with the sound and is generated out of five discrete lines – one for each channel in the surround system. The lines are treated in different ways, and as the high voltage builds up in the music they look more and more like electric wires, inflicting each other with violent discharges and eruptions. This version was made for a promotional DVD release on Swedish sound art.

also see here

traer physics library for supercollider

a while ago i started porting the java/processing library TRAER.PHYSICS 3.0 by Jeffrey Traer Bernstein to supercollider. it's a simple and elegant particle system and a physics engine all in one. there are already ports to actionscript3, javascript and c++ (cinder), but i haven't seen anyone working with it in sc yet. so i had a go - both to learn more and to have an alternative to my own physics library quark redUniverse.

it is now finished and released as a quark. this is the initial version and there might still be bugs. i _did see sc crash once in a strange way after spawning lots of particles, so watch out for memory leaks.
to install it run the following code and recompile sc...

Quarks.checkoutAll;
Quarks.install("TraerPhysics");

i also wrote a few simple examples to go along with the helpfiles. here's a screenshot of one...

hats

a tiny circuit i designed and built in five copies for dancer Raffaella Galdi. with the help of a small magnetic sensor this circuit makes it possible to start and stop sound coming from a mp3 player. because the five circuit boards, speakers and mp3players are mounted inside pointy hats, the electronics had to be light and draw very little current from the battery.
for the sound volume control i used a vactrol (ldr+led) and the timing and fade in/out logic are encoded in the firmware of a little microcontroller (ATtiny45). to save battery, the tiny45 is put to sleep and is only active when the magnetic reed sensor is triggered. i used the great JeeLib.h for controlling the sleep cycles of the microcontroller.

schematics, firmware and partslist attached below.

AttachmentSize
Package icon hats.zip29.15 KB

more sc twitter

more audio recordings of my twitter sctweets. see twitter.com/redFrik and this post.
normally you run these lines of code (140 characters) in supercollider and it will play you some kind of generative music or soundscape (also graphics in rare cases). here i've recorded a few for those who are too lazy to install sc.

 

//--tweet0026

{CombL.ar(In.ar(8).tanh/8,1,1,8)!2}.play;Pbind(\amp,8,\dur,1/4,\degree,Pseq(List.fib(32)%(List.fib(64)%12),inf),\out,8).play//#SuperCollider

this one is using the built in .fib (as in fibonacci) method to generate pitches (\degree) for the Pbind. the Pbind in it self is quite boring to listen to, so by playing it out on audio bus 8 and then making a small distortion+echo effect synth reading from bus 8, we get a much more interesting sound.

 

//--tweet0028

play{MoogFF.ar(LFTri.ar(CombN.ar(Duty.ar(1/8,0,Dseq(Dshuf(List.fib(16)%8*99,8),inf)),4,4,16))/4,LFTri.kr(1/16,0,2e3,3e3))!2}//#SuperCollider

again using the built in fibonacci method to generate patterns. here every 8th bar the pattern is scrambled (Dshuf), and in every 8th bar period the first 2 bars are transposed by a strange trick running the melody pattern (i.e. the frequencies) through a CombN.

 

//--tweet0030

play{a=LFPar;GVerb.ar(VarSaw.ar(a.ar(1,0,5,a.ar([0.05,0.04],0,50,160).round(50)),0,a.ar(0.2,0,0.5,a.ar(3,0,0.2,0.5)))/8,80)}//#SuperCollider

here is something that sounds a bit like a couple of trombones playing a riff in a reverberant room. the riff just goes on and on and is made from a pair of slowly changing LFPar oscillators, scaled, offset and rounded to the nearest 50Hz.

 

//--tweet0033

play{f=LFPar.ar(1/14).round*20+80;Splay.ar(LFPar.ar({|i|[i+1*f,i*f+(i+1/3)]}!4)>BrownNoise.ar(Pulse.ar({|i|i+1}!4,0.35))/3)}//#SuperCollider

sounds a bit like punk rock in 6/8 time signature. the crispness comes from the > BrownNoise combo and the rhythms from the Pulse. overall melody is the slowly running LFPar oscillator stored in variable f. note that this tweet only works in sc version 3.5 and above.

 

//--tweet0041

play{o=SinOsc.ar(1/RunningMax.ar(Sweep.ar(LocalIn.ar(6)),Impulse.ar([1,0.749,6,12,3,4])));LocalOut.ar(o);Splay.ar(o).tanh/2}//#SuperCollider

an ever rising tone cluster with some clicks. this is built using a localin/localout feedback chain. there are plateaus where one thinks the maximum frequency is reached, but those are only temporary and after a while the tone starts to rise again.

 

//--tweet0044

play{a=SinOsc;Limiter.ar(LeakDC.ar(a.ar(0.11,BRF.ar(a.ar(a.ar(0.12).exprange(1,1e4),2pi),1/a.ar(0.13).range(1,[99,100])))))}//#SuperCollider

here the cutoff frequency of a BRF (band reject filter) is modulated with a SinOsc. the cutoff varies between 1 and 99 Hz in the left channel, and 1 and 100 Hz in the right channel. the BRF goes wild and outputs totally crazy sounds when modulated in this matter - just like the BPF used to behave in old sc versions (3.3 and earlier).

 

//--tweet0045

play{a=SinOsc;a.ar(a.ar(a.ar(0.11)),a.ar(a.ar(95*a.ar(0.01,0,1,1),0,a.ar(5e-3,0,50),100),a.ar([98,97]),pi+a.ar(5e-4))).tanh}//#SuperCollider

a deep fat bass. it sounds as lovely in a big speaker system as it sounds poor in laptop speakers. the patch is mainly doing phase modulation on a SinOsc with tanh distortion.

 

//--tweet0046

play{a=LFTri;GVerb.ar(Mix(Limiter.ar(BRF.ar(a.ar(50,1e-4),a.ar(a.ar([1.01,1.0111])*a.ar(8e3)*1e3+4e3,55),a.ar(0.01)*3))))/9}//#SuperCollider

this tweet sounds much like a field recording. the noise comes from an exploding BRF (band reject filter) that is wrapped in a Limiter so that it keeps in range. last a GVerb is adding a metallic quality reverb to the overall sound.

 

//--tweet0047

play{CombN.ar(Limiter.ar(BRF.ar(LFSaw.ar(10,0,0.01),LFTri.ar([5,6]*0.1))),0.1,LFTri.kr(0.1,0,0.05,0.05).round(0.01))}//#SuperCollider#SC2012

this was coded, believe it or not, within a 5min time limit and under water pistol threat (part of sc2012 keynote talk in london). again it's a BRF misbehaving run through a comb delay with short modulated delaytime (from 0 to 0.1).

 

//--tweet0048

play{a=Impulse;b=SinOsc;c=b.ar(0,BRF.ar(a.ar([7,8]),a.ar(9).lag2(1e-3),1.5,2pi));Ringz.ar(c,b.ar(0.02,0,99,150),1/9)+c*0.02}//#SuperCollider

a quite poor tweet. the rhythms are not so interesting and it also have the problem of running out and stopping after a few seconds. anyway, the principle is that a BRF is generating strange sounds that phase modulate a SinOsc, that in turn goes through a ringing filter (Ringz). i only wanted to record it so that when someone fixes the BRF in some upcoming supercollider version, i can go back and listen to how it could sound.

 

//--tweet0053

Pbind(\freq,Pseq("SUPERCOLLIDER".ascii,inf)*Pstutter(64,Pseq([3,4,5],inf))*[1,2.045],\dur,0.03,\amp,Pseq([0,0.1],inf)).play// #SuperCollider

super annoying little thing. it is using the values of the ascii characters in the string "SUPERCOLLIDER" which is [83, 85, 80, 69, 82, 67, 79, 76, 76, 73, 68, 69, 82]. this is played in sequence and transposed and detuned. maybe a candidate for the official supercollider theme song?

 

//--tweet0054

play{CombN.ar(SyncSaw.ar(Saw.ar([3,4],32,64),Saw.ar([4,3],99,Duty.kr(1,0,flop(Dseq(2!6++4++3,99)*(4**(0..4))))))/9,1,1/6,2)}//#SuperCollider

very intense sounding tweet.

 

//--tweet0055

play{a=Pulse;CombN.ar(Slope.ar(a.ar(a.ar([1,2]/3,1/9,50,[50,150])),a.ar([3,4],1/3)+a.ar([2,3],1/4)/10+0.005).cos/5,1,1/6,2)}//#SuperCollider

an even more intense sounding tweet.

 

//--tweet0057

a=GVerb;fork{loop{z=play{#b,c,d,e,f,g,h,i=(1..50).scramble;a.ar(a.ar(a.ar(a.ar(Dust.ar(1),b,c),d,e),f,g),h,i)/20};6.wait;z.release(5)}}//#sc

this patch is heavy on the cpu. it consists of a synth with nested GVerbs all with random settings for roomsize and reverberation time. synths play for 6 seconds and then fades out over 5 seconds as another synth, with different reverb settings start. the result is overlapping sounds and quite dense texture.

 

//--tweet0059

a=LFTri;play{CombN.ar(SinOsc.ar(Saw.ar(3,128,128),Saw.ar([3,4],a.ar(a.kr(0.1,0,8,12),0,32,128)).sin)/4,1,1/6,a.kr(1/32)+1)}// #SuperCollider

a rhythmic tweet. gets a bit annoying after a while but there are some nice details in there.

 

//--tweet0061

a=Demand;b=SinOsc;play{b.ar(a.ar(t=Saw.ar([9,9.01]),0,Dseq(0!6++500,inf)),b.ar(a.ar(t,0,Dshuf((0..7)*99,inf)).lag(0.04)))/2}//#SuperCollider

phasing melody in left and right channels. every 7th note has a slightly different timbre (the 0!6++500 part) and every time one starts this tweet the melody changes (the Dshuf((0..7) part). the phasing is done with two Saw oscillators running at 9 and 9.01Hz. they are in turn used as triggers for the timbre and melody sequences (the two Demand ugens).

one reason why i love sc

140 characters (sc3.5 only)...

play{Splay.ar(SinOsc.ar(9,SinOsc.ar(midicps((Sweep.ar(0,(33..3))%128&(Sweep.ar(0,(3..9))%(LFSaw.ar(3)*9+99)))+33),0,pi)))/3}//#SuperCollider

if we run this line in supercollider we hear this...


and using Rohan Drape's great rd_dot quark and swap play{} with draw{} in the line above, this mess gets revealed...

so with a single line of code - short enough to fit in a twitter tweet - we've built this amazingly complex sound synthesis patch. i can not imagine a system with greater code-to-noise ratio than supercollider.

and this one is pretty fun to .draw as well...

play{f={|o,i|if(i>0,{SinOsc.ar([i,i+1e-4]**2*f.(o,i-1),f.(o,i-1)*1e-4,f.(o,i-1))},o)};f.(60,6)/60}//#SuperCollider


a heavily recursive patch that looks almost fractal. the pdf file generated from this line of code is 300kb! the number 6 in the code means recursion depth and 60 is the base frequency.

to run the rd_dot quark in supercollider on a mac you'll need Graphviz (i use 2.28 on my osx 10.6.8). you also need to make sure the resulting .dot files opens automatically in graphviz and not photoshop, word or something (get info on a .dot file in Finder and change all filetypes to open with graphiviz. you'll find the .dot files from rd_dot in your hidden /tmp directory)

AttachmentSize
PDF icon 637231982.pdf85.87 KB
PDF icon 1909609728.pdf300.44 KB

analog video in/out on a recent macbook pro

for a project i needed to take in and send out realtime analog (composite) video. analog video input has always been a problem, but on recent laptops apple even removed the video output via dvi adapter option (i.e. there is no displayport to video/s-video adapter).
so after experimenting and going through some old hardware i had laying around, i found a solution using two devices that i last used around 10years ago.

* dfg1394 bus powered s-video/composite video to uncompressed firewire converter from imagingsource (firewire version not longer available).
* mac osx drivers for the dfg1394 from outcastsoft. works with max/jitter etc.
* an old TView Gold scanconverter from Focus enhancements. used in combo with a 5v power from usb hack and a displayport to vga adapter.

Pages

Subscribe to f0blog RSS