一个简单的音频分析
processing吧
全部回复
仅看楼主
level 5
墨镜L阿大 楼主
如下
ParticleSystem ps;
import ddf.minim.*;
AudioPlayer player;
Minim minim;
public PVector Bvel;
float tempLevel,AvgN,AvgP;
public float[] AvgLevel =new float[104];
//float[] AvgEx =new float[104];
void setup() {
frameRate(70);
size(640,360);
AvgLevel[0] = 0;
smooth();
minim = new Minim(this);
player = minim.loadFile("music.mp3", 1024);
player.play();
ps = new ParticleSystem(new PVector(width/2,50));
AvgN = 0;
}
void draw() {
background(120);
AvgP = AvgN;
AvgN = 0;
tempLevel = player.right.level();
for (int i =1 ; i<=103 ; i++){
AvgLevel[i]=AvgLevel[i-1];
}
AvgLevel[103] = tempLevel;
for (int j =0 ; j<=103 ; j++){
AvgN += AvgLevel[j];
}
cauAvg();
ps.addParticle(width*0.6,300-height*sqrt(sq(player.right.level()))/4);
ps.update();
ps.display();
}
public float AvgD;
void cauAvg(){
AvgD = AvgN-AvgP;
Bvel = new PVector(random(-2,-3),AvgD);
}
2016年05月05日 04点05分 1
level 5
墨镜L阿大 楼主
public PVector vy;
class Particle {
PVector location;
PVector velocity;
PVector acceleration;
PVector velocity0;
PVector vy0,y0,y1;
float lifespan;
// int mod; //mod
float r = random(2,3);
boolean highlight;
Particle(float x, float y) {
acceleration = new PVector(0.05,0);
velocity = new PVector(Bvel.x,Bvel.y*10);
vy = new PVector (0,0);
y0 = new PVector (0,-1);
y1 = new PVector (0,-10);
//velocity = new PVector(random(-3, -2), random(-1, 0));
location = new PVector(x, y);
lifespan = 255.0;
if (AvgLevel[103]>0.5){
vy.add(y0);
}
vy0 = new PVector(vy.x,vy.y);
if (AvgD >0.3){
location.add(y1);
}
}
void run() {
update();
display();
}
void applyForce(PVector f) {
acceleration.add(f);
}
void update() {
location.add(vy0);
velocity.add(acceleration);
location.add(velocity);
acceleration.mult(0);
lifespan -= 2.0;
}
void display() {
noStroke();
strokeWeight(2);
fill(127,0,0, lifespan);
//float AvgDc = map(AvgD,0,1,0,95);
ellipse(location.x, location.y, r*2, r*2);
}
boolean isDead() {
if (lifespan < 0.0) {
return true;
}
else {
return false;
}
}
}
2016年05月05日 04点05分 2
level 5
墨镜L阿大 楼主
class ParticleSystem {
ArrayList<Particle> particles;
ParticleSystem(PVector location) {
particles = new ArrayList<Particle>();
}
void addParticle(float x, float y) {
particles.add(new Particle(x, y));
}
void display() {
for (Particle p : particles) {
p.display();
}
}
void update() {
for (int i = particles.size()-1; i >= 0; i--) {
Particle p = particles.get(i);
p.update();
if (p.isDead()) {
particles.remove(i);
}
}
}
}
2016年05月05日 04点05分 3
level 5
墨镜L阿大 楼主
以上 因为是简单的 所以没有添加太多的东西
有啥想说的留言吧
2016年05月05日 04点05分 4
level 5
墨镜L阿大 楼主
逻辑有点乱 也没有标注 用的PVector 还有level
2016年05月05日 04点05分 5
level 1
我也 刚做这个 但是运行之后 老显示 The function detectSize() does not exist谢谢
2016年05月05日 05点05分 6
分割是新建一个标签 音乐放在同目录下或者/data下面
2016年05月05日 06点05分
有很多错误官方根本没说 因为确实没有汉化的 所以你需要点时间去习惯哪些错误 大概要2小时 自己写3次就好了
2016年05月05日 06点05分
我能 加你好友吗,我刚玩这个 这个原因 我一直弄不懂我扣1685031317谢谢
2016年05月06日 04点05分
回复 墨镜L阿大 :这个data是要自己建吗 我不明白 音乐应该放在哪个文件下
2016年05月06日 05点05分
level 1
我的想用arduino 和precessing的音乐灯 但是刚玩 不太懂
2016年05月05日 05点05分 7
processing转arduino只需要把draw改成loop 其他指示命令就是把ellipse改了 这些你自己改吧 因为我也需要找工作················
2016年05月05日 06点05分
还有 音乐等不值得去试了 因为确实算法太简单了 你去看看c写的 很多 自己能转过来 你就可以不用问任何问题了 除非你要考研
2016年05月05日 06点05分
level 5
墨镜L阿大 楼主
ParticleSystem ps;
import ddf.minim.*;
AudioPlayer player;
Minim minim;
public PVector Bvel;
public float AvgN1;
public boolean needadd=false;
float tempLevel,AvgN,AvgP;
public float[] AvgLevel =new float[104];
//float[] AvgEx =new float[104];
void setup() {
frameRate(70);
size(640,360);
AvgLevel[0] = 0;
smooth();
minim = new Minim(this);
player = minim.loadFile("music.mp3", 1024);
player.play();
ps = new ParticleSystem(new PVector(width/2,50));
AvgN = 0;
}
void draw() {
background(120);
AvgP = AvgN;
AvgN = 0;
AvgN1 = 0;
tempLevel = player.right.level();
for (int i =1 ; i<=103 ; i++){
AvgLevel[i]=AvgLevel[i-1];
}
AvgLevel[103] = tempLevel;
for (int j =0 ; j<=103 ; j++){
AvgN += AvgLevel[j];
if(j>87){
AvgN1 += AvgLevel[j];
}
}
float v0y = height*sqrt(sq(player.right.level()))/4;
cauAvg();
if (v0y>30){
v0y = v0y/1.2;
}
ps.addParticle(width*0.6,300-v0y-morehigh);
ps.update();
ps.display();
aspan-=1;
if (morehigh<40){
needadd = true;
}else{
needadd = false;
}
text(aspannum,20,20);
text(morehigh,20,30);
if (morehigh>0){
morehigh -=0.01;
if (morehigh>25){
morehigh -=0.03;
}
}
}
public float AvgD;
void cauAvg(){
AvgD = AvgN-AvgP;
Bvel = new PVector(random(-2,-3),AvgD);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
标签(particle)
public PVector vy;
public int aspannum = 0;
public float morehigh;
public float aspan=0;
class Particle {
PVector location;
PVector velocity;
PVector acceleration;
PVector velocity0;
PVector vy0,v1,y0,y1;
PVector damp = new PVector(0,-0.01);
PVector v0 = new PVector(Bvel.x,random(-0.1,0.1));
float c = random(.1,.2);
int dampspan = 70,toy1 = 35;
float lifespan;
float r = random(2,3);
boolean hady1 = true;
Particle(float x, float y) {
acceleration = new PVector(0.5+Bvel.y,0);
if (Bvel.y>1.5){
v1 = new PVector(0,Bvel.y*7);
}else{
v1 = new PVector(0,Bvel.y*10);
}
if (y>0.6*height){
if (AvgN1>0.2){
if(needadd){
morehigh += c;
aspan+=1.2;
aspannum+=1;
}
}
}
location = new PVector(x, y);
vy = new PVector (0,0);
y0 = new PVector (0,-1);
y1 = new PVector (0,-10);
velocity = new PVector(Bvel.x, random(-0.1, 0.1));
location = new PVector(x, y);
lifespan = 560.0;
if (AvgLevel[103]>0.5){
vy.add(y0);
}
vy0 = new PVector(vy.x,vy.y);
if (AvgD >0.3){
location.add(y1);
}
}
void run() {
update();
display();
}
void applyForce(PVector f) {
acceleration.add(f);
}
void update() {
if (hady1 & toy1<=0){
velocity.add(v1);
hady1 = false;
}
if (dampspan<=0 ){
if( velocity.y>0.3){
needdamp();
}
}
accy0();
location.add(vy0);
velocity.add(acceleration);
location.add(velocity);
acceleration.mult(0);
if(accspan){
location.sub(acc0);
}
lifespan -= 2.0;
dampspan -= 1;
toy1 -= 1;
}
void display() {
noStroke();
strokeWeight(2);
float ki = map(lifespan,0,560,0,255);
fill(0,0,0,ki);
ellipse(location.x, location.y, r*2, r*2);
}
boolean accspan = false;
PVector acc0;
void accy0(){
if (velocity.y<-0.03){
accspan = true;
//lifespan+=30;
}else{
accspan =false;
}
acc0 = new PVector (0,velocity.y*-random(0.5,1));
}
boolean isDead() {
if (lifespan < 0.0) {
return true;
}
else {
return false;
}
}
void needdamp(){
velocity.add(damp);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
标签(particleSystem)
class ParticleSystem {
ArrayList<Particle> particles;
ParticleSystem(PVector location) {
particles = new ArrayList<Particle>();
}
void addParticle(float x, float y) {
particles.add(new Particle(x, y));
}
void display() {
for (Particle p : particles) {
p.display();
}
}
void update() {
for (int i = particles.size()-1; i >= 0; i--) {
Particle p = particles.get(i);
p.update();
if (p.isDead()) {
particles.remove(i);
}
}
}
}
记得新建 标签 更新了 如果有很多的更新 我会马上发 但是参数我不一定调试 如果参数调试了 有谁愿意分享 我会非常感谢的
待会儿发出修改了变量名称的源文件 因为可能过两天我都会不记得了
虽然只是简单的PVector的建模 但是很久没用了 所以很慢
2016年05月05日 08点05分 8
1