Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Skipping back takes too long

$
0
0

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);
  groove.loop();
}

void draw()
{
  background(0);

  stroke(255);

  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);
  stroke(0,200,0);
  line(posx, 0, posx, height);

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

void keyPressed()
{
  if ( key == 'f' )
  {
    // skip forward 1 second (1000 milliseconds)
    groove.skip(1000);
  }
  if ( key == 'r' )
  {
    // skip backward 1 second (1000 milliseconds)
    groove.skip(-1000);
  }
}

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.


Viewing all articles
Browse latest Browse all 2896

Trending Articles