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 & HelpSound,  Music Libraries › ESS - reducing processer load
Page Index Toggle Pages: 1
ESS - reducing processer load? (Read 1161 times)
ESS - reducing processer load?
Jan 19th, 2008, 4:36am
 
Okay, so I have:

/* import & load audio library */
import krister.Ess.*;
AudioChannel mySound;
FFT myFFT;
int bands = 256; // no of FFT bands
& then:

void mouseReleased() {
 
 if (shapetype == 3) {
   Ess.start(this);
   mySound = new AudioChannel("dog.aif");
   mySound.play(Ess.FOREVER);
 }
 
 if (shapetype == 2) {
   Ess.start(this);
   mySound = new AudioChannel("plane.aif");
   mySound.play(Ess.FOREVER);
 }

 if (shapetype == 1) {
   Ess.start(this);
   mySound = new AudioChannel("cars.aif");
   mySound.play(Ess.FOREVER);
 }

 if (shapetype == 0) {
   Ess.start(this);
   mySound = new AudioChannel("crowd.aif");
   mySound.play(Ess.FOREVER);
 }  
}

Although running this is causing massive strain on the sketch and causing it to crash extremely frequently (see below). Would anyone offer any advice as to reducing this - pre-loading the sounds into a buffer, perhaps? How would I go about this?



Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space
at krister.Ess.AudioChannel.loadSound(AudioChannel.java:263)
Re: ESS - reducing processer load?
Reply #1 - Jan 19th, 2008, 5:54am
 
Why would you load a sound file every mouseReleased()? Why not do


Code:

// declare all your sounds
AudioChannel dog;
AudioChannel plane;
//...

// write a loading function that pre-loads everything
void loadSounds(){
dog = new AudioChannel("dog.aif");
plane = new AudioChannel("plane.aif");
//...
}

// on mouse released...
void mouseReleased(){
if(shapetype == 3)
dog.play(Ess.FOREVER);
if(shapetype == 2)
plane.play(Ess.FOREVER);
}



By the way you shouldn't call Ess.start(this) every click. Just do this once on setup().
Re: ESS - reducing processer load?
Reply #2 - Jan 19th, 2008, 11:56am
 
// declare sounds
AudioChannel dog;
AudioChannel plane;
AudioChannel cars;
AudioChannel crowd;

///////////////////////////////////////

void loadSounds() {
 dog = new AudioChannel("dog.aif");
 plane = new AudioChannel("plane.aif");
 cars = new AudioChannel("cars.aif");
 crowd = new AudioChannel("crowd.aif");
}

void mouseReleased() {  
 if (shapetype == 3) {
   dog.play(Ess.FOREVER);
 }
 
 if (shapetype == 2) {
   plane.play(Ess.FOREVER);
 }

 if (shapetype == 1) {
   cars.play(Ess.FOREVER);
 }

 if (shapetype == 0) {
   crowd.play(Ess.FOREVER);
 }  
}


It's compiling just fine - but I'm still getting a NullPointerException when I request playback (by clicking the button).
Re: ESS - reducing processer load?
Reply #3 - Jan 19th, 2008, 12:56pm
 
Let's see the rest of your code. I bet you're not instantiating Ess or setting it up properly in setup().
Re: ESS - reducing processer load?
Reply #4 - Jan 20th, 2008, 5:46am
 
I took your previous advice and moved it to setup, so it looks like this:

void setup() {
 size(850,800);
 background(#333333);
 smooth();
 Ess.start(this);
}
Re: ESS - reducing processer load?
Reply #5 - Jan 20th, 2008, 11:09am
 
A really silly question probably, but you are running loadSounds() in setup as well aren't you?
Re: ESS - reducing processer load?
Reply #6 - Jan 20th, 2008, 2:58pm
 
I'm running loadSounds right before the mouseReleased thats starting the sounds after drawing a shape - does it need a reference in setup also?
Re: ESS - reducing processer load?
Reply #7 - Jan 20th, 2008, 4:29pm
 
loadSounds should be in setup only or else you are still (re)loading files every mouseReleased wich causes your program to stall unnecessarily. Generally you want to avoid loading anything while the program is running, so do that in setup()

fb
Re: ESS - reducing processer load?
Reply #8 - Jan 20th, 2008, 5:19pm
 
Aha, got it! Thanks everyone Smiley
Page Index Toggle Pages: 1