Interactivity with Sound Library

One of my interests is ability to translate sounds into visuals. I installed Sound and Minim libraries.

http://code.compartmental.net/minim/audioinput_class_audioinput.html

First, I wanted to use sound input received from computer mic to change opacity of the image – make it blink. That sketch does it –

import ddf.minim.*;

PImage img;

Minim minim;
AudioInput in;
void setup()
{
size(400, 400, P3D);
img = loadImage(“ballerina.jpg”);
minim = new Minim(this);

// use the getLineIn method of the Minim object to get an AudioInput
in = minim.getLineIn();
}

void draw()
{
background(0);
stroke(255);
float level = in.mix.level();

tint(255, 255*level);
image(img, 0, 0);

}

Further I tried to combine this idea with last week’s sketch, where pixels created explosive movement by reacting on mouse movement, so this time i decided make them react to sound instead of mouse, here is what I got –

import ddf.minim.*;

PImage img;

//float myOpacity;

Minim minim;
AudioInput in;
float bufferSizeMy;
int i = 0;

void setup()
{
size(400, 400, P3D);
img = loadImage(“ballerina.jpg”);
minim = new Minim(this);

// use the getLineIn method of the Minim object to get an AudioInput
in = minim.getLineIn();
}

void draw()
{
background(0);
//stroke(255);
loadPixels();
// Begin loop for columns
for ( int x = 0; x < width;x++) {
// Begin loop for rows
for ( int y = 0; y < height;y++) {
int loc = x + y*width; // Pixel array location
color c = img.pixels[loc]; // Grab the color

// myOpacity = map ( abs(in.mix.get(i)), 0, .7, 0, 255);
float level = in.mix.level();

// Calculate a z position as a function of mouseX and pixel brightness
float z = level*5 * brightness(img.pixels[loc]) – 100.0;
// Translate to the location, set fill and stroke, and draw the rect
pushMatrix();
translate(x,y,z);
fill(c);
noStroke();
rectMode(CENTER);
rect(0,0,1,1);
popMatrix();
}
}

}

}

 

The output is pretty much the same(but controlled with the live sound):

pixeldance3pixeldancepixeldance2pixeldance3pixeldance4

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s