Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

OutOfMemoryError with minim

$
0
0
Hi guys

I've made a sketch to launch some mp3 files with minim and a button on my arduino. There is a .txt containing sond names, and the program loads those names to play mp3 in a random way. It's simple and it works, but if I put more than 2, 3 mp3, I get this error : 
  1. An OutOfMemoryError means that your code is either using up too much memory
  2. because of a bug (e.g. creating an array that's too large, or unintentionally
  3. loading thousands of images), or that your sketch may need more memory to run.
  4. If your sketch uses a lot of memory (for instance if it loads a lot of data files)
  5. you can increase the memory available to your sketch using the Preferences window.
  6. Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space
  7. at ddf.minim.javasound.FloatSampleBuffer.insertChannel(Unknown Source)
  8. at ddf.minim.javasound.FloatSampleBuffer.createChannels(Unknown Source)
  9. at ddf.minim.javasound.FloatSampleBuffer.init(Unknown Source)
  10. at ddf.minim.javasound.FloatSampleBuffer.initFromByteArray(Unknown Source)
  11. at ddf.minim.javasound.FloatSampleBuffer.initFromByteArray(Unknown Source)
  12. at ddf.minim.javasound.JSMinim.loadFloatAudio(Unknown Source)
  13. at ddf.minim.javasound.JSMinim.getAudioSample(Unknown Source)
  14. at ddf.minim.Minim.loadSample(Unknown Source)
  15. at ddf.minim.Minim.loadSample(Unknown Source)
  16. at voix_led_memoire_bouton.setup(voix_led_memoire_bouton.java:101)
  17. at processing.core.PApplet.handleDraw(PApplet.java:2117)
  18. at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
  19. at processing.core.PApplet.run(PApplet.java:2020)
  20. at java.lang.Thread.run(Thread.java:662)


I increased the maximum available memory but still can't load more than 4,5 with 512 Mo. Here is my code :

  1. import processing.serial.*;
  2. import cc.arduino.*;
  3. import ddf.minim.*;

  4. Minim minim;
  5. AudioSample son[];



  6. Arduino arduino;
  7. int ledPin = 2;
  8. int btn = 3;
  9. int r =0;


  10. void setup()
  11. {

  12.   minim = new Minim(this);
  13.   String titres[] = loadStrings("titres.txt");
  14.   
  15.   son = new AudioSample[titres.length];
  16.   for (int i=0;i<titres.length;i++){
  17.   son[i] = minim.loadSample("musique/"+titres[i]);
  18.   }
  19.   arduino = new Arduino(this, Arduino.list()[0], 57600);
  20.   arduino.pinMode(ledPin, Arduino.OUTPUT);
  21.   arduino.pinMode(btn, Arduino.INPUT);
  22.   
  23. }

  24. void draw()
  25. {  
  26.   String titres[] = loadStrings("titres.txt");
  27.   if (arduino.digitalRead(btn) == Arduino.LOW)
  28.   {
  29.   arduino.digitalWrite(ledPin, Arduino.LOW);
  30.     
  31.     int mem = r;
  32.     while (r==mem)
  33.     {
  34.     r = int(random(titres.length));
  35.     }
  36.     
  37.   son[mem].stop();
  38.   son[r].trigger();
  39.   println(titres[r]);

  40.   while(arduino.digitalRead(btn) == Arduino.LOW);
  41.   }
  42.   else 
  43.   {
  44.   arduino.digitalWrite(ledPin, Arduino.HIGH);
  45.   }  
  46. }


  47. void stop() {
  48.   String titres[] = loadStrings("titres.txt");
  49.   for (int i=0;i<titres.length;i++){
  50.   son[i].close();
  51.   }
  52.   minim.stop();
  53.   super.stop();
  54. }
  55.  

Thanks for your help...


Viewing all articles
Browse latest Browse all 1768

Trending Articles