There are no translations available.
Kapcsolódó linkek:
www.processing.org
http://www.openprocessing.org/
http://www.shiffman.net/
http://www.youtube.com/watch?v=AyJfHU4GoOQ
http://www.youtube.com/watch?v=RbJWLMeHYmM&feature=related
http://vimeo.com/410394
processing :: soundAnalyzer class
www.binaura.net/bnc/temp/SoundAnalizer.pde
-------------------------------------------------------------------------------------
copy/paste
-------------------------------------------------------------------------------------
import ddf.minim.analysis.*;
import ddf.minim.*;
PApplet app = this;
public class SoundAnalizer extends PApplet
{
Minim minim;
AudioInput in;
FFT fft;
int bufferSize = 512;
int sampleRate = 44100;
float maxAvg = 0;
float[] spectrum;
float t_volume, volume;
float volumeDamp = 3;
float learnSpeed = 0.995;
float peak, t_peak;
float peakDamp = 5.0;
SoundAnalizer()
{
app.registerDraw(this);
minim = new Minim(this);
in = minim.getLineIn(Minim.MONO, bufferSize, sampleRate);
fft = new FFT(in.bufferSize(), in.sampleRate());
fft.logAverages(sampleRate, bufferSize);
spectrum = new float[bufferSize];
peak = t_peak = 0;
}
void draw()
{
fft.forward(in.mix);
maxAvg *= learnSpeed;
t_volume = 0;
for (int i = 0; i < fft.avgSize(); i++)
{
if (fft.getAvg(i) > maxAvg) maxAvg = fft.getAvg(i);
float v = fft.getAvg(i) * (1 / maxAvg);
spectrum[i] = v;
if (v > t_volume)
{
t_volume = v;
t_peak = i / (float)fft.avgSize();
}
}
peak += (t_peak - peak) / peakDamp;
volume += (t_volume - volume) / volumeDamp;
}
float getSpectrum(float p)
{
p = constrain(p, 0, 1);
int n = (int)(p * (fft.avgSize() - 1));
return spectrum[n];
}
float getSignal(float p)
{
p = constrain(p, 0, 1);
int n = (int)(p * (in.bufferSize() - 1));
return in.mix.get(n);
}
float getVolumeRange(float a, float b)
{
if (a > b)
{
float c = a;
a = b;
b = c;
}
a = constrain(a, 0, 1);
int n1 = (int)(a * (fft.avgSize() - 1));
b = constrain(b, 0, 1);
int n2 = (int)(b * (fft.avgSize() - 1));
float vol = 0;
for (int i = n1; i < n2; i++)
{
vol += spectrum[i];
}
if (n1 != n2) vol /= (n2 - n1);
return vol;
}
float getVolume()
{
return volume;
}
float getPeak()
{
return peak;
}
void stop()
{
minim.stop();
super.stop();
}
}
----------------------------------------------------------
Program modes example:
----------------------------------------------------------
import processing.opengl.*;
boolean modeLines;
boolean modeCircles;
void setup()
{
size(500, 500, OPENGL);
modeLines = false;
modeCircles = false;
background(0, 0, 0);
}
void draw()
{
noStroke();
fill(128, 128, 128, 10);
rect(0, 0, width, height);
if (modeLines == true)
{
drawRandomLines();
}
if (modeCircles == true)
{
drawRandomCircles();
}
}
void drawRandomLines()
{
stroke(255, 255, 255, 100);
for (int i = 0; i < 100; i++)
{
line(random(width), random(height), random(width), random(height));
}
}
void drawRandomCircles()
{
noStroke();
fill(0, 0 ,0 , 100);
for (int i = 0; i < 100; i++)
{
ellipse(random(width), random(height), random(10, 20), random(10, 20));
}
}
void keyPressed()
{
println(key);
if (key == 'a')
{
if (modeLines == true)
{
modeLines = false;
}
else
{
modeLines = true;
}
}
if (key == 'b')
{
if (modeCircles == true)
{
modeCircles = false;
}
else
{
modeCircles = true;
}
}
}
!!you will need the soundAnalizer frameworks to use these codes!!
--------------------------------------------------------------
spectroGraph example
--------------------------------------------------------------
import processing.opengl.*;
SoundAnalizer sound;
int x;
void setup()
{
size(1024, 200, OPENGL);
sound = new SoundAnalizer();
x = 0;
background(0, 0, 0);
}
void draw()
{
noStroke();
for (int y = 0; y < height; y++)
{
float v = sound.getSpectrum(map(y, 0, height, 0, 1));
fill(255 * v);
rect(x, y, 1, 1);
}
x++;
if (x > width)
{
x = 0;
}
}
--------------------------------------------------------------------
volumeRadialBoxes example
---------------------------------------------------------------------
import processing.opengl.*;
SoundAnalizer sound;
void setup()
{
size(1024, 768, OPENGL);
sound = new SoundAnalizer();
rectMode(CENTER);
noCursor();
}
void draw()
{
background(0, 0, 0);
noFill();
stroke(255, 255, 255);
for (int y = 0; y < height; y += 10)
{
for (int x = 0; x < width; x += 10)
{
float d = dist(x, y, mouseX, mouseY) / map(sound.getVolume(), 0, 1, 10, 100);
rect(x, y, d, d);
}
}
}
---------------------------------------------------------------------
randomLines example
--------------------------------------------------------------------
import processing.opengl.*;
SoundAnalizer sound;
void setup()
{
size(1024, 768, OPENGL);
sound = new SoundAnalizer();
background(0, 0, 0);
}
void draw()
{
noStroke();
fill(0, 0, 0, 10);
rect(0, 0, width, height);
float volume = sound.getVolume();
stroke(volume * 255);
for (int i = 0; i < volume * 100; i++)
{
line(random(width), random(height), random(width), random(height));
}
}
------------------------------------------------------------------------
spectrumEllipses
------------------------------------------------------------------------
import processing.opengl.*;
SoundAnalizer sound;
void setup()
{
size(1024, 768, OPENGL);
sound = new SoundAnalizer();
sound.learnSpeed = 1;
}
void draw()
{
background(0, 0, 0);
fill(255, 255, 255, mouseX);
noStroke();
for (int x = 0; x < width; x++)
{
float v = sound.getSpectrum(map(x, 0, width, 0, 0.4));
ellipse(x, height/2, 2 + v * 10, 2 + v * 500);
}
} |