http://spark.cla.umn.edu/schedule.html
import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;
AudioOutput out;
ByteSynth byteSynth;
float frequencyScale = PI / 2;
void setupSynth(PppProgram program) {
minim = new Minim(this);
out = minim.getLineOut(Minim.MONO, 1024, 44100 / 2);
byteSynth = new ByteSynth(program);
out.addSignal(byteSynth);
}
void stop() {
out.close();
minim.stop();
super.stop();
}
class ByteSynth implements AudioSignal {
PppProgram program;
ByteSynth(PppProgram program) {
this.program = program;
}
int curPosition = 0;
int feedbackPosition = 0;
void generate(float[] samp) {
float sumPosition = 0;
for(int i = 0; i < samp.length; i++) {
sumPosition += program.loopGet(curPosition) * frequencyScale;
samp[i] = sin(sumPosition);
curPosition++;
}
frequencyScale = map(samp[feedbackPosition], -1, +1, -TWO_PI, +TWO_PI);
feedbackPosition = (feedbackPosition + mouseY) % samp.length;
}
// this is a stricly mono signal
void generate(float[] left, float[] right) {
generate(left);
generate(right);
}
}
/*
also, code == data
but that's another project
*/
PppProgram program;
int zoom = 8;
int sizeScale = 2;
int updateRate = 256;
int colorOffset = 8;
void setup() {
frameRate(30);
size(1280 / sizeScale, 720 / sizeScale, P2D);
program = new PppProgram();
program.randomize();
setupSynth(program);
}
void draw() {
background(0);
for(int i = 0; i < updateRate; i++)
program.step();
noStroke();
int i = 0;
for(int x = 0; x < width / zoom; x++) {
for(int y = 0; y < height / zoom; y++) {
color curColor = palette[abs(program.loopGet(i) + colorOffset) % palette.length];
fill(curColor);
rect(x * zoom, y * zoom, zoom, zoom);
i++;
}
}
frequencyScale = map(mouseX, 0, width, -TWO_PI, TWO_PI);
}
void mousePressed() {
program.randomize();
}
int maxMemory = 256;
int baseRefreshTime = 2 << 12;
int refreshTime = baseRefreshTime;
class PppProgram {
TreeMap memory;
int memoryPtr;
String code;
int codePtr;
PppProgram(String code) {
this();
this.code = code;
}
PppProgram() {
memory = new TreeMap();
memoryPtr = 0;
codePtr = 0;
}
synchronized void randomize() {
int codeLength = (int) random(0, 2 << 12);
int loops = (int) random(1, 128);
code = randomCode(codeLength, loops);
maxMemory = (int) random(2, 1024);
//println("Made code: " + codeLength + "/" + loops + "/" + maxMemory);
colorOffset = (int) random(0, 16);
}
void gotoMatchedBracket() {
int count = 0;
char cur = code.charAt(codePtr);
int direction = cur == '[' ? +1 : -1;
do {
cur = code.charAt(codePtr);
if(cur == '[')
count++;
if(cur == ']')
count--;
codePtr += direction;
} while (count != 0);
}
int loopGet(int location) {
if(maxLocation == 0)
return 0;
return get(location % maxLocation);
}
int get(int location) {
location %= maxMemory;
Integer value = (Integer) memory.get(location);
if(value == null)
return 0;
else
return (int) value;
}
int get() {
return get(memoryPtr);
}
int maxLocation = 0;
void set(int location, int newValue) {
location %= maxMemory;
if(location > maxLocation)
maxLocation = location;
memory.put(location, newValue);
}
void set(int newValue) {
set(memoryPtr, newValue);
}
void plus() {
set(get() + 1);
}
void minus() {
set(get() - 1);
}
void left() {
memoryPtr--;
}
void right() {
memoryPtr++;
}
void startWhile() {
if(get() == 0)
gotoMatchedBracket();
}
void endWhile() {
if(get() != 0)
gotoMatchedBracket();
}
int size() {
return code.length();
}
int steps = 0;
void step() {
if(codePtr < size() && codePtr >= 0) {
char cur = code.charAt(codePtr);
switch(cur) {
case '+': plus(); break;
case '-': minus(); break;
case '<': left(); break;
case '>': right(); break;
case '[': startWhile(); break;
case ']': endWhile(); break;
}
codePtr++;
}
if(steps > refreshTime) {
memory = new TreeMap();
randomize();
codePtr = 0;
steps = 0;
refreshTime = (int) (baseRefreshTime * random(0, 1));
}
steps++;
}
}
String randomCode(int size, int loops) {
String code = "";
for(int i = 0; i < size; i++) {
code += randomCommand();
}
for(int i = 0; i < loops; i++) {
size = code.length();
int left = (int) random(0, size - 1);
code = insert(code, left, "[");
int right = (int) random(left + 2, size + 1);
code = insert(code, right, "]");
}
return replace(code, "\\[\\]", "");
}
String[] commands = {"<", ">", "+", "-"};
String randomCommand() {
float choice = random(0, 3);
for(int i = 0; i < 4; i++)
if(choice < i)
return commands[i];
return "";
}
String replace(String trunk, String oldText, String newText) {
String[] parts = trunk.split(oldText);
String newTrunk = "";
for(int i = 0; i < parts.length - 1; i++) {
newTrunk += parts[i] + newText;
}
newTrunk += parts[parts.length - 1];
return newTrunk;
}
String insert(String trunk, int position, String branch) {
return trunk.substring(0, position) + branch + trunk.substring(position, trunk.length());
}
color[] palette = {
0xff888888,
0xffffffff,
0xff0000ff,
0xff00ff00,
0xffff0000,
0xffffff00,
0xff00ffff,
0xffff00ff,
0xff000000,
0xff000088,
0xff008800,
0xff880000,
0xff88ff00,
0xff0088ff,
0xffff0088,
0xff888800,
0xff008888,
0xff880088,
0xffff8800,
0xff00ff88,
0xff8800ff
};
pppd is a highly formalized audiovisual composition built around the esoteric programming language p'' ("p prime prime"). During each brief scene, a random sequence of p'' code is generated and run, while the memory it uses is visualized and sonified. pppd is an artistic re-imagining of the otherwise academic field of computability theory. It functions simultaneously as an investigation of complex behavior emerging from formally simple systems, and as a playful exploration of computational dreams.
p'' is a subset of the programming language better known as Brainfuck.