Skipping back takes too long

edited February 2017 in Library Questions

Hi together,

I'm trying to program a little audio player using minim which needs to read large files. The player can read long files as a mp3. My mp3 fiel has about 25 MB (about 30 minutes).

The problem is when I skip to a previous position in the file, it tooks so much time to go there and playback again. Also when I only want to skip five seconds back. Forward is quite ok, but not satisfactory when going more forward than, let's say, 30 seconds or more. But backward is a big issue. It seems that when skipping back, the functionality from the library is to start from the beginning again and going to this position.

To get the same issue: - Create or Load (from examples) a Project from minim player - load a (long) mp3 file - I guess that other formats has the same problem - let some time pass (let's say about 10 minutes) - than skip 5 seconds back

Also when you jump to a certain position which is longer in the future.

I guess that the library get's through all samples in the file from beginning, because it cannot jump directly in.

You can also see the behavior in the example below. You will see that skipping back let's the little file lag a little bit. With forward it is no problem. Now assume bigger and longer files.

Sample Code from minim examples (slightly changed):

import ddf.minim.*;

Minim minim;
AudioPlayer groove;

void setup()
  size(512, 200);
  // instead of size(512, 200, P3D);

  minim = new Minim(this);
  groove = minim.loadFile("groove.mp3");
  // instead of  groove = minim.loadFile("groove.mp3", 2048);

void draw()


  for(int i = 0; i < groove.bufferSize() - 1; i++)
    line(i, 50  + groove.left.get(i)*50,  i+1, 50  + groove.left.get(i+1)*50);
    line(i, 150 + groove.right.get(i)*50, i+1, 150 + groove.right.get(i+1)*50);

  float posx = map(groove.position(), 0, groove.length(), 0, width);
  line(posx, 0, posx, height);

  text("Press f to skip forward and r to skip backward.", 10, 20);

void keyPressed()
  if ( key == 'f' )
    // skip forward 1 second (1000 milliseconds)
  if ( key == 'r' )
    // skip backward 1 second (1000 milliseconds)

The problem is similar to jumping to a certain position in the file when the delta of the current (or start) position and the desired position is big enough.

It would be great to understand the problem. Thank you very much in advance for your help.



  • Answer ✓

    Edit post, highlight code, press ctrl-o to format the code for the forum. Leave a blank line before and after.

    This might be a limitation in mp3 file format. Things are stored in variable length buckets. You know how long the current bucket is so it's easy enough to get to the next bucket. But you don't know how big the previous bucket is so you don't know how far to skip backwards.

  • Answer ✓

    Similarly, the bucket for 30 seconds from now might be 1000 buckets away and you have to read every one between now and there.

  • Answer ✓

    And mp3s don't store samples directly, they store mdct versions of the input which can be used to (roughly) recreate it but take up a lot less space.

  • Thank you very much for the fast reply. I will work through the link you shared to get a better understanding of mp3 format.

    I also have this issue with wav files and perhaps this could also occure in other formats. Can you also please share some good links for understanding this all better?

  • Answer ✓

    ('frames' is a better word than my 'buckets'. a frame represents 1152 samples for mp3 but how long that is, timewise, depends on the sample rate)

  • When we have a frame rate of 10 then the sample rate would be 11,520 and we would have 1 second of audio if we have 11,520 samples. Is that what you meant @koogs?

  • edited February 2017 Answer ✓

    that's frame within the mp3 file, not frame as in processing frameRate.

Sign In or Register to comment.