ok
This commit is contained in:
parent
622b4185fe
commit
df64850dfa
7 changed files with 281 additions and 92 deletions
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
@ -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<Shape2D> 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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
|
@ -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<threshold) {
|
||||
//int[] forColor = pa.getEntropyFactory().getForeground();
|
||||
//int[] backColor = pa.getEntropyFactory().getBackground();
|
||||
//if(pa.getBeat().isKick()){
|
||||
// forColor = pa.getEntropyFactory().getBackground();
|
||||
// backColor = pa.getEntropyFactory().getForeground();
|
||||
//}
|
||||
pa.stroke(forColor[0], forColor[1], forColor[2], 255);
|
||||
pa.background(backColor[0], backColor[1], backColor[2], 255);
|
||||
pa.strokeWeight(pa.random(wMin, wMax));
|
||||
|
||||
pa.line(pa.random(pa.width), pa.random(pa.height), pa.random(pa.width), pa.random(pa.height));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
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;
|
||||
|
||||
public abstract class Shape2D {
|
||||
|
||||
public Shape2D() {
|
||||
}
|
||||
|
||||
|
||||
public abstract void draw(MainSketch pa);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.incandenza.processing.audioshapes.utils;
|
||||
|
||||
import org.incandenza.processing.audioshapes.entities.Shape2D;
|
||||
import processing.core.PApplet;
|
||||
import processing.core.PGraphics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class EntropyFactory {
|
||||
|
||||
public static int LINE_DENSITY =10;
|
||||
|
||||
public int[] getForeground(){
|
||||
return new int[]{255,255,255};
|
||||
}
|
||||
|
||||
public int[] getBackground(){
|
||||
return new int[]{0,0,0};
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue