Skip to content

Instantly share code, notes, and snippets.

@robbeofficial
Created December 11, 2014 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbeofficial/1da157e452b431b75b37 to your computer and use it in GitHub Desktop.
Save robbeofficial/1da157e452b431b75b37 to your computer and use it in GitHub Desktop.
renders this: https://www.youtube.com/watch?v=rtR63-ecUNo in software (no sound output yet). result looks like this: https://dl.dropboxusercontent.com/u/5505209/tmp/lissajous.png
import java.io.*;
DataInputStream dis;
void setup()
{
size(256, 256);
try {
dis = new DataInputStream(new FileInputStream("/home/robbe/tmp/howtodrawmushrooms.8s.raw")); // 192khz, 8 bit signed, stereo PCM
} catch (Exception e) {e.printStackTrace();}
background(0);
noStroke();
fill(16,255,32);
}
void draw()
{
// fade out instead of clear to be more phosphor-like (TODO move this to a shader)
loadPixels();
for (int i=0; i<pixels.length; i++) {
int v = pixels[i];
int b = (v << 0) & 0xff;
int g = (v >> 8) & 0xff;
int r = (v >> 16) & 0xff;
final int decay = 16;
r = constrain(r-decay, 0, 255);
g = constrain(g-decay, 0, 255);
b = constrain(b-decay, 0, 255);
pixels[i] = (b << 0) | (g << 8) | (r << 16);
}
updatePixels();
translate(width/2, height/2);
int n = (int) (192000.0 / frameRate); // number of samples for this frame
try {
for (int i=0; i<n; i++) {
int l = dis.readByte(); // left/right channel
int r = dis.readByte();
ellipse(l,-r,3,3); // electron beam (TODO gaussian shape of beam and line connections between samples)
}
} catch (Exception e) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment