[Openal] Retrieve the total number of seconds of a sound file
?
Jason Daly
jdaly at ist.ucf.edu
Thu May 22 11:15:20 PDT 2008
wassim_belhadj wrote:
> Dear list
>
> How to get the number of seconds of a sound file with Openal?
>
> I do not want to retrieve the number of seconds when the source is in play
> (that I know do) but I want to retrieve the total number of seconds to get
> a display like 01:00 / 03:40
>
> what I try to retrieve is 03:40
>
I don't think there's a direct mechanism for this. You should be able
to do it by querying the buffer size, and then dividing by sample rate,
number of channels, and and bytes per sample:
alGetBufferi(bufferID, AL_SIZE, &size);
alGetBufferi(bufferID, AL_FREQUENCY, &freq);
alGetBufferi(bufferID, AL_BITS, &bits);
alGetBufferi(bufferID, AL_CHANNELS, &channels);
seconds = size / freq / bits / channels;
This assumes you've got a single, static buffer attached to the source.
If you're using buffer queueing, you'll have to do the same for each
buffer, and accumulate the results.
--"J"
More information about the Openal
mailing list