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 › Time taken to move in an mp3 with minim
Page Index Toggle Pages: 1
Time taken to move in an mp3 with minim (Read 1987 times)
Time taken to move in an mp3 with minim
Jun 20th, 2008, 6:52am
 
Hello

I've got a question, I'm trying to do an applet to play mp3, and let browse within it, but, using minim, it usually take something like 4 to 8 seconds before the song begin again.
Another strange thing is that song.position() begin to give the new position a couple of second before the song begin again.
With this, by exemple, the exemple of scrubbing is useless.
Another strange thing is that, sometime, the playing doesn't begin at the beggining of the song, but something like 20 second after.

Is there anything I could do?
Re: Time taken to move in an mp3 with minim
Reply #1 - Jun 23rd, 2008, 1:26am
 
I'm afraid you just aren't going to be able to scrub as smoothly as you might like, at least with an AudioPlayer. An AudioPlayer streams from a file, which means that when you skip to a new position, it has to read and discard all the bytes between the current position and the new position. When you are reading an mp3, this means that it must read, decode, and discard. The decoding is primarily what is slowing it down. If the mp3 is not terribly long, you could try loading it into an AudioSnippet, which means it will be entirely decoded and stored in memory. Then skipping will take much less time.
Re: Time taken to move in an mp3 with minim
Reply #2 - Sep 24th, 2009, 5:20pm
 
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();
}
Re: Time taken to move in an mp3 with minim
Reply #3 - Sep 24th, 2009, 6:15pm
 
Did you test and change the available memory ? maybe you just need more. Go to File - preferences and change it to something bigger.

btw, is a wav file larger in memory than an mp3?
using images it doesnt make a difference if you load a jpg or a bmp, but using mp3s it probably does cause its not only compressed but optimized. so maybe try to load an mp3 instead cause it maybe uses less memory.

Re: Time taken to move in an mp3 with minim
Reply #4 - Sep 25th, 2009, 12:54pm
 
Hi Cedric,

Thanks -- don't know why I didn't think of that myself.  Increasing the memory does indeed keep the program from crashing.  That's a good enough solution for now.  Excellent.

That said, ultimately, I'm still interested in implementing scrubbing without having to allocate oodles of memory.  This seems like it should be possible, at least in theory...  Can anyone give any pointers on how this could be done, either using Minim, or some other audio library?

Thanks, and best wishes,




Dave
Re: Time taken to move in an mp3 with minim
Reply #5 - Sep 25th, 2009, 4:01pm
 
Using OpenAL It used to free a lot of memory in the JVM for me. But it has its own issues of compatibility.

I like to use Sound System by paulscode.com

Made a thread earlier about it
http://processing.org/discourse/yabb2/num_1251268180.html

But... it doesn't feature mp3 support (OGG instead).

Re: Time taken to move in an mp3 with minim
Reply #6 - Oct 4th, 2009, 1:27pm
 
Yah, I figured out why the out of memory stuff was happening and it will be fixed in the next release, which should be available in the next day or two.
Page Index Toggle Pages: 1