generative audioreactive glitch visuals
in
Share your Work
•
1 year ago
Kunst Als Strafe visuals 2012 from DEKONSTRUKTIV.org on Vimeo.
generative audioreactive glitch visuals for post-industrial/ambient/noise act
Kunst Als Strafe . i appropriated some snippets from several places all over the web & did a fair share of developing on my own.
you will need to throw some audio via line in at the thing or dump an mp3 file into its data folder as foo.mp3 & uncomment/comment lines 55/56 to load the file.
the thing is split into a sequence of several sections i shortened to 1 min each.
- import java.util.Collections;
- import ddf.minim.*;
- import ddf.minim.analysis.*;
- import processing.video.*;
- import wblut.geom.core.*;
- import wblut.hemesh.creators.*;
- import wblut.hemesh.tools.*;
- import wblut.geom.grid.*;
- import wblut.geom.nurbs.*;
- import wblut.core.math.*;
- import wblut.hemesh.subdividors.*;
- import wblut.core.processing.*;
- import wblut.hemesh.composite.*;
- import wblut.core.random.*;
- import wblut.hemesh.core.*;
- import wblut.geom.frame.*;
- import wblut.core.structures.*;
- import wblut.hemesh.modifiers.*;
- import wblut.hemesh.options.*;
- import wblut.hemesh.simplifiers.*;
- import wblut.geom.triangulate.*;
- import wblut.geom.tree.*;
- Circles circles;
- Grid grid;
- Data data;
- Glitch glitch;
- Timer timer;
- Mesh meshl, meshr;
- SequenceManager sequenceManager;
- int[] sequence= {
- 1, 1, 1,
- 1, 1, 1,
- 1, 1
- };
- int current_stage;
- Audio audio;
- PGraphics pgDummy;
- MovieMaker mmOut;
- void setup(){
- size(1600, 600, P3D);
- frameRate(12);
- sequenceManager= new SequenceManager(sequence);
- Minim minim= new Minim(this);
- //audio= new Audio(minim, "foo.mp3");
- audio= new Audio(minim);
- circles= new Circles(createGraphics(width, height, P2D), audio, 255, 75);
- //grid= new Grid(createGraphics(width, height, P2D), audio, 0);
- grid= new Grid(g, audio, 0);
- glitch= new Glitch(g, audio, 0);
- data= new Data(g, audio, 255, 128, false);
- meshl= new Mesh(this, g, audio, width/4, height/2, 64, 32, false);
- meshr= new Mesh(this, g, audio, width-width/4, height/2, 200, 100, true);
- timer= new Timer(g, sequenceManager, width-250, height-16, 255, 200);
- pgDummy= createGraphics(width, height, P2D);
- }
- void draw(){
- current_stage= sequenceManager.getStage();
- background(0);
- // println(frameRate);
- audio.analyze();
- switch(current_stage){
- case 0:{
- circles.draw();
- copy(circles.img, 0, 0, circles.img.width, circles.img.height, 0, 0, circles.img.width, circles.img.height);
- break;
- }
- case 1:{
- circles.draw();
- copy(circles.img, 0, 0, circles.img.width, circles.img.height, 0, 0, circles.img.width, circles.img.height);
- grid.split=true;
- grid.prepare();
- data.setGrid(grid.rects);
- data.alpha= 100;
- data.draw();
- break;
- }
- case 2:{
- circles.draw();
- copy(circles.img, 0, 0, circles.img.width, circles.img.height, 0, 0, circles.img.width, circles.img.height);
- grid.split=true;
- grid.prepare();
- data.setGrid(grid.rects);
- data.alpha= 100;
- data.draw();
- glitch.draw();
- break;
- }
- //////////////////////////////////////////////////////////////////////
- case 3:{
- circles.draw();
- copy(circles.img, 0, 0, circles.img.width, circles.img.height, 0, 0, circles.img.width, circles.img.height);
- lights();
- if(! (Boolean) audio.clicks.get(2))
- meshl.draw();
- if(! (Boolean) audio.clicks.get(5))
- meshr.draw();
- glitch.draw();
- break;
- }
- case 4:{
- circles.draw();
- copy(circles.img, 0, 0, circles.img.width, circles.img.height, 0, 0, circles.img.width, circles.img.height);
- grid.prepare();
- grid.split=true;
- grid.draw();
- lights();
- meshl.draw();
- meshr.draw();
- glitch.draw();
- break;
- }
- case 5:{
- circles.draw();
- copy(circles.img, 0, 0, circles.img.width, circles.img.height, 0, 0, circles.img.width, circles.img.height);
- lights();
- meshl.draw();
- meshr.draw();
- grid.prepare();
- grid.split= true;
- grid.draw();
- glitch.draw();
- break;
- }
- case 6:{
- circles.draw();
- copy(circles.img, 0, 0, circles.img.width, circles.img.height, 0, 0, circles.img.width, circles.img.height);
- lights();
- meshl.draw();
- meshr.draw();
- grid.prepare();
- grid.split= true;
- grid.draw();
- glitch.draw();
- break;
- }
- case 7:{
- circles.draw();
- copy(circles.img, 0, 0, circles.img.width, circles.img.height, 0, 0, circles.img.width, circles.img.height);
- lights();
- meshl.draw();
- meshr.draw();
- grid.prepare();
- grid.split= true;
- grid.draw();
- glitch.draw();
- break;
- }
- case 12:{
- data.setGrid(grid.rects);
- grid.draw();
- data.draw();
- glitch.draw();
- break;
- }
- }
- timer.draw();
- }
- class Audio {
- Minim minim;
- FFT fft;
- AudioInput input;
- AudioPlayer player;
- int beat_sensitivity;
- BeatDetect bLeft, bRight;
- public ArrayList clicks;
- float level, left, right;
- Audio(Minim m, String s){
- minim = m;
- println("using audio file "+s);
- player = minim.loadFile(s);
- player.play();
- fft = new FFT(player.bufferSize(), player.sampleRate());
- bLeft= new BeatDetect(player.bufferSize(), player.sampleRate());
- bLeft.setSensitivity(beat_sensitivity);
- bRight= new BeatDetect(player.bufferSize(), player.sampleRate());
- bRight.setSensitivity(beat_sensitivity);
- _init();
- }
- Audio(Minim m){
- minim = m;
- println("using line in ");
- input= minim.getLineIn(Minim.STEREO, 2048);
- fft = new FFT(input.bufferSize(), input.sampleRate());
- bLeft= new BeatDetect(input.bufferSize(), input.sampleRate());
- bRight= new BeatDetect(input.bufferSize(), input.sampleRate());
- _init();
- }
- void _init(){
- clicks= new ArrayList();
- beat_sensitivity= 1000;
- level= 0;
- left= 0;
- right= 0;
- setBeatSensitivity(beat_sensitivity);
- for(int i=0; i<6; i++){
- clicks.add(false);
- }
- }
- public void analyze(){
- if(input == null){
- fft.forward(player.mix);
- level= player.mix.level();
- left= player.left.level();
- right= player.right.level();
- bLeft.detect(player.left);
- bRight.detect(player.right);
- } else {
- fft.forward(input.mix);
- level= input.mix.level();
- left= input.left.level();
- right= input.right.level();
- bLeft.detect(input.left);
- bRight.detect(input.right);
- }
- clicks.set(0, bLeft.isKick());
- clicks.set(1, bLeft.isSnare());
- clicks.set(2, bLeft.isHat());
- clicks.set(3, bRight.isKick());
- clicks.set(4, bRight.isSnare());
- clicks.set(5, bRight.isHat());
- }
- public void setBeatSensitivity(int s){
- println("beat sensitivity: "+s);
- beat_sensitivity= s;
- bLeft.setSensitivity(beat_sensitivity);
- bRight.setSensitivity(beat_sensitivity);
- }
- }
- class Circles{
- PGraphics img;
- Audio audio;
- int col= 255;
- int alpha= 255;
- int fade= 0;
- public int speed= 1;
- float x;
- int y, delta;
- Circles(PGraphics pg, Audio aud){
- _init(pg, aud);
- }
- Circles(PGraphics pg, Audio aud, int c, int a){
- col= c;
- alpha= a;
- _init(pg, aud);
- }
- void _init(PGraphics pg, Audio a){
- img= pg;
- audio= a;
- img.background(0, 0);
- img.smooth();
- img.noFill();
- delta= (int) width/25;
- x= 0;
- y= delta;
- }
- public void draw(){
- float level= audio.level;
- float dim= level * img.width;
- hint(DISABLE_DEPTH_TEST);
- for(int i= 0; i < speed; i++){
- img.beginDraw();
- img.smooth();
- img.stroke(col, alpha);
- img.noFill();
- if(fade == 0){
- x+= level * delta;
- img.ellipse(x, y, dim, dim);
- if(x>img.width){
- x= 0;
- y+= delta;
- }
- }
- if(y>img.height) {
- if(fade < 30){
- img.fill(0, fade);
- img.rect(0, 0, img.width, img.height);
- fade++;
- } else {
- img.noFill();
- y= delta;
- fade= 0;
- }
- }
- img.endDraw();
- hint(ENABLE_DEPTH_TEST);
- }
- }
- public void reset(){
- img.beginDraw();
- img.fill(0);
- img.rect(0, 0, img.width, img.height);
- img.noFill();
- img.endDraw();
- }
- }
- class Grid{
- PGraphics img;
- public int col= 255;
- public boolean invert;
- public boolean split;
- Audio audio;
- public ArrayList<int[]> rects, rects_inverted;
- ArrayList idx_top, idx_btm;
- int _w, _h;
- Grid(PGraphics pg, Audio a, int c){
- col= c;
- img= pg;
- audio= a;
- invert= false;
- split= false;
- rects= new ArrayList();
- rects_inverted= new ArrayList();
- idx_top= new ArrayList();
- idx_btm= new ArrayList();
- for(int i= 0; i<audio.clicks.size(); i++){
- idx_top.add(i);
- idx_btm.add(i);
- }
- }
- public void prepare(){
- rects.clear();
- rects_inverted.clear();
- if((Boolean) audio.clicks.get(0)){
- Collections.shuffle(idx_top);
- }
- if((Boolean) audio.clicks.get(3)){
- Collections.shuffle(idx_btm);
- }
- for(int i= 0; i<audio.clicks.size(); i++){
- if(!split){
- _w= img.width;
- _h= ceil(img.height/12);
- if(decide((Boolean) audio.clicks.get((Integer) idx_top.get(i)))){
- int[] _rect= {0, _h*i, _w, _h};
- rects.add(_rect);
- } else {
- int[] _rect= {0, _h*i, _w, _h};
- rects_inverted.add(_rect);
- }
- if(decide((Boolean) audio.clicks.get((Integer) idx_btm.get(i)))){
- int[] _rect= {0, _h*(i+6), _w, _h};
- rects.add(_rect);
- } else {
- int[] _rect= {0, _h*(i+6), _w, _h};
- rects_inverted.add(_rect);
- }
- } else {
- _w= img.width/2;
- _h= ceil(img.height/6);
- if(decide((Boolean) audio.clicks.get((Integer) idx_top.get(i)))){
- int[] _rect= {0, _h*i, _w, _h};
- rects.add(_rect);
- } else {
- int[] _rect= {0, _h*i, _w, _h};
- rects_inverted.add(_rect);
- }
- if(decide((Boolean) audio.clicks.get((Integer) idx_btm.get(i)))){
- int[] _rect= {_w, _h*i, _w, _h};
- rects.add(_rect);
- } else {
- int[] _rect= {_w, _h*i, _w, _h};
- rects_inverted.add(_rect);
- }
- }
- }
- }
- boolean decide(Boolean b){
- if(invert){
- return !b;
- } else {
- return b;
- }
- }
- public void draw(){
- draw(false);
- }
- public void draw(boolean invert){
- img.beginDraw();
- img.hint(DISABLE_DEPTH_TEST);
- img.noStroke();
- img.fill(col);
- if(invert){
- for(int i= 0; i<rects_inverted.size(); i++){
- int[] _rect= rects_inverted.get(i);
- img.rect(_rect[0], _rect[1], _rect[2], _rect[3]);
- }
- } else {
- for(int i= 0; i<rects.size(); i++){
- int[] _rect= rects.get(i);
- img.rect(_rect[0], _rect[1], _rect[2], _rect[3]);
- }
- }
- img.hint(ENABLE_DEPTH_TEST);
- img.endDraw();
- }
- }
- class Data{
- public PGraphics img;
- public int col= 255;
- public int alpha= 255;
- public boolean invert= false;
- PFont pixel;
- StringBuilder str, bin;
- ArrayList<int[]> rects;
- Data(PGraphics pg, Audio audio, int c, int a, boolean i){
- col= c;
- alpha= a;
- invert= i;
- img= pg;
- rects= new ArrayList();
- str= new StringBuilder();
- bin= new StringBuilder();
- pixel= createFont("Minecraftia.ttf", 8, false);
- }
- void setGrid(ArrayList<int[]> g){
- rects= g;
- }
- void draw(){
- str.setLength(0);
- bin.setLength(0);
- str.append(frameRate);
- str.append(audio.level);
- str.append(audio.left);
- str.append(audio.right);
- str.append(millis());
- for(int i= 0; i<str.length(); i++){
- bin.append(binary(str.charAt(i)));
- }
- str.append(bin);
- img.beginDraw();
- img.textMode(SCREEN);
- img.hint(DISABLE_DEPTH_TEST);
- img.noStroke();
- img.fill(col, alpha);
- img.textFont(pixel);
- for(int i= 0; i<rects.size(); i++){
- int[] _rect= rects.get(i);
- img.text(str.toString(), _rect[0], _rect[1], _rect[2], _rect[2]);
- }
- img.hint(ENABLE_DEPTH_TEST);
- img.endDraw();
- }
- }
- class Glitch{
- PGraphics img;
- Audio audio;
- int col= 0;
- float tempBand;
- float sensitivity;
- Glitch(PGraphics pg, Audio a, int c){
- img= pg;
- col= c;
- audio= a;
- sensitivity= 0.5;
- }
- public void draw(){
- int _height = height / audio.fft.specSize() - 2;
- img.beginDraw();
- img.hint(DISABLE_DEPTH_TEST);
- img.stroke(col);
- for (int i = 0; i < audio.fft.specSize() && i * (_height+3) <= height; i++) {
- tempBand = audio.fft.getBand(i);
- if(tempBand>sensitivity){
- img.line(0, i * (_height+3), width, i * (_height+3));
- }
- }
- img.hint(ENABLE_DEPTH_TEST);
- img.endDraw();
- }
- }
- class Mesh{
- PGraphics img;
- Audio audio;
- public int col_stroke, col_fill;
- public boolean axis_invert;
- public int xpos, ypos;
- public float noise_scale, mesh_scale;
- double rotate_x, rotate_y;
- HE_Mesh mesh;
- HEM_Extrude extrude;
- HEM_Noise modifier;
- HEC_Icosahedron creator;
- HES_CatmullClark subdividor_cmc;
- HES_PlanarMidEdge subdividor_pme;
- WB_Render render;
- Mesh(PApplet parent, PGraphics pg, Audio a, int x, int y, int s, int f, boolean i){
- img= pg;
- col_stroke= s;
- col_fill= f;
- axis_invert= i;
- xpos= x;
- ypos= y;
- mesh_scale= 0.75;
- noise_scale= width/3;
- audio= a;
- rotate_x= 0;
- rotate_y= 0;
- creator= new HEC_Icosahedron();
- creator.setEdge(mesh_scale*height/2);
- creator.setZAngle(PI/2);
- creator.setCenter(xpos, ypos, 0);
- subdividor_pme= new HES_PlanarMidEdge();
- subdividor_cmc= new HES_CatmullClark();
- /*creator= new HEC_Geodesic();
- creator.setRadius(height/4);
- creator.setLevel(2);
- creator.setCenter(xpos, ypos, 0);
- */
- mesh= new HE_Mesh(creator);
- render= new WB_Render(parent);
- modifier= new HEM_Noise();
- }
- public void draw(){
- rotate_y+= audio.left;
- rotate_x+= audio.right;
- if(axis_invert){
- creator.setZAxis(0, 0, 1);
- } else {
- creator.setZAxis(0, 1, 0);
- }
- creator.setZAngle(rotate_x);
- if(axis_invert){
- creator.setZAxis(0, 1, 0);
- } else {
- creator.setZAxis(0, 0, 1);
- }
- creator.setZAngle(rotate_y);
- mesh= new HE_Mesh(creator);
- mesh.subdivide(subdividor_cmc,1);
- //mesh.subdivide(subdividor_pme);
- modifier.setDistance(audio.level * noise_scale);
- mesh.modify(modifier);
- img.beginDraw();
- img.fill(col_fill, 128);
- img.noStroke();
- render.drawFaces(mesh, img);
- if(col_stroke>0){
- img.stroke(col_stroke, 128);
- render.drawEdges(mesh, img);
- }
- img.endDraw();
- }
- }
- class SequenceManager{
- int[] sequence;
- int current_stage;
- int t_offset;
- float t;
- SequenceManager(int[] s){
- sequence= s;
- current_stage= -1;
- t_offset= 0;
- }
- public int getStage(){
- t= millis()/60000.0 + t_offset;
- int stage= 0;
- while(stage < sequence.length && t >= duration(stage)){
- stage++;
- }
- if(stage > current_stage && stage<sequence.length){
- current_stage= stage;
- println("### STAGE "+(current_stage+1)+" of "+sequence.length+" at "+nf(hour(), 2)+":"+nf(minute(),2)+" for "+sequence[current_stage]+" min ending at "+duration(current_stage)+" of "+duration());
- }
- return current_stage;
- }
- public int duration(int stage){
- int duration= 0;
- for(int i=0; i<= stage; i++){
- duration+= sequence[i];
- }
- return duration;
- }
- public int duration(){
- int duration= 0;
- for(int i=0; i< sequence.length; i++){
- duration+= sequence[i];
- }
- return duration;
- }
- }
- class Timer{
- public PGraphics img;
- SequenceManager manager;
- public int col, alpha, x, y;
- PFont pixel;
- int t, h, m, s, mils;
- Timer(PGraphics pg, SequenceManager m, int _x, int _y, int c, int a){
- img= pg;
- manager= m;
- col= c;
- alpha= a;
- x= _x;
- y= _y;
- pixel= createFont("Minecraftia.ttf", 16, false);
- }
- public void draw(){
- img.beginDraw();
- img.hint(DISABLE_DEPTH_TEST);
- img.textFont(pixel);
- img.stroke(col, alpha);
- for(int i= 0; i<manager.sequence.length; i++){
- if(manager.current_stage == i){
- int stage_left= manager.duration(i) * 60000 - millis();
- img.fill(col, alpha);
- if(stage_left>0){
- text(getTimer(stage_left), x + manager.sequence.length*10 + manager.sequence.length*3 + 10 +3, y-10);
- }
- } else {
- img.noFill();
- }
- rect( x + i*10 + i*3, y, 10, 10);
- }
- img.noStroke();
- img.fill(col, alpha);
- img.text(getTimer(), x + manager.sequence.length*10 + manager.sequence.length*3 + 10 +3, y+12);
- img.hint(ENABLE_DEPTH_TEST);
- img.endDraw();
- }
- public String getTimer(){
- return getTimer(millis());
- }
- public String getTimer(int t){
- h= t / (1000 * 60 * 60);
- t-= h * (1000 * 60 * 60);
- m= t / (1000 * 60);
- t-= m * (1000 * 60);
- s= t / 1000;
- t-= s * 1000;
- mils= t;
- return nf(h, 2)+":"+nf(m, 2)+":"+nf(s, 2)+":"+nf(mils, 3);
- }
- }
- void keyPressed(){
- if(key == ENTER){
- println("frame saved.");
- saveFrame();
- }
- if(key=='f' || key=='F'){
- println("current framerate: "+frameRate);
- }
- if(key=='c' || key=='C'){
- if(circles.speed == 1){
- circles.speed= 15;
- } else {
- circles.speed= 1;
- }
- }
- if(key=='s' || key=='S'){
- grid.split= !grid.split;
- }
- if(key=='i' || key=='I'){
- grid.invert= !grid.invert;
- }
- if(key>='0' && key <='9'){
- if(key=='0'){
- key= '9'+1;
- }
- audio.setBeatSensitivity((key-'1'+1)*100);
- }
- }