research

work with mark: RedUniverse - a simple toolkit

i made a short demo/poster session at the LAM conference 19dec in london. see livealgorithms.org
below is the handout describing the toolkit.


this toolkit is now distributed via supercollider's package system quarks. all open source.
how to install:
download supercollider
Quarks.checkoutAll
Quarks.install("redUniverse")
(if you run OSX and prefer to use SwingOSC over Cocoa gui, you'll need to move the file RedJWindow.sc to the osx folder and recompile.)

RedUniverse - a simple toolkit

Mark d'Inverno & Fredrik Olofsson

This is basically a set of tools for sonification and visualisation of dynamic systems. It lets us build and experiment with systems as they are running. With the help of these tools we can quickly try out ideas around simple audiovisual mappings, as well as code very complex agents with strange behaviours.

The toolkit consists of three basic things... Objects, Worlds and a Universe. Supporting these are additional classes for things like particle systems, genetic algorithms, plotting, audio analysis etc. but preferably many of these functions you will want to code your self as a user.

We have chosen to work in the programming language SuperCollider (www.audiosynth.com) as it provides
tight integration between realtime sound synthesis and graphics. It also allows for minimal classes that are easy to customise and extend. SuperCollider is also open for communication with other programs and it run cross-platform.

So to take full advantage of our toolkit, good knowledge of this programming language is required. We do provide helpfiles and examples as templates for exploration, but the more interesting features, like the ability to live-code agents, are hard to fully utilise without knowing this language.

Detailed overview

In SuperCollider we have the three base classes: RedObject, RedWorld and RedUniverse.

RedObject - things like particles, boids, agents, rocks, food etc.
RedWorld - provides an environment for objects.
RedUniverse - a global collection of all available worlds.

Objects all live in a world of some sort. There they obey a simplified set of physical laws. They have a location, velocity, acceleration, size and a mass. They know a little about forces and can collide nicely with other objects.

Pendulums are objects that oscillates. They have an internal oscillation or resonance of some sort.

Particles are objects that ages with time. They keep track of how long they have existed.

Boids are slightly more advanced particles. They have a desire and they can wander around independently seeking it.

Agents are boids that can sense and act. They also carries a state 'dictionary' where basically anything can be stored (sensory data, urges, genome, phenome, likes, dislikes, etc). Both the sense and act functions as well as the state dictionary, can be manipulated on the fly. Either by the system itself or by the user in runtime.

Worlds provide an environment for the objects. They have properties like size, dimensions, gravity etc and they also keep a list of all objects currently in that world.
For now there are three world classes:
RedWorld - endless in the sense that objects wrap around its borders.
RedWorld2 - a world with soft walls. Objects can go through but at a cost. How soft these walls are and how great the cost is depends on gravity and world damping.
RedWorld3 - a world with hard walls. Objects bounce off the borders - how hard depends on gravity and world damping.

The Universe is there to keep track of worlds. It can interpolate between different worlds. It can sequence worlds, swap and replace, and also migrate objects between worlds. All this while the system is running.
The RedUniverse class also does complete system store/recall to disk of all objects and worlds.

So the above are the basic tools. They should be flexible enough to work with e.g. objects can live in worlds of any number of dimensions. But as noted, one can easily extend functionality of these classes by subclassing.

Conclusion

How the objects and worlds behave, sound and look like are open for experimentation. That is, this is left for the user to code. So while there is great potential for customisation, it also requires more work form its users.
The RedUniverse as a whole tries not to enforce a particular type of system. E.g. one can use it purely without any visual output or vice-verse.
We see it both as a playground for agent experiments as well as a serious tool for music composition and performance. We hope it is simple and straightforward and while there is nothing particularly novel about it, we have certainly had fun with it so far. Foremost it makes it easy to come up with interesting mappings between sound and graphics. In a way we just joyride these simple dynamic systems to create interesting sounds.

The software and examples will be available online on the LAM site. Of course as open source.

(note:and also in the supercollider package system quarks)

work with mark: genetics

i also spent time at UoW learning about genetic algorithms and genetic programming. mainly from john h holland's books and karl sims' papers. i found it all very interesting and inspiring and again i got great help and input from rob saunders.

one of our ideas was to construct synthesis networks from parts of our agents' genomes i.e. to have the phenomes be actual synths that would synthesise sound in realtime. the first problem to tackle was a really hard one. how to translate the genome - in form of an array of floats - into a valid supercollider synth definition?
of course there are millions of ways to do this translation. i came up with the RedGAPhenome class which works with only binary operators, control and audio unit generators. unfortunately there can be no effects or modifier units. on the other hand the class is fairy flexible and it can deal with genomes of any length (>=4). one can customise which operators and generators to use and specify ranges for their arguments. you can also opt for topology of the synthesis network (more nested or more flat).
there is no randomness involved in the translation, so each gene should produce the exact same synthdef. of course generators involving noise, chaos and such might make the output sound slightly different each time but the synthesis network should be the same.
this class produces a fantastic range of weird synths with odd synthesis techniques, and it is useful just as a synth creation machine on its own. here are some generated synths... n_noises.rft, n_fmsynths.rft, and corresponding 5sec audio excerpts are attached below.

then, after the struggle with the phenome translation, the code for the actual genetic algorithms was easy to write. the genome and its fitness are kept in instances of a class called RedGAGenome, and the cross breeding and mutation are performed by the class RedGA. there are a couple of different breeding methods but i found the multi-point crossover one to give the generally best results. all the above classes and their respective helpfiles and examples are available here. and there are many more automatically generated synths in the attached krazysynths+gui.rtf example below.

i also made a couple of fun example applications stemming from this. one is a six voice sequencer where you can breed synths, patterns and envelopes. it is attached as 'growing soundsBreedPatternEnv.rtf' below. (note that the timing is a bit shaky. i really should rewrite it to run on the TempoClock instead of the AppClock.)


ref articles:

Frankensteinean Methods for Evolutionary Music Composition, Todd and Werner
Sounds Unheard of – Evolutionary algorithms as creative tools for the contemporary composer, Palle Dahlstedt
Evolutionary Design by Computers, Peter J. Bentley
Technical Papers, Karl Sims
Evolving Sonic Ecosystems, Jon McCormack

ref books:

John H. Holland - Hidden Order: How Adaptation Builds Complexity
Melanie Mitchell - An introduction to Genetic Algorithms
Richard Dawkins - The Blind Watchmaker

update 101128: growing_soundsBreedPatternEnv.rtf file updated, also see this post.

 

//--n_noises

 

//--n_fmsynths

work with mark: istreet - online

taking the intelligent street project further, mark d'inverno wanted me to try to get it online. the idea was to let people surf to a webpage, send commands to a running istreet system and hopefully collaborate with other online users to compose music. just like in the original sms-version of the piece, everybody could make changes to the same music and the result would be streamed back to all the online users.

the first prototype was easy to get up and running. we decided to use processing and write a java applet for the web user-interface and then stream the audio back with shoutcast. the users would listen to the music through itunes, winamp or some similar program. this of course introduced quite a delay before they could actually hear their changes to the music. but that was not all too bad as we had designed the original istreet in a way that latency was part of the user experience :-)
(the commands sent there via sms took approx 30 sec to reach us from the vodafone server and that could not be sped up. the users were given no instant control over the music - rather they could nudge it in some direction with their commands.)
so our internet radio/shoutcast solution worked just fine and we had it up and running for a short while from mark's house in london.

that was a total homebrewn solution of course. we wanted it to handle a lot of visitors, deal with some hopefully high traffic, be more stable, permanent and not run on an adsl connection.
so at UoW we got access to a os x server cluster and i started to plan how to install supercollider, a webserver and istreet on that. little did i know about servers, network and security and i had to learn ssh and emacs to get somewhere. rob saunders helped me a lot here.

then there were some major obstacles. first of all the cluster didn't have any window manager installed - not even x11. i spent many days getting supercollider and stefan kersten's emacs interface for sclang called scel to compile.
we also had some minor issues with starting the webserver and punching hole in the university firewall etc. but the major problem turned out to be to get the audio streaming going. i didn't have root access and wasn't allowed to install jack on the cluster. to stream i needed a shoutcast client and some way to get audio to that from supercollider. i did find os x programs that could have worked but none would run windowless on the console. so stuck.

the only solution was to write my own streaming mechanism. the resulting supercollider class for segmenting audio into mp3s is here. a java gateway handled the communication between sc and the java applet that would stitch these files back together. (the java gateway program also distributed all the other network data like the chat, checking online users, pending/playing commands etc. it used NetUtil by sciss).

unfortunately i never got the streaming thing to run smoothly. nasty hickups in the sound made it impossible to listen to. the hickups were probably partly due to my crappy coding but i think the main error was in the ESS library for processing. either ESS (releases 1 and 2) can't do asynchronous loading or java is just too slow to load mp3s without dropping audio playback. very annoying.
after that defeat i also spent time with flash and did a little player there that could load and play back mp3s smoothly. with the help from my flash expert friend abe we also could talk to the flash thing from my java applet via javascript. but time ran out and this would have been a too complicated system anyway.

so the istreet never made it online. but again i learned a lot about networks, unix, java and some tools got developed in the process. RedGUI - a set of user-interface classes for processing, ISRecord and ISGateway for sc, and the ISgateway.java.

screenshot of the java applet running istreet online...


work with mark: istreet - recording mp3s for streaming

mark d'inverno wanted to see the intelligent street installation gain new live online. so for streaming the sound from istreet over internet, i wrote a class for supercollider called ISRecord. it basically records sound to disk in small mp3 segments. so any sound supercollider produces will be spliced into many short mp3 files that could later be sent as small packages over the internet.
the technique is to continuously save the sound into one of two buffers. when one buffer is filled, the recording swaps and continues in the other. the buffer that just got filled is saved to disk and conversion to mp3 is started. this swap-and-write-to-disk cycle should have no problems keeping up realtime recording. but as the mp3 conversion takes a little bit of extra time - depending on quality and segmentation size etc, there is a callback message from the mp3 converter that evaluates a user defined segAction function when the mp3 conversion is finished. thereby one can notify other programs when the mp3 file is ready to be used.
there is also a cycle parameter that controls how many mp3 segments to save before starting to overwrite earlier ones. this is needed to not totally flood the harddrive with mp3s.

the actual mp3 conversion is done using lame and cnmat's sendOSC is also needed for the lame-to-sc communication.
attached is the recorder class plus a helpfile.

AttachmentSize
ISrecord060920.zip5.81 KB

work with mark: istreet - osx

at UoW i also rewrote an old installation called the intelligent street. mark d'inverno and i had worked together on this one earlier and we now wanted it to run on a modern computer (os x). we also wanted to redesign it a bit and make it into a standalone application.

the original intelligent street was a transnational sound installation were users could compose music using mobile phones and sms. that in turn was an extended version of a yet older installation called 'the street' by john eacott. this totally reworked 'intelligent' version was premiered in nov'03 and realised as a joined effort between the ambigence group (j.eacott, m.d'inverno, h.lörstad, f.rougier, f.olofsson) and the sonic studio at the interactive institute in piteå (way up in northern sweden).

for the new os x version we dropped sms as the only user interface and also removed the direct video+sound links between uk-se that was part of the old setup. except for that the plan was to move it straight over to supercollider server (sc3) and rather spend time on polishing the overall sound and music.

i roughly estimated it would take just a few days to do the actual port. most of the old code was written in supercollider version 2 (mac os 9) and the generative music parts were done using sc2's patterns and crucial libraries. so that code, i thought, would be pretty much forward compatible with our targeted supercollider 3. but sigh - it turned out that i had to rewrite it completely from scratch. the 'smart' tweaks and optimisations i had done in the old sc2 version in combination with the complexity of the engine made it necessary to redesign the thing bottom up. even the generative patterns parts. last i also dropped crucial library for the synthesised instruments and did it all in bare-bone sc3.

but i guess it was worth the extra weeks of work. in the end the system as a whole became more robust and better sounding. and standalone not to mention so hopefully it will survive a few years longer.
but i can also think of more creative work than rewriting old code. i've been doing that quite a lot recently. it feels like these old installations i've worked on earlier comes back to haunt me at regular intervals. and there is more and more of them for each year :-)

proof: intelligent street running happily under os x...


work with mark: shadowplay

idea
yet another system mark d'inverno and i worked on but never finished had the working title 'shadowplay'. we had this idea about an audiovisual installation where people's limbs (or outlines of bodies) would represent grid worlds. agents would live in these worlds and evolve differently depending on things like limb size, limb movement over time, limb shape and limb position. the agents would make different music/sounds depending on the world they live in. a limb world could be thought of as a musical part in a score. the worlds would sound simultaneously but panned to different speakers to help interaction.
the visitors would see the outline of their bodies projected on a big screen together with the agents represented visually in this picture as tiny dots. hopefully people could then hear the agents that got caught or breed inside their own limbs. we hoped to active a very direct feeling of caressing and breeding your own sounding agents.
there were plans for multi user interaction: if different limbs/outlines touched (e.g. users shaking hands), agents could migrate from one world to another. there they would inject new genes in the population, inflicting the sound, maybe die or take over totally. though to keep agents within the worlds they were made to bounce off outlines. but one could shake off agents by moving quickly or just leave the area. these 'lost' agents would then starve to death if not adopted by other users.

tech
the whole thing was written in processing and supercollider. processing did the video and graphics: getting the dv input stream, doing blobtracking (using the 3rd party library blobdetection) and drawing the agents and lines for the limbs. supercollider handled rest: the sound synthesis, the genetics, agent state and behaviours, keeping track of the worlds etc etc. we used a slightly modified version of our A4 agent framework i wrote about here.
the two programs communicated via network (osc) and would ideally run on different machines.
i had major problems with programming. the math was hairy and all the features were very taxing on the cpu. we never got further than a rough implementation.




work with mark: array primitives and benchmarking the framework

i spent a lot of time benchmarking the code for the agents in the different versions of the multi-agent frameworks i posted about here earlier. best performance boost was (of course) when i ported some vital parts of the supercollider code to c. so for example one cpu-intensive task that the agents had to do a lot was to find out about their surroundings. and another 'heavy' task was to calculate the distance to other objects. each operation wasn't very demanding on its own, but when hundreds of agents would do this at the same time, we really needed the speed of the c primitives.

below is the c code i came up with. it replaces some of the computational heavy parts in the Surroundings and ALoaction supercollider classes. to try them out you'd need to download the supercollider source code from svn, add my code to the file PyrArrayPrimitives.cpp and then recompile the whole application. edit the file extArrayedCollection.sc in the A4.zip package posted here earlier to use the primitives.
one issue we then had was to distribute this 'hack'. supercollider doesn't have an api for adding extensions like this to the language (but there's a nice plugin architecture for the server). so i had to build dedicated sc applications including this speed hack.

int prArrayAsALocationIndex(struct VMGlobals *g, int numArgsPushed)
{
        PyrSlot *a, *b;
        PyrObject *obj;
        int size, i;
        double asIndex, w, worldSize;
        a = g->sp - 1;
        b = g->sp;
        worldSize = b->ui;
        obj = a->uo;
        size = obj->size;
        asIndex= 0;
        for (i=0; i<size; ++i) {
                getIndexedDouble(obj, i, &w);
                asIndex= asIndex+(pow(worldSize, i)*w);
        }
        SetFloat(a, asIndex);
        return errNone;
}
int prArrayAsALocationRoundedIndex(struct VMGlobals *g, int numArgsPushed)
{
        PyrSlot *a, *b;
        PyrObject *obj;
        int size, i;
        double asIndex, w, worldSize;
        a = g->sp - 1;
        b = g->sp;
        worldSize = b->ui;
        obj = a->uo;
        size = obj->size;
        asIndex= 0;
        for (i=0; i<size; ++i) {
                getIndexedDouble(obj, i, &w);
                w= sc_round(w, 1.0);
                w= sc_clip(w, 0, worldSize-1);
                asIndex= asIndex+(pow(worldSize, i)*w);
        }
        SetFloat(a, asIndex);
        return errNone;
}
int prArrayDistance(struct VMGlobals *g, int numArgsPushed)
{
        PyrSlot *a, *b;
        PyrObject *obj1, *obj2;
        int size, i;
        double w1, w2, distance;
        a = g->sp - 1;
        b = g->sp;
        if (b->utag != tagObj || a->uo->classptr != b->uo->classptr) return errWrongType;
        obj1 = a->uo;
        obj2 = b->uo;
        size = obj1->size;
        distance= 0;
        for (i=0; i<size; ++i) {
                getIndexedDouble(obj1, i, &w1);
                getIndexedDouble(obj2, sc_mod(i, size), &w2);
                distance= distance+pow(w2-w1, 2);
        }
        SetFloat(a, fabs(sqrt(distance)));
        return errNone;
}
int prArraySurroundings(struct VMGlobals *g, int numArgsPushed)
{
        PyrSlot *a, *b, *c, *d, *areaArraySlots, *indexArraySlots, *outArraySlots;
        PyrObject *obj, *areaArray, *indexArray, *outArray;
        int areaSize, outSize, i, j, worldDim, area;
        double w;
        a = g->sp - 3;          //list
        b = g->sp - 2;          //worldDim
        c = g->sp - 1;          //area - as float possible later?
        d = g->sp;                      //boolean - exclude/include fix later
        if (b->utag != tagInt) return errWrongType;
        if (c->utag != tagInt) return errWrongType;
        if (d->utag != tagTrue && d->utag != tagFalse) return errWrongType;
        obj = a->uo;
        worldDim = b->ui;
        area = c->ui;
        areaSize = area*2+1;
        indexArray = newPyrArray(g->gc, worldDim, 0, true);
        indexArraySlots = indexArray->slots;
        indexArray->size = worldDim;
        if (IsTrue(d)) {        //--build index array excluding
                areaArray = newPyrArray(g->gc, areaSize-1, 0, true);
                areaArraySlots = areaArray->slots;
                areaArray->size = areaSize-1;
                int j = 0;
                for (i=0; i<areaSize-1; ++i) {
                        int temp = 0-area+i;
                        if (temp==0) {j++;}
                        areaArraySlots[i].ucopy = temp+j;
                }
                outSize = pow(areaSize, worldDim)-1;
        } else {                        //--build index array including
                areaArray = newPyrArray(g->gc, areaSize, 0, true);
                areaArraySlots = areaArray->slots;
                areaArray->size = areaSize;
                for (i=0; i<areaSize; ++i) {
                        areaArraySlots[i].ucopy = 0-area+i;
                }
                outSize = pow(areaSize, worldDim);
        }
        for (i=0; i<worldDim; ++i) {
                SetObject(indexArraySlots+i, areaArray);
        }
        //indexArray is here... [[-1, 0, 1]] or [[-1, 0, 1], [-1, 0, 1]] etc. for area=1
        //or [[-2, -1, 0, 1, 2]] or [[-2, -1, 0, 1, 2], [-2, -1, 0, 1, 2]] etc. for area=2
        //--all tuples
        outArray = newPyrArray(g->gc, outSize*sizeof(PyrObject), 0, true);
        outArraySlots = outArray->slots;
        outArray->size = outSize;
        for (i=0; i<outSize; ++i) {
                int k = i;
                PyrObject *tempArray = newPyrArray(g->gc, worldDim, 0, true);
                PyrSlot *tempArraySlots = tempArray->slots;
                tempArray->size = worldDim;
                for (j=worldDim-1; j>=0; --j) {
                        tempArraySlots[j].ucopy = areaArraySlots[k%areaSize].ucopy;
                        getIndexedDouble(obj, j, &w);
                        tempArraySlots[j].ucopy += w;
                        k /= areaSize;
                }
                SetObject(outArraySlots+i, tempArray);
        }
        a->uo = outArray;
        return errNone;
}

supercollider code for benchmarking...

//speedtest
({
        var size= 100, cSize= 2, rule= 30;
        var world, agents, y= 0, dict;
        dict= ();               /*lookup dictionary for rules*/
        8.do{|i| dict.put(i.asBinaryDigits(3).join.asSymbol, rule.asBinaryDigits[7-i])};
        ACell.rules= dict;
        world= APattern(size);                                          /*create 1d world*/
        size.do{|i| ACell(ALocation(world, [i]))};      /*fill up 1d grid with agents*/
        world.get(ALocation(world, [(size/2).round])).value= 1; /*middle agent value=1 as init*/
        agents= world.items;
        while({y&lt;size}, {
                /*here update.  first all agents.sense then all agents.act*/
                agents.do{|a| a.sense};
                /*agents.do{|a| a.location.list_([(size/2).round])};*/
                /*agents.do{|a| a.location= ALocation(a.location.world, [(size/2).round])};*/
                agents.do{|a| a.act};
                y= y+1;
        });
}.bench)

Pages

Subscribe to RSS - research