triscuit
YaBB Newbies
Offline
Posts: 41
Simple Question: ESS Offline Render
Apr 30th , 2008, 8:34pm
I'm trying to modify code from this thread: http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Sound;action=display;num=1174169711 I want to be able to preview what is going on without rendering it down to images. I need something that says something like OUTPUT_TYPE_MUSIC. This seems really simple, but I just can't figure it out. /** FFTOfflineRenderer.pde May 2007 Dave Bollinger to demonstrate use of non-real-time fft analysis and rendering putting ESS, OpenGL and MovieMaker all together to make sure they all get along */ import processing.opengl.*; import krister.Ess.*; import processing.video.*; static final int OUTPUT_TYPE_IMAGE = 0; static final int OUTPUT_TYPE_MOVIE = 1; int outputType = OUTPUT_TYPE_IMAGE; // change this as desired MovieMaker mm; AudioChannel chn; FFT fft; int frameNumber = 0; int framesPerSecond = 30; void setup() { size(320,240,OPENGL); Ess.start(this); if (outputType==OUTPUT_TYPE_MOVIE) mm = new MovieMaker(this,width,height,"output.mov",MovieMaker.RAW,MovieMaker.HIGH,framesP erSecond); chn = new AudioChannel(dataPath("music.wav")); fft = new FFT(512); fft.limits(); } public void stop() { Ess.stop(); super.stop(); } void draw() { progress(); analyze(); render(); store(); advance(); } void progress() { if ((frameNumber%100) == 0) { println("Working on frame number " + frameNumber); } } void analyze() { int pos = (int)(frameNumber * chn.sampleRate / framesPerSecond); if (pos >= chn.size) { if (outputType==OUTPUT_TYPE_MOVIE) mm.finish(); exit(); } fft.getSpectrum(chn.samples, pos); } void render() { background(255); fill(0); noStroke(); for (int i=0; i<256; i++) { float sp = fft.spectrum[i]; rect(32+i,230,1,-sp*220); } // (optional) pretend the rendering took a long time just as proof of concept... //try { Thread.sleep(100); } catch(InterruptedException e) {} } void store() { if (outputType==OUTPUT_TYPE_MOVIE) { loadPixels(); mm.addFrame(pixels,width,height); } else { saveFrame("out\\img_"+nf(frameNumber,6)+".jpg"); } } void advance() { frameNumber++; }