Skip to content

Instantly share code, notes, and snippets.

@mattearnshaw
Last active July 9, 2016 14:14
Show Gist options
  • Save mattearnshaw/0a28fad10e58f0525c9dbbd593bed03c to your computer and use it in GitHub Desktop.
Save mattearnshaw/0a28fad10e58f0525c9dbbd593bed03c to your computer and use it in GitHub Desktop.
schizviz
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
Minim minim;
AudioOutput output;
MultiChannelBuffer buf;
AudioRecordingStream stream;
FilePlayer player;
// these 4 constants need to be changed to re-centre viz
// if window dimensions are different from 720p
// someone should work out the general formula :p
final float origin_x = 0;
final float origin_y = 113.45;
final float zoom_x = 113;
final float zoom_y = 113;
final int bufSize = 2048;
PImage fader;
// might not work if < 2
int fade_speed = 8;
// must be wav or mp3
String file_path = "/tmp/sdgfdb.wav";
int background_color = 0; // black
void setup()
{
size(1280, 720);
background(fade_speed);
fader = get();
background(background_color);
frameRate(25);
minim = new Minim(this);
output = minim.getLineOut(Minim.STEREO, bufSize);
stream = minim.loadFileStream(file_path, bufSize, false);
player = new FilePlayer(stream);
player.patch(output);
player.play();
}
void mouseClicked()
{
// reset when clicked
background(0);
player.pause();
player.rewind();
//delay(1000);
player.play();
}
// for internal use
int k = 0;
float m = 0.0;
float n = 0.0;
float x = 0.0;
float y = 0.0;
void draw()
{
// loop through buffer and draw point for each sample
for (int i = 0; i < output.bufferSize(); ++i)
{
// get sample at current index
m = output.mix.get(i);
// get sample at an index a few frames before the current (between 5 and 50, as a function of framecount)
// 5 and 50 can be changed for different effects. basically we are creating a phase plot
k = i-((frameCount%50)+5);
k = (k<0) ? -k : k; // making sure that isn't <0
n = output.mix.get(k);
// white points
stroke(255,255,255);
// calculate and draw point
x = (origin_x+n*sqrt(1-(m*m))*zoom_x);
y = (origin_y+m*sqrt(1-(n*n))*zoom_y);
point(8*(x*cos(-PI/4)-y*sin(-PI/4)), 4.5*(x*sin(-PI/4)+y*cos(PI/4)));
}
// Fade out by drawing a rectangle over display with alpha < 255
fill(background_color, fade_speed);
stroke(background_color);
// every 20 frames use blend+fader, otherwise will never fade out completely due to rounding error
if(frameCount%20==0){
noFill();
blend(fader,0,0,width,height,0,0,width,height,SUBTRACT);
}
rect(0, 0, width, height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment