jzellis
YaBB Newbies
Offline
Posts: 16
NV
Synchronizing generative video + audio
Mar 17th , 2007, 10:15pm
Hi, folks. So I've written a Flight404 knockoff sketch that uses a traer particle system and ess to generate a particle cloud that "flashes" when the audio input (either from mic or from an MP3) goes over a threshold. Pretty basic stuff for Processing, I gather, but this is only my first week messing with it. So I fired up Air's "Redhead Girl" from their new album and tried rendering out the animation generated from it (with plans to sync it up in iMovie or After Effects or whatever afterwards). This is where I run into a problem: when I use saveFrame() the animation bogs down, goes below 30fps, and so it's not actually rendering synced with the audio. This seems wrong to me, as I'm running an Intel Macbook Pro with 1GB of RAM, and using OpenGL as my renderer. Can anybody suggest how I could optimize my code to make this work? Code is below: --------------- //import processing.opengl.*; import traer.physics.*; import krister.Ess.*; AudioFile myInput; AudioStream myStream; FFT myFFT; float volume; float avgVol; ParticleSystem ps; Particle[] particles; Particle audioController; Attraction[] attract; int numParticles; int i; int offset; PImage particlePic; PImage starfield; int bgColorChange; int maxpal = 512; int numpal = 0; void setup() { size(720,480,P3D); frameRate(30); particlePic = loadImage("star.gif"); particlePic.mask(particlePic); starfield = loadImage("bg.gif"); Ess.start(this); myInput=new AudioFile("redhead_girl.mp3",0,Ess.READ); myStream = new AudioStream(256*1024); myStream.sampleRate(myInput.sampleRate); myFFT=new FFT(8); myStream.start(); numParticles = 100; ps = new ParticleSystem(0,1.5); particles = new Particle[numParticles]; attract = new Attraction[numParticles]; audioController = ps.makeParticle(100,width /2, height / 2,0); audioController.makeFixed(); audioController.moveTo(width / 2, height / 2,0); for(i = 0; i < numParticles; i++){ particles[i] = ps.makeParticle(300,random(0,width) - (particlePic.width / 2),random(0,height)- (particlePic.height / 2),0); attract[i] = ps.makeAttraction(audioController,particles[i],50,500); } noStroke(); offset = 8; background(0); } void draw() { ps.tick(); myFFT.smooth = true; //myFFT.damp(0.001); noCursor(); background(0); image(starfield,0,0); avgVol = myFFT.getLevel(myStream); volume = round(avgVol * 10); audioController.moveTo(mouseX,mouseY,0); tint(255); image(particlePic, audioController.position().x() - (particlePic.width / 2),audioController.position().y() - (particlePic.height / 2)); stroke(255,50); noStroke(); for(i=0; i< numParticles; i++){ tint(255, 100); float sizeRange = max(20,volume * 40); if(mousePressed | keyPressed | avgVol > 0.5){ attract[i].setStrength(-500); sizeRange = sizeRange + 25; } else{ attract[i].setStrength(400); } image(particlePic, particles[i].position().x() - (sizeRange / 2),particles[i].position().y() - (sizeRange / 2),sizeRange,sizeRange); } //saveFrame("redheadgirl-#####.jpg"); } void audioStreamWrite(AudioStream theStream) { // read the next chunk int samplesRead=myInput.read(myStream); if (samplesRead==0) { // start over myInput.close(); samplesRead=myInput.read(myStream); } } public void stop() { Ess.stop(); super.stop(); } ---------------