Hello!
Since the last few days, I try to make a "Peter de Jong"-Attractor depending on the Computer-Microphone (Audio Input), with help of Minim.
Unfortunately, I'm quite unexperienced with processing, because I've just started learning it, so I wanted to ask, if someone here could help me with this code.
I hope, it's possible to bring the graphic/ attractor moving right to the sound intensity coming into the micro.
Here is the processing-exemplar concerning Minim- AudioInput.
CODE:
import ddf.minim.*;float x;float y;Minim minim;AudioInput input;void setup () {// Sketch einstellensize (800,800);smooth();stroke (255, 25);noFill ();// Startposition festlegenx = 0;y = 20;// Audiotoolkit anlegenminim = new Minim (this);input = minim.getLineIn (Minim.STEREO, 512);background (0);}void draw () {// Kreisgröße Abhängig von Lautstärkefloat dim = input.mix.level () * width;// Kreis x-Position verschiebenx += input.mix.level () * 20;// Kreis zeichnenellipse (x, y, dim, dim);if (x > width) {x = 0;y += 20;}}
Following the Code, I tried to write. Sorry, some comments are written in my language.
CODE:
import ddf.minim.*;
Minim minim;AudioInput input;
// Variablen und Koeffizienten (Eingangswerte)
float a = 1.78125, b = -0.78125, c = 1.90625, d = 2.65625, e = 0.7, f = -1.1; //Koeffizientenfloat x = 0.6, y = 0.9, z = 0.3; //Variablenfloat xn,yn,zn,la,lb,lc,ld; //Voruebergehende Kopien der Variablen, Koeffizienten
int N = 512, u, v; //Bildgroeße, Pixel KoordinatenPImage img = createImage(N,N,RGB); //Das Bild selbstfloat K = N*0.2; //Bildskalierungskonstante
float[] r = {0.0,0.0,0.0}; //Color (float)int[] clr = {0,0,0}; //Color (int)float[][][] fimg; //Anordnung / Matrix / Array der Punktansammlung
int nrSamples = 1000000; //Abtastwertschritteint nrPasses = 16; // Anzahl der "Schritte"int nrIterations = nrSamples/nrPasses; //Anzahl der Wiederholungenint imageProgress=0, total=0; // Buchfuehrung über den Bildfortgangboolean noise = true, init = true, hide = false; //Display Optionen
void setup() {size (N,N);frameRate (30);fimg = new float [N][N][4];
//Audiotoolkit anlegenminim = new Minim (this);input = minim.getLineIn (Minim.STEREO, 512);}
void update() {la = a;lb = b;lc = c;ld = d; // Noise hinzufügen, um Koeffizienten smoother zu machenif (noise) {la += random(-0.001, 0.001);lb += random(-0.001, 0.001);lc += random(-0.001, 0.001);ld += random(-0.001, 0.001);}
xn = sin (la*y) - cos(lb*x);yn = sin (lc*x) - cos(ld*y);zn = sin ( e*x) - cos( f*z);
x = xn;y = yn;z = zn; //Set Original to Tempu = (int)((x+2.5) * K); //Convert to 2D Image Space for Plottingv = (int)((y+2.5) * K);
r[0] = z * 0.9 + (1.0-z) * 0.6; //Map Z-Coordinate to Colorr[1] = z * 0.2 + (1.0-z) * 0.4;r[2] = z * 0.5 + (1.0-z) * 0.9;}
void accumulatePoints() {if (imageProgress < nrPasses) {colorMode(RGB, 1.0);for (int i = 0; i < nrIterations; i++) {update(); //Compute Next Pointfimg[u][v][0] += r[0];fimg[u][v][1] += r[1]; //Add New Point to Totalfimg[u][v][2] += r[2];fimg[u][v][3] += 1.0;if (i < 2000) {stroke(r[0],r[1],r[2]);point(u,v);} //Draw Points}colorMode(RGB, 255);imageProgress++;if (imageProgress <= nrPasses) total += nrIterations;}}
void draw() {//----------------------Here is, what I've tried with Minim.//----------------------Unfortunatly, I didn't come across with the//----------------------variables and so, it doesn't work :(
background (0);float a0 = a, b0 = b, c0 = c, d0 = d;// graphic depending on sound intensityfloat dim = input.mix.level () * width;a0 += input.mix.level () * 20;b0 += input.mix.level () * 20;c0 += input.mix.level () * 20;d0 += input.mix.level () * 20;//Parameter changingif (!(a==a0&&b==b0&&c==c0&&d==d0)) {init=true;}
//Initialize Collection Binsif (init) {for (int i=0; i<N; i++) {for (int j=0; j<N; j++) {for (int k=0; k<4; k++) {fimg[i][j][k] = 1.0; //Set All to 1.0 (Log-Valued Zero)}}}imageProgress = 0;total = 0;init = false;}
accumulatePoints();
// --accumulatePoints redern ----if (imageProgress == nrPasses && total == nrSamples) {
//Find Max Value - //float t1 = millis();float max = -1.0;for (int i=0; i<N; i++) {for (int j=0; j<N; j++) {if (fimg[i][j][3] > max) {max = fimg[i][j][3];}}}
//Adjust Values and Fill Imagefloat logval, logmax = log(max);float M = (logmax * logmax) / 255.0; //Precomputation for ratio (log(val)/log(max))^2
img.loadPixels();for (int i=0; i<N; i++) {for (int j=0; j<N; j++) {for (int k=0; k<3; k++) {logval = log(fimg[i][j][k]);clr[k] = (int) (logval * logval / M);}img.pixels[j*N + i] = color(clr[0],clr[1],clr[2]);}}img.updatePixels(); //float t2 = millis();println("Render: " + (t2-t1));total++;}
/* if (total >= nrSamples) {image(img,0,0,N,N);} //Draw Rendered Image */}
Thanks for your help!
1