Circular Audioreactive Video Element
in
Share your Work
•
1 year ago
Circular Audioreactive Video Element from DEKONSTRUKTIV.org on Vimeo.
new audiorective video element for the DISKURS'12 - Festival for young performing Arts visuals for noise/glitch/ambient band Kunst Als Strafe done in processing
either drop a foo.mp3 into the data folder or comment/uncomment line 13/14 to use line in.
- import ddf.minim.*;
- import ddf.minim.analysis.*;
- Audio audio;
- Circular circular;
- void setup(){
- size(800, 800, P2D);
- frameRate(12);
- audio= new Audio(new Minim(this), "foo.mp3");
- //audio= new Audio(new Minim(this));
- circular= new Circular(g, audio, 100);
- saveFrame();
- }
- void draw(){
- //println(frameRate);
- background(0);
- audio.analyze();
- circular.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 Circular{
- PGraphics img;
- Audio audio;
- ArrayList<Integer> history, history_left, history_right;
- int history_size;
- float[] deg_x, deg_y;
- Circular(PGraphics pg, Audio a, int h){
- audio= a;
- img= pg;
- history_size= h;
- history= new ArrayList(h);
- history_left= new ArrayList(h);
- history_right= new ArrayList(h);
- deg_x= new float[audio.fft.specSize()];
- deg_y= new float[audio.fft.specSize()];
- float x= img.width/4;
- float y= img.height/2;
- float radius= min(img.width, img.height) /2 - 100;
- float modifier= 0;
- for(int i=0; i< audio.fft.specSize(); i++){
- float deg= i * 360.0 / audio.fft.specSize();
- deg_x[i]= cos(deg) * radius + modifier;
- deg_y[i]= sin(deg) * radius + modifier;
- }
- }
- void draw(){
- drawCircles(img.width/2, height/2, 0);
- }
- void drawCircles(int x, int y, int rotate){
- float max_band= 0;
- int max_index= 0;
- img.beginDraw();
- img.ellipseMode(RADIUS);
- img.noFill();
- img.smooth();
- img.stroke(255, 100);
- int w= min(x, y)/2;
- int h= w;
- for(int i=0; i<audio.fft.specSize(); i++){
- float tempBand= audio.fft.getBand(i);
- if(tempBand > 0){
- if(tempBand > max_band){
- max_band= tempBand;
- max_index= i;
- }
- float _x= deg_x[i];
- float _y= deg_y[i];
- img.strokeWeight(max(0.2, tempBand));
- float radius= tempBand + 10;
- img.ellipse(x+_x, y+_y, radius, radius);
- }
- }
- history.add(max_index);
- if(history.size()>history_size){
- history.remove((int) 0);
- }
- img.stroke(255, 50);
- img.strokeWeight(1);
- for(int i=0; i<history.size()-1; i++){
- float xs= deg_x[history.get(i)];
- float ys= deg_y[history.get(i)];
- float xd= deg_x[history.get(i+1)];
- float yd= deg_y[history.get(i+1)];
- img.line(xs+x, ys+y, xd+x, yd+y);
- }
- img.endDraw();
- }
- }