3

I'm migrating from FMOD to OpenAL and I can't find an analogue of the FSOUND_Sample_GetLength() function, which returns the length of the sample in samples (it doesn't take frequency in consideration)... I get OpenAL buffer name from alutLoadMemoryFromFileImage(), so I can't get the waveform data this way.

Please help!

Ryan
  • 1,451
  • 2
  • 27
  • 36

1 Answers1

13

You need to piece it together yourself using alGetBufferi():

ALint sizeInBytes;
ALint channels;
ALint bits;

alGetBufferi(bufferID, AL_SIZE, &sizeInBytes);
alGetBufferi(bufferID, AL_CHANNELS, &channels);
alGetBufferi(bufferID, AL_BITS, &bits);

lengthInSamples = sizeInBytes * 8 / (channels * bits);

And for duration in seconds:

ALint frequency;

alGetBufferi(bufferID, AL_FREQUENCY, &frequency);

durationInSeconds = (float)lengthInSamples / (float)frequency;
Karl
  • 14,434
  • 9
  • 44
  • 61