我正在做Processing 3中的一个项目,其中视觉效果是通过歌曲的振幅进行调制的。然而,我想更进一步。我希望能够播放任何歌曲,甚至可以让乐队在麦克风的房间里演奏,并在播放时让我的视觉效果得到响应。现在,我必须告诉计算机使用Sketch文件夹中的哪首歌曲,但显然这不是我想要做的。
最终目标是将我的视觉效果投射到俱乐部背景下的墙上。为了避免拾取人群的噪音,我认为将信号从DJ电话亭发送到计算机(可能使用音频接口)是有意义的。我不知道这对于编写代码是否一定很重要,但这就是我的想法。(Ik这可能与前面提到的band编程想法有点不同…)
无论如何,如果任何人有任何关于如何做到这一点的好例子或信息,将不胜感激。我已经附上了我的代码截图现在。最后,我会让视觉效果变得更复杂,但您已经明白了。
import processing.sound.*;
SoundFile sample;
Amplitude rms;
float smoothingFactor = 0.06;
float sum;
float x, y;
float xStep = 40;
float yStep = 200;
float a, a_;
int num = 400;
void setup(){
size(1400,1000);
sample = new SoundFile(this, "prettylights.mp3"); //to run code, load an audio file here
sample.loop();
rms = new Amplitude(this);
rms.input(sample);
}
void draw(){
background(20,20,30);
strokeCap(CORNER);
strokeWeight(xStep);
sum += (rms.analyze() - sum) * smoothingFactor;
float rms_scaled = sum * (height/2) * 3;
int n=0;
while (n<num) {
stroke(255-255*cos(radians(a)),25,25,230-255*sin(radians(a)));
line(x, y, x, y+yStep);
//line(x, y,rms_scaled, rms_scaled);
x+=xStep;
if (x>width){
x=xStep/2;
y+=yStep;
}
if (y>=height){
y=0;
a=rms_scaled;
//a=0;
}
n++;
a+=a_;
}
a_+=0.1;
}发布于 2020-12-20 18:39:28
我想通了!我只需要使用AudioIn类。
import processing.sound.*;
AudioIn in;
void setup() {
size(640, 360);
background(255);
// Create the Input stream
in = new AudioIn(this, 0);
in.play();
}
void draw() {
}https://stackoverflow.com/questions/65281178
复制相似问题