We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Audio Analysis - Windowed Averaging/Memory Problem
Page Index Toggle Pages: 1
Audio Analysis - Windowed Averaging/Memory Problem (Read 522 times)
Audio Analysis - Windowed Averaging/Memory Problem
Jun 15th, 2007, 8:54am
 
Hi all,

I've split my audio into 8 spectrum bands and am taking their average every 60 frames (2 seconds).

I then want to record these 8 vaules changing in a simple graph.

The program works fine when loading in a 20MB wav file but I am getting a -

java.lang.RuntimeException: java.lang.OutOfMemoryError

with the 70MB file I want to use.

Is my computer simply not up to the task or is there a more memory effecient way to tackle this problem. I am working from an audiofile rather than an audiostream so that the results I get are constant - so the audio player and computer volume level aren't an issue.

Thanks a lot

Nathan

--------------------------------------------------------

import processing.opengl.*;
import krister.Ess.*;
import moviemaker.*;

int bufferSize;
int steps;
float limitDiff;
int numAverages=0;
float myDamp=.1f;
float maxLimit,minLimit;

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;

float x=0;

float[] oldy = new float[7];
float[] av = new float[7];
float[] realav= new float[7];

int framecheck = 60;
int framecheckconstant = 60;

void setup() {
 size(700,500,OPENGL);
 colorMode(HSB, 7);
 background(7);
 //strokeWeight(2);
 smooth();

 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.aif"));
 fft = new FFT(16);
 fft.equalizer(true);
 fft.limits();

 minLimit=.005;
 maxLimit=.05;
 fft.limits(minLimit,maxLimit);
 fft.damp(myDamp);
 //myFFT.averages(numAverages);
 //steps=bufferSize/numAverages;
 limitDiff=maxLimit-minLimit;

 for(int i=0; i<7;i++){
   oldy[i] = i;
   av[i] = 0;
   realav[i] = 0;
 }
}

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.finishMovie();
   exit();
 }
 fft.getSpectrum(chn.samples, pos);
}

void render() {
 for(int i=0;i<7;i++){    
   av[i] = av[i]+fft.spectrum[i];  
 }

 if (frameCount == framecheck){
   x=x+3;
   strokeWeight(3);
   for(int i=0; i<7; i++){
     oldy[i]=realav[i];    
     realav[i] = av[i]/50;
     stroke(0,5,4,6);
     line(x, realav[i]*500, x-3, oldy[i]*500);  
     av[i]=0;    
   }    

   for(int i =0; i <height; i= i +50){
     stroke(0,0,6);
     strokeWeight(1);
     line(0,i, width, i);
   }
   framecheck = framecheck+50;    
 }  
}

void store() {
 if (outputType==OUTPUT_TYPE_MOVIE) {
   loadPixels();
   mm.addFrame(pixels,width,height);
 }
 else {
   saveFrame("out\\img_"+nf(frameNumber,6)+".jpg");
 }
}

void advance() {
 frameNumber++;
}

void keyPressed(){
 if (myDamp>1) myDamp=1;
 else if(myDamp<0) myDamp=0;
 fft.damp(myDamp);  
}
Re: Audio Analysis - Windowed Averaging/Memory Pro
Reply #1 - Jun 15th, 2007, 4:53pm
 
I expect you just need to increase the amount of memory that Processing will use. It's in File > Preferences.
Re: Audio Analysis - Windowed Averaging/Memory Pro
Reply #2 - Jun 18th, 2007, 8:02am
 
Wow, that was simple, and a little embarassing. Thanks for the tip.
Page Index Toggle Pages: 1