I’m trying to find a way to get the length of a sound,

I’m trying to use

unsigned int length;
sound->getLength(&length, FMOD_TIMEUNIT_MS);

The length that I get is 227918, whereas the sound file I open is 3min47sec. This is completely incorrect

In reality, I’m not trying to get the length in ms, I need to get the number of bytes.

I’m executing the following loop, where BUF_SIZE is 4096. The loop increments 9815 times, and I need to get that number before entering the loop. How would I do this?


[code:2g74gfd0]bool processing = true; 
    unsigned int bytesRead;
    result = sound->readData((char *)buf, BUF_SIZE, &bytesRead);
    if (result == FMOD_ERR_FILE_EOF)
        processing = false;
    ProcessBuf(buf, bytesRead);
  • You must to post comments

If the length of your sound is 3 minutes and 47 seconds, then the value of 227918 milliseconds is correct.

227918 milliseconds is 227.918 seconds. Let’s round that down to 227 seconds. 227 seconds divided by 60 seconds per minute gives 3.7833, or three minutes and change. Three minutes is 180 seconds, so 227 -180 = 47 seconds left over. So we get 3 minutes and 47 seconds, exactly what you think it should be.

For your loop, I’m guessing that you’ll probably want to use FMOD_TIMEUNIT_PCMBYTES, which will give you the number of samples * channels * datawidth.

Also, in your loop, you’ll want to make sure that you ProcessBuf() even if FMOD_ERR_FILE_EOF is returned, because you will probably get a partial read in that case, and you don’t want to miss the last chunk of your file.

Hope that helps!

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.