diff --git a/src/main/java/org/example/MySketch.java b/src/main/java/org/example/MySketch.java deleted file mode 100755 index 6d54212..0000000 --- a/src/main/java/org/example/MySketch.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.example; - -import ddf.minim.AudioInput; -import ddf.minim.Minim; -import ddf.minim.analysis.FFT; -import processing.core.PApplet; -import processing.core.PFont; - - -public class MySketch extends PApplet { - - - Minim minim; - //AudioPlayer myAudio; - AudioInput myAudio; - FFT aFFT; - - // Variables for FFT - int delFFT = 11; - int aM = 70; - float amp = 30.0f; - float aI = 0.2f; - float aIa = aI; - float aIStep = 0.35f; - float[] aData = new float[delFFT]; - - - public void settings() { - fullScreen(); - } - public void setup() { - //fullScreen(); - background(0); - - // textFont(mono, 14); - smooth(); - minim = new Minim(this); - // myAudio = minim.loadFile("music.mp3"); // must be in data folder - // myAudio.loop(); - myAudio = minim.getLineIn(Minim.MONO); - aFFT = new FFT(myAudio.bufferSize(), myAudio.sampleRate()); - aFFT.linAverages(delFFT); - aFFT.window(FFT.GAUSS); - } - - public void draw() { - noStroke(); - fill(0, 7); - rect(-10, -10, width+10, height+10); - aFFT.forward(myAudio.mix); - aDelData(); - //println(aData); - } - - void aDelData() { - String b = "[ "; - String d = "] "; - - for (int i = 0; i < delFFT; ++i) { - stroke(255,50); - fill(233f,123f,98f); - float partI = (aFFT.getAvg(i) * amp) * aIa; - float tempIndexCon = constrain(partI, 0, aM); - rect(60 + (i*35), height - 80, 39, -partI); - - fill(255); - text(b, 40 , height - 30); - text(d, width - 50, height - 30); - text( i, 60 + (i*35), height - 30); - aData[i] = tempIndexCon; - aIa += aIStep; - } - aIa = aI; - } - - public void stop() { - myAudio.close(); - minim.stop(); - super.stop(); - } - - public static void main(String[] passedArgs) { - String[] appletArgs = new String[] { "MySketch" }; - MySketch ms = new MySketch(); - PApplet.runSketch(appletArgs,ms); - } -} diff --git a/src/main/java/org/example/ConcentricParticles.java b/src/main/java/org/incandenza/processing/audioshapes/ConcentricParticles.java old mode 100755 new mode 100644 similarity index 95% rename from src/main/java/org/example/ConcentricParticles.java rename to src/main/java/org/incandenza/processing/audioshapes/ConcentricParticles.java index 2f80af9..f462629 --- a/src/main/java/org/example/ConcentricParticles.java +++ b/src/main/java/org/incandenza/processing/audioshapes/ConcentricParticles.java @@ -1,13 +1,11 @@ -package org.example; +package org.incandenza.processing.audioshapes; + -import ddf.minim.AudioInput; -import ddf.minim.Minim; -import ddf.minim.analysis.FFT; import processing.core.PApplet; import processing.core.PGraphics; import processing.core.PVector; -import java.awt.*; + import java.util.ArrayList; diff --git a/src/main/java/org/incandenza/processing/audioshapes/MainSketch.java b/src/main/java/org/incandenza/processing/audioshapes/MainSketch.java new file mode 100644 index 0000000..0c6ebdf --- /dev/null +++ b/src/main/java/org/incandenza/processing/audioshapes/MainSketch.java @@ -0,0 +1,140 @@ +package org.incandenza.processing.audioshapes; + +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import ddf.minim.analysis.BeatDetect; +import ddf.minim.analysis.FFT; +import org.incandenza.processing.audioshapes.entities.Line; +import org.incandenza.processing.audioshapes.entities.Shape2D; +import org.incandenza.processing.audioshapes.utils.EntropyFactory; +import processing.core.PApplet; +import processing.core.PGraphics; + +import java.util.ArrayList; + + +public class MainSketch extends PApplet { + //shapes + private ArrayList shapes = new ArrayList<>(); + + + private EntropyFactory entropyFactory; + Minim minim; + AudioPlayer myAudio; + //AudioInput myAudio; + private FFT aFFT; + + + + private BeatDetect beat; + + // Variables for FFT + int delFFT = 11; + int aM = 70; + float amp = 30.0f; + float aI = 0.2f; + float aIa = aI; + float aIStep = 0.35f; + float[] aData = new float[delFFT]; + + float maxAvg=0.0000000001f; + + + private PGraphics pg; + public void settings() { + + fullScreen(); + } + public void setup() { + this.entropyFactory = new EntropyFactory(); + for (int i = 0; i < EntropyFactory.LINE_DENSITY; i++) { + shapes.add(new Line()); + } + + smooth(); + + //fullScreen(); + pg = createGraphics(displayWidth, displayHeight); + background(0); + color(0,0,0); + // textFont(mono, 14); + minim = new Minim(this); + myAudio = minim.loadFile("C:\\Users\\LucaConte\\tmp\\song.mp3",2048); // must be in data folder + myAudio.loop(); + //myAudio = minim.getLineIn(Minim.MONO); + aFFT = new FFT(myAudio.bufferSize(), myAudio.sampleRate()); + aFFT.linAverages(delFFT); + aFFT.window(FFT.GAUSS); + beat = new BeatDetect(myAudio.bufferSize(),myAudio.sampleRate()); + + } + + public void draw() { + + aFFT.forward(myAudio.mix); + beat.detect(myAudio.mix); + background(0); + // fill(0, 255); + // color(255,255,255); + for (Shape2D s: shapes) { + s.draw(this); + } + // noStroke(); + // rect(-10, -10, width+10, height+10); + //aDelData(); + maxAvg =aFFT.getAvg(0)>maxAvg?aFFT.getAvg(0):maxAvg; + // for (int i = 0; i < delFFT; ++i) { + // println(i+": " + aFFT.getAvg(i)); + //} + } + + @Override + public void keyPressed() { + super.keyPressed(); + println("max avg: " + maxAvg); + } + + void aDelData() { + String b = "[ "; + String d = "] "; + + for (int i = 0; i < delFFT; ++i) { + stroke(255,50); + fill(233f,123f,98f); + float partI = (aFFT.getAvg(i) * amp) * aIa; + float tempIndexCon = constrain(partI, 0, aM); + rect(60 + (i*35), height - 80, 39, -partI); + + fill(255); + text(b, 40 , height - 30); + text(d, width - 50, height - 30); + text( i, 60 + (i*35), height - 30); + aData[i] = tempIndexCon; + aIa += aIStep; + } + aIa = aI; + } + + public void stop() { + myAudio.close(); + minim.stop(); + super.stop(); + + } + public EntropyFactory getEntropyFactory() { + return entropyFactory; + } + public FFT getaFFT() { + return aFFT; + } + + public BeatDetect getBeat() { + return beat; + } + public static void main(String[] passedArgs) { + String[] appletArgs = new String[] { "MySketch" }; + MainSketch ms = new MainSketch(); + PApplet.runSketch(appletArgs,ms); + } +} diff --git a/src/main/java/org/incandenza/processing/audioshapes/PerlinStorm.java b/src/main/java/org/incandenza/processing/audioshapes/PerlinStorm.java new file mode 100644 index 0000000..6ed4ab7 --- /dev/null +++ b/src/main/java/org/incandenza/processing/audioshapes/PerlinStorm.java @@ -0,0 +1,70 @@ +package org.incandenza.processing.audioshapes; + +import processing.core.PApplet; +import processing.core.PGraphics; +import processing.core.PVector; + +public class PerlinStorm extends PApplet { + + private PGraphics pg; + + @Override + public void settings(){ + // fullScreen(); + size(displayWidth, displayHeight, P2D); + } + @Override + public void setup() { + + pg = createGraphics(displayWidth, displayHeight, P2D); + pg.smooth(8); + pg.beginDraw(); + pg.blendMode(ADD); + pg.background(0); + pg.endDraw(); + } + @Override + public void draw() { + pg.beginDraw(); + pg.background(0); + pg.stroke(125, 125, 200, 50); + float r = 500; + int perFrame = (int)(r * 1.5); + PVector m = new PVector(pg.width / 2, pg.height / 2); + for (int i = 0; i < perFrame; i++) { + float t = 2 * PI * i / perFrame; + PVector p = PVector.fromAngle(t).mult(r).add(m); + noiseLine(m.x, m.y, p.x, p.y, 5f + r * 1.5f * mouseX / width); + } + pg.endDraw(); + image(pg, 0, 0, width, height); + println(frameRate); + } + + private void noiseLine(float x1, float y1, float x2, float y2, float maxNoise) { + PVector a = new PVector(x1, y1); + PVector b = new PVector(x2, y2); + PVector diff = b.copy().sub(a); + PVector dir = diff.copy().normalize(); + PVector n = new PVector(-dir.y, dir.x); + float mag = diff.mag(); + float half = mag / 2; + pg.noFill(); + pg.beginShape(); + //vertex(a.x, a.y); + for (int i = 0; i < mag; i += 4) { + PVector p = dir.copy().mult(i).add(a); + float df = 1 - abs(i - half) / half; + p.add( + n.copy().mult(df * maxNoise * (0.5f - noise(p.x * 0.01f + frameCount * 0.017f, p.y * 0.01f + frameCount * 0.009f)))); + pg.vertex(p.x, p.y); + } + pg.endShape(); + } + public static void main(String[] passedArgs) { + String[] appletArgs = new String[] { "PerlinStorm" }; + PerlinStorm ms = new PerlinStorm(); + PApplet.runSketch(appletArgs,ms); + + } +} diff --git a/src/main/java/org/incandenza/processing/audioshapes/entities/Line.java b/src/main/java/org/incandenza/processing/audioshapes/entities/Line.java new file mode 100644 index 0000000..a86b12c --- /dev/null +++ b/src/main/java/org/incandenza/processing/audioshapes/entities/Line.java @@ -0,0 +1,33 @@ +package org.incandenza.processing.audioshapes.entities; + +import org.incandenza.processing.audioshapes.MainSketch; +import org.incandenza.processing.audioshapes.utils.EntropyFactory; +import processing.core.PApplet; +import processing.core.PGraphics; +import processing.core.PVector; + +public class Line extends Shape2D { + + @Override + public void draw(MainSketch pa) { + float dice = pa.random(100); + float threshold = pa.getaFFT().getAvg(0); + threshold = threshold >=10 ? 100:threshold*10; + int wMin = 1; + int wMax = wMin+10; + + if(dice