FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Sound
(Moderators: pitaru, REAS)
   possible memory issue with loading samples
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: possible memory issue with loading samples  (Read 445 times)
ashtonium

kravdraard WWW Email
possible memory issue with loading samples
« on: Apr 17th, 2004, 6:51pm »

i am currently integrating Sonia's sample control into a graphical program that i have been developing (nothing like good audio to help engage an audience in the visual components of a piece)
 
what i am doing is grabbing eight random sound files (each rather small) into an array of sample objects.  Then allowing the user to grab another random eight into the array (presumably replacing the old samples).  The problem occurs when this happens multiple times, the graphics gradually get choppy and eventualy the environment locks up.  My guess is that the replaced samples are still taking up space in memory, and the program is gradually consuming the available RAM.
 
this is the method i am using to load and re-load the random audio files into the sample array:
Code:

void resetAudio() {
  for(int i=0; i<8; i++){
    int aNum = int(random(144));
    mySampleArray[i] = new Sample("audio/"+aNum+".aif");
  }
}

Is there some way to unload a sample that i have overlooked?  Or am i simply loading the samples in an inappropriate manner?  Has anyone else experienced similar memory issues?
 
-kevin
 
pitaru


WWW Email
Re: possible memory issue with loading samples
« Reply #1 on: Apr 17th, 2004, 10:36pm »

Hi Kevin,  
 
its definitely a bug - i should implement better mem-control over deleting unused samples, as well as overwriting samples with existing names (such as in your case).  
 
lets see how quick i can fix this. in the meantime, maybe you can go around it by using the mySample.write() command - which writes an array of floats/shorts into a given sample (see reference).
 
-amit
 
ashtonium

kravdraard WWW Email
Re: possible memory issue with loading samples
« Reply #2 on: Apr 24th, 2004, 8:33pm »

heya, got distracted by other responsibilities (bleh) but i took a look at mySample.write() and the relevant documentation and couldn't quite figure out how to get a workaround using it (my own ignorance i'm sure).  
My dirty solution for now was to compile multiple samples into one large sample and just loop sections of it.
 
saw in the other problem thread that you mentioned something about some memory-leakage fixes?  how's that going? [anxious antisipation]  
-kevin
 
pitaru


WWW Email
Re: possible memory issue with loading samples
« Reply #3 on: Apr 24th, 2004, 9:30pm »

Hey there,  
 
i've just uploaded the 2.7 version of sonia at http://pitaru.com/sonia  
 
in this version, i've added Sample.delete(); which forces java to free up the resources.  
 
I think this should solve the problem you've discovered (thanks!) - let me know.
 
Here's a modification to your code:  
 
void resetAudio() {  
  for(int i=0; i<8; i++){  
    int aNum = int(random(144));  
    mySampleArray[i].delete();
    mySampleArray[i] = new Sample("audio/"+aNum+".aif");  
  }  
}  
 
 
make sure to first initialize the samples outside of this routine (maybe in setup()), as the delete() command only works on existing samples.
 
cheers,
-amit
« Last Edit: Apr 24th, 2004, 9:31pm by pitaru »  
ashtonium

kravdraard WWW Email
Re: possible memory issue with loading samples
« Reply #4 on: Apr 24th, 2004, 11:35pm »

looks like the memory issue is taken care of!  I can continuously re-load samples into the array and suffer no degrading performance at all.  much thanks!  
 
unfortunately, however, i am now getting an error that i wasn't before.  My guess is that it is a result of a different part of my code trying to access a sample in between the "delete()" and the "new Sample()" call, not sure though... (I hope that's all it is.) I'm going to try replicating the error in some simpler code.
 
btw: the Sonia.setMaxSamples(int); looks like it has great potential as well, i'll have to play with that and see if it can fix my problem.  (am i correct in assuming that sample.delete() is not needed to clear up a sample's space in memory when a maximum number of samples is set?)
 
thanks again for the fixes, -kevin
 
ashtonium

kravdraard WWW Email
Re: possible memory issue with loading samples
« Reply #5 on: Apr 24th, 2004, 11:58pm »

yes, looks like my problem is fixed by setting Sonia.setMaxSamples(int) in setup() and removing sample.delete() from my resetAudio() method.
 
Pages: 1 

« Previous topic | Next topic »