Hi,
I've got a related question. I'm trying to write a java app that lets users jump to different locations in a long audio file. I don't care so much about speed for now; it's no problem if the app hangs for a few seconds between each seek operation. My problem is that, right now, the program crashes with an "Out of Memory Error" every time I try to jump any sizable distance. Jumps of small distances, on the order of a few seconds, work file. Jumps of big distances, on the order of minutes, raise the error and make the program crash.
I'm including a functional sketch that replicates the error. Just add audio. (... to the data folder, and name it "audio.wav".)
If there any way I can get this sort of seeking/scrubbing working with Minim? If not, is there another sound library I could use? I'm doing most of my development in Eclipse, so I'm not restricted to Processing audio libraries.
Many thanks in advance for your help. :)
Best wishes,
Dave
Code:
/**
* Based on Load Sample by Damien Di Fede.
*/
import ddf.minim.*;
Minim minim;
AudioPlayer longSound;
int RECT_WIDTH = 400;
int RECT_OFFSET = 50;
float normalizedPosition;
int newPosition;
int soundLength;
int playHeadPos;
void setup()
{
size(500, 200, P2D);
minim = new Minim(this);
longSound = minim.loadFile("brahms.wav", 2048);
textMode(SCREEN);
textFont(createFont("SanSerif", 12));
}
void draw()
{
background(0);
rectMode(CORNER);
rect(RECT_OFFSET,50,RECT_WIDTH,100);
text("Position in file: "+longSound.position()+" ms",5,15);
longSound.play();
rectMode(CENTER);
playHeadPos = round(RECT_OFFSET + RECT_WIDTH*longSound.position()/(float)longSound.length());
rect(playHeadPos,100,10,160);
text("Click in the box to jump to a new location in the file.",100,180);
}
void mousePressed()
{
normalizedPosition = (mouseX-RECT_OFFSET) / (float)RECT_WIDTH;
newPosition = round(normalizedPosition * longSound.length());
longSound.cue(newPosition);
}
void stop()
{
// always close Minim audio classes when you are done with them
longSound.close();
minim.stop();
super.stop();
}