【发布时间】:2018-07-01 13:04:46
【问题描述】:
我在停止播放字符串后无法在画布上保留绘图。
所以我将它映射为从我的麦克风中拾取一个频率,当它听到该频率时,它会在画布上画一条线。唯一的问题是停频后就消失了。
如何在画布上保留线条,然后用其他频率绘制更多线条?
代码如下:
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioInput in;
FFT fft;
float highestAmp=0,freq,frequency;
float amplitude;
int x = 0;
int y = 0;
int p = x;
int o = y;
void setup(){
size(512, 200);
background(0);
// initialize Minim and catching the output
minim = new Minim(this);
in = minim.getLineIn(Minim.MONO, 4096*8, 44100);
fft = new FFT(in.left.size(), 44100);
}
void draw() {
highestAmp=0;
amplitude=0;
frequency = 0;
fft.forward(in.left);
x = constrain(x,0,width);
y = constrain(y,0,height);
//searching from 0Hz to 20000Hz. getting the band, and from the band the frequency
for(int i = 0; i < 20000; i++) {
amplitude = fft.getFreq(i);
if (amplitude > highestAmp){
highestAmp = amplitude;
frequency = i;
}
}
//write the frequency on the screen
fill(255);
background(0);
text(frequency,200,100);
text(amplitude,400,100);
if (frequency > 340.00 & frequency < 360){
stroke(28,125,85);
line(x, y, p, o);
x++;
y++;
}
if (frequency > 320.00 & frequency < 340){
stroke(255,0,166);
line(x, y, p, o);
x++;
y--;
}
}
【问题讨论】:
标签: java audio canvas processing frequency