I'm trying minim library and when I try to record the sketch with moviemaker, the result came out not as I expected. Although, it seems perfect fine while running the real-time simulation, the ".mov" is so different with the real-time one. When the bubbles fade away, it came out awkard mozaics. I don't know why this is happening. What's more, the ".mov" 's speed seems a lot faster than the real-time one, Where would I adjust these setting? At last, can I record the video with sound also, how can I get video and sound at the same time?
P.S.: in order to work, you must have one song in the folder of the sketch file. I didn't upload the mp3 file.
Code:import processing.video.*;
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.*;
Minim minim;
AudioPlayer song;
FFT fft;
ArrayList trails;
MovieMaker mm;
void setup()
{
size(1024, 800);
smooth();
frameRate(128);
mm = new MovieMaker(this, width,height,"bubbles.mov",30,MovieMaker.VIDEO, MovieMaker.LOSSLESS);
// always start Minim first!
minim = new Minim(this);
// specify 1024 for the length of the sample buffers
// the default buffer size is 1024
song = minim.loadFile("糖不厌.mp3", 1024);
song.play();
// an FFT needs to know how
// long the audio buffers it will be analyzing are
// and also needs to know
// the sample rate of the audio it is analyzing
fft = new FFT(song.bufferSize(), song.sampleRate());
trails = new ArrayList();
}
void draw()
{
background(0);
//spectrum
// first perform a forward fft on one of song's buffers
// I'm using the mix buffer
// but you can use any one you like
fft.forward(song.mix);
//stroke(255, 0, 0, 128);
//strokeWeight(5);
// draw the spectrum as a series of vertical lines
// I multiple the value of getBand by 4
// so that we can see the lines better
for(int i = 0; i < (fft.specSize()-1)*2; i+=1024/(fft.specSize()-1))
{
//line(i, height, i, height - fft.getBand(i)*5);
if(dist(i,height, i, height - fft.getBand(i)*5)>height/20){
Circle c = new Circle(int(random(0,width)), int(random(0,height)), random(10,50), random(0,255));
c.drawOneCircle();
}
}
//trails
for(int j = 0; j < trails.size(); j++){
Trail t = (Trail) trails.get(j);
t.update();
t.drawOneCircle();
}
//waveform
stroke(255);
strokeWeight(0);
// we draw the waveform by connecting neighbor values with a line
// we multiply each of the values by 50
// because the values in the buffers are normalized
// this means that they have values between -1 and 1.
// If we don't scale them up our waveform
// will look more or less like a straight line.
for(int i = 0; i < song.bufferSize() - 1; i++)
{
// line(i, height/2 - 50 + song.left.get(i)*50, i+1, height/2 - 50 + song.left.get(i+1)*50);
// line(i, height/2 + 50 + song.right.get(i)*50, i+1, height/2 + 50 + song.right.get(i+1)*50);
// line(i, height/2 + song.mix.get(i)*50, i +1, height/2 + song.mix.get(i+1)*50);
}
mm.addFrame();
}
void stop()
{
song.close();
minim.stop();
super.stop();
}
void keyPressed(){
if(key == 'f'){
mm.finish();
println("movie saved");
}
if ( key == 'p' ) song.play();
}
class Trail{
//variable
int posx;
int posy;
float radius;
float magnatude;
//constructor
Trail(int _posx, int _posy, float _radius, float _magnatude){
posx = _posx;
posy = _posy;
radius = _radius;
magnatude = 255;
}
//method
void update(){
magnatude-=30;
if(magnatude < 0){
trails.remove(this);
}
}
void drawOneCircle(){
noStroke();
fill(magnatude,magnatude,magnatude,10);
ellipse(posx,posy,radius*4,radius*4);
fill(magnatude,magnatude,magnatude,10);
ellipse(posx,posy,radius*3,radius*3);
fill(magnatude,magnatude,magnatude,10);
ellipse(posx,posy,radius*2.5,radius*2.5);
//stroke(0,60);
fill(magnatude);
ellipse(posx,posy,radius*2,radius*2);
//color
// noStroke();
// for(int k = 1; k < 30; k++){
// fill(random(0,magnatude),random(0,magnatude),random(0,magnatude),20);
// arc(posx, posy, radius*2, radius*2, random(0,2*PI), random(0,2*PI));
// }
// for(float i = 0.0; i < 2.0*PI; i+=0.5-radius/200){
// stroke(0,random(0,100));
// line(posx,posy,posx+sin(i)*radius,posy+cos(i)*radius);
// }
}
}
class Circle{
//variable
int posx;
int posy;
float radius;
float magnatude;
//constructor
Circle(int _posx, int _posy, float _radius, float _magnatude){
posx = _posx;
posy = _posy;
radius = _radius;
magnatude = _magnatude;
}
//method
void drawOneCircle(){
noStroke();
fill(magnatude,magnatude,magnatude,10);
ellipse(posx,posy,radius*4,radius*4);
fill(magnatude,magnatude,magnatude,10);
ellipse(posx,posy,radius*3,radius*3);
fill(magnatude,magnatude,magnatude,10);
ellipse(posx,posy,radius*2.5,radius*2.5);
//stroke(0,60);
fill(255);
ellipse(posx,posy,radius*2,radius*2);
//color
noStroke();
for(int k = 1; k < 30; k++){
fill(random(0,magnatude),random(0,magnatude),random(0,magnatude),20);
arc(posx, posy, radius*2, radius*2, random(0,2*PI), random(0,2*PI));
}
// for(float i = 0.0; i < 2.0*PI; i+=0.5-radius/200){
// stroke(0,random(0,100));
// line(posx,posy,posx+sin(i)*radius,posy+cos(i)*radius);
// }
trails.add(new Trail(posx, posy, radius, magnatude));
}
}