OutOfMemoryError with minim
in
Core Library Questions
•
7 months ago
Hi guys
Thanks for your help...
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 :
- An OutOfMemoryError means that your code is either using up too much memory
- because of a bug (e.g. creating an array that's too large, or unintentionally
- loading thousands of images), or that your sketch may need more memory to run.
- If your sketch uses a lot of memory (for instance if it loads a lot of data files)
- you can increase the memory available to your sketch using the Preferences window.
- Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space
- at ddf.minim.javasound.FloatSampleBuffer.insertChannel(Unknown Source)
- at ddf.minim.javasound.FloatSampleBuffer.createChannels(Unknown Source)
- at ddf.minim.javasound.FloatSampleBuffer.init(Unknown Source)
- at ddf.minim.javasound.FloatSampleBuffer.initFromByteArray(Unknown Source)
- at ddf.minim.javasound.FloatSampleBuffer.initFromByteArray(Unknown Source)
- at ddf.minim.javasound.JSMinim.loadFloatAudio(Unknown Source)
- at ddf.minim.javasound.JSMinim.getAudioSample(Unknown Source)
- at ddf.minim.Minim.loadSample(Unknown Source)
- at ddf.minim.Minim.loadSample(Unknown Source)
- at voix_led_memoire_bouton.setup(voix_led_memoire_bouton.java:101)
- at processing.core.PApplet.handleDraw(PApplet.java:2117)
- at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
- at processing.core.PApplet.run(PApplet.java:2020)
- 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 :
- import processing.serial.*;
- import cc.arduino.*;
- import ddf.minim.*;
- Minim minim;
- AudioSample son[];
- Arduino arduino;
- int ledPin = 2;
- int btn = 3;
- int r =0;
- void setup()
- {
- minim = new Minim(this);
- String titres[] = loadStrings("titres.txt");
- son = new AudioSample[titres.length];
- for (int i=0;i<titres.length;i++){
- son[i] = minim.loadSample("musique/"+titres[i]);
- }
- arduino = new Arduino(this, Arduino.list()[0], 57600);
- arduino.pinMode(ledPin, Arduino.OUTPUT);
- arduino.pinMode(btn, Arduino.INPUT);
- }
- void draw()
- {
- String titres[] = loadStrings("titres.txt");
- if (arduino.digitalRead(btn) == Arduino.LOW)
- {
- arduino.digitalWrite(ledPin, Arduino.LOW);
- int mem = r;
- while (r==mem)
- {
- r = int(random(titres.length));
- }
- son[mem].stop();
- son[r].trigger();
- println(titres[r]);
- while(arduino.digitalRead(btn) == Arduino.LOW);
- }
- else
- {
- arduino.digitalWrite(ledPin, Arduino.HIGH);
- }
- }
- void stop() {
- String titres[] = loadStrings("titres.txt");
- for (int i=0;i<titres.length;i++){
- son[i].close();
- }
- minim.stop();
- super.stop();
- }
Thanks for your help...
1