Skip to content

Instantly share code, notes, and snippets.

@shawngrimes
Last active August 29, 2015 14:13
Show Gist options
  • Save shawngrimes/b7ab5b08fdbf3a620a1e to your computer and use it in GitHub Desktop.
Save shawngrimes/b7ab5b08fdbf3a620a1e to your computer and use it in GitHub Desktop.
Testing using audio inputs and mapping that to a color.
import ddf.minim.*;
import ddf.minim.analysis.*;
float myOpacity;
float getVolume;
int mappedVolume;
Minim minim;
AudioInput in;
void setup(){
smooth();
size(800, 400);
background(255);
minim = new Minim(this);
in = minim.getLineIn(Minim.MONO,255);
}
void draw(){
background(0);
stroke(255);
// draw the waveforms so we can see what we are monitoring
for(int i = 0; i < in.bufferSize() - 1; i++)
{
float value=in.left.get(i);
//Map the volume which ranges from 0-2 to a hex color value which ranges from 0 - 16777215
mappedVolume = int(map(value,0,255,10000,16777215));
//Get Red
float r = mappedVolume >> 16 & 0xFF;
//Get Green
float g = mappedVolume >> 8 & 0xFF;
//Get Blue
float b = mappedVolume & 0xFF;
//Set the fill color
fill(r,g,b);
//Set the stroke of the ellipse to black.
stroke(0);
//Draw the ellipse
ellipse(56, 46, 55, 55);
stroke(#FF0000);
line( i, 250 + in.left.get(i)*50, i+1, 250 + in.left.get(i+1)*50 );
}
//Reset fill color
fill(255);
String monitoringState = in.isMonitoring() ? "enabled" : "disabled";
text( "Input monitoring is currently " + monitoringState + ".", 5, 15 );
}
void keyPressed()
{
if ( key == 'm' || key == 'M' )
{
if ( in.isMonitoring() )
{
in.disableMonitoring();
}
else
{
in.enableMonitoring();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment