Linking rotation speed to volume of audio input?
in
Core Library Questions
•
7 months ago
Hi there, first time posting on this forum (and first time using Processing).
We're trying to create an app that features a rotating image that has its speed linked to volume. We've managed to get the speed of the rotation roughly linked to the volume of the audio picked up through the built-in mic, but it's pretty ugly. The main problem seems to be that the image returns to its origin point when there is no external input. Ideally we'd like it to continuously rotate, with the speed dictated by the volume of the audio input, so that it speeds up and slows down smothly as people speak, whistle etc.
Here's the code we're currently working on (apologies if it's a bit sloppy, we're more used to graphic design and this is a bit out of our comfort zone!):
import ddf.minim.*;
Minim minim;
AudioInput in;
float r = 0;
float s = 0;PImage myImage;
void setup(){
size(500,500);
myImage = loadImage("4test.png");
smooth();
minim = new Minim(this);
minim = new Minim(this);
minim.debugOn();
in = minim.getLineIn(Minim.STEREO,2000);}
void draw(){
background(240);
translate(250,250);
rotate (s);
rotate (r);
image( myImage, -myImage.width/2.0, -myImage.height/2.0 );
s = s + 0.01;
r = (s+in.right.get(0)*0010);
}
void stop()
{
minim.stop();
super.stop();
}
Any help/advice would be vastly appreciated! Thanks in advance.
1