work in progress
I am working on a screen saver reacting to the ambiant sound input. Thanks to the sonia library I will be able to fulfill my wishes expressed in the first post of this blog.
import pitaru.sonia_v2_9.*; // automcatically added when importing the library from the processing menu.
void setup(){
size(800,400);
Sonia.start(this); // Start Sonia engine.
LiveInput.start(256); // Start LiveInput and return 256 FFT frequency bands.
framerate(15);
}
void draw(){
background(30,0,30);
// getMeterLevel(); // Show meter-level reading for Left/Right channels.
getSpectrum(); // Show FFT reading
}
void getSpectrum(){
strokeWeight(3);
stroke(50);
// populate the spectrum array with FFT values.
LiveInput.getSpectrum();
// draw a bar for each of the elements in the spectrum array.
// Note - the current FFT math is done in Java and is very raw. expect optimized alternative soon.
for ( int i = 0; i < 25; i++){
fill(10*i,10);
rectMode(CENTER);
rect(i*50, 3*height/4, i*20, height/2 - LiveInput.spectrum[i]/10);
rect(-i*50+850+random(30), height/4, i*20, height/2 - LiveInput.spectrum[i]/10);
}
/* rect(0,height,20,-LiveInput.spectrum[1]/10);*/
}
void getMeterLevel(){
// get Peak level for each channel (0 -> Left , 1 -> Right)
// Value Range: float from 0.0 to 1.0
// Note: use inputMeter.getLevel() to combine both channels (L+R) into one value.
float meterDataLeft = LiveInput.getLevel();
float meterDataRight = LiveInput.getLevel();
// draw a volume-meter for each channel.
fill(100,100,0);
float left = meterDataLeft*height;
float right = meterDataRight*height;
rect(width/2 - 100, height, 100 , left*-1);
rect(width/2 , height, 100, right*-1);
}
// Safely close the sound engine upon Browser shutdown.
public void stop(){
Sonia.stop();
super.stop();
}
import pitaru.sonia_v2_9.*; // automcatically added when importing the library from the processing menu.
void setup(){
size(800,400);
Sonia.start(this); // Start Sonia engine.
LiveInput.start(256); // Start LiveInput and return 256 FFT frequency bands.
framerate(15);
}
void draw(){
background(30,0,30);
// getMeterLevel(); // Show meter-level reading for Left/Right channels.
getSpectrum(); // Show FFT reading
}
void getSpectrum(){
strokeWeight(3);
stroke(50);
// populate the spectrum array with FFT values.
LiveInput.getSpectrum();
// draw a bar for each of the elements in the spectrum array.
// Note - the current FFT math is done in Java and is very raw. expect optimized alternative soon.
for ( int i = 0; i < 25; i++){
fill(10*i,10);
rectMode(CENTER);
rect(i*50, 3*height/4, i*20, height/2 - LiveInput.spectrum[i]/10);
rect(-i*50+850+random(30), height/4, i*20, height/2 - LiveInput.spectrum[i]/10);
}
/* rect(0,height,20,-LiveInput.spectrum[1]/10);*/
}
void getMeterLevel(){
// get Peak level for each channel (0 -> Left , 1 -> Right)
// Value Range: float from 0.0 to 1.0
// Note: use inputMeter.getLevel() to combine both channels (L+R) into one value.
float meterDataLeft = LiveInput.getLevel();
float meterDataRight = LiveInput.getLevel();
// draw a volume-meter for each channel.
fill(100,100,0);
float left = meterDataLeft*height;
float right = meterDataRight*height;
rect(width/2 - 100, height, 100 , left*-1);
rect(width/2 , height, 100, right*-1);
}
// Safely close the sound engine upon Browser shutdown.
public void stop(){
Sonia.stop();
super.stop();
}
0 Comments:
Post a Comment
<< Home