ddf / Minim

A Java audio library, designed to be used with Processing.
http://code.compartmental.net/tools/minim
GNU Lesser General Public License v3.0
669 stars 136 forks source link

sound.position() never reaches sound.length() #70

Open francescosoave opened 6 years ago

francescosoave commented 6 years ago

Hi, I'm not sure if this is a bug of if I missed something however I see that the sound.position() value never reaches the sound.length(). Is this normal or not? I'm using Processing 3.1.1

basically I was trying to do the following but the condition will never become true

if(sound.position() >= sound.length()){
        sound.pause();

for instance these are the final values I get if I run println(sound.position() + " - " + (sound.length()))

7523 - 8072
7523 - 8072
7546 - 8072
7569 - 8072
7592 - 8072
7616 - 8072
7616 - 8072
7639 - 8072
7662 - 8072
7662 - 8072
7685 - 8072
7709 - 8072
7709 - 8072
7732 - 8072
7732 - 8072
7755 - 8072
7801 - 8072
7801 - 8072
7801 - 8072
7848 - 8072
7848 - 8072
7871 - 8072
7871 - 8072
7918 - 8072
7918 - 8072
7941 - 8072
7941 - 8072
7941 - 8072
7941 - 8072
7941 - 8072
7941 - 8072
7941 - 8072
yonghuming commented 6 years ago

have any solutions?

francescosoave commented 6 years ago

not from me I'm afraid

ddf commented 5 years ago

it should work, but might be file-specific. i realize i've taken a very long time to respond to this, but if you could provide me with an example problem file, that'd be great.

ddf commented 5 years ago

It would also be helpful to know which class sound is in this case.

francescosoave commented 5 years ago

Hello, thanks for the reply. I was using mp3 files. I can't attach them here but I'm happy to send them over in whatever way is good for you.

sound is just sound = minim.loadFile("/data/samples/sample1.mp3");

ddf commented 5 years ago

If you could possibly share them via Dropbox or something similar, that'd be fantastic.

francescosoave commented 5 years ago

link

in order to have it working I was doing something like

if(sound.position() >= sound.length()-200){ //do stuff }

ddf commented 5 years ago

Thanks, I was able to reproduce the issue with these files and should be able to dig into it later today or tomorrow.

ddf commented 5 years ago

Ok, after looking into this for a bit, I've determined that the problem is that the length() of the files is being misreported due to how it is determined by Minim. In all cases the length is longer than it should be. This means that when playing normally, the end of the file is reached before position() is equal to length().

Attempting to fix this properly is going to take a while, I think, due to the fact that Minim still contains a hacky workaround for how it deals with mp3 metadata. It may also turn out that it's unfixable (or require a patched version of mp3spi), since my attempt at a quick fix is essentially the same as what mp3spi does internally, which means it might be the case that the mp3spi library will also report an incorrect length() for these files. It's not clear to me yet whether or not this is a bug, however.

In the meantime, if all you are doing is calling play() and then want to poll for when the file finishes playing, it should suffice to check isPlaying(), which will switch to false when it reaches the end of the file. At least this is what happens with current code.

ddf commented 5 years ago

Also, is it OK if I include the mp3 files you shared in this repo as part of a test case?

francescosoave commented 5 years ago

hi, thanks for the reply. yes you can include 2 of them (I don't own the rights for the percussion track)