Sign in to follow this  
_rab_

Ogg stream length

Recommended Posts

_rab_    122
I've got a ogg/vorbis stream, i need to know how long it is (pcm duration). Does anyone know if this possible? I'm not opening a file, it's streaming from the internet, so I can't use the ov_* functions (unless I'm wrong), and I can't find anything in the headers that store this information. I guessed this would be something that is done frequently, but can't find any reference to this sort of stuff on the web. Cheers Rab

Share this post


Link to post
Share on other sites
Gorax    202
You can determine the length of a track going by the data length, frequency and the format. I wrote these functions a while ago to find the length of a track.


ALuint oalGetSampleSize(ALenum format){
//defaults to 1, even if the format is invalid
ALuint sampleSize = 1;
switch (format){
case AL_FORMAT_STEREO16:
sampleSize *= 2;
case AL_FORMAT_MONO16:
case AL_FORMAT_STEREO8:
sampleSize *= 2;
break;
}
return sampleSize;
}

ALfloat oalGetTrackLength(ALuint dataLength,ALuint freq,ALenum format){
ALfloat trackLength = 0.0f;
if (freq != 0.0f){//avoid divide by zero
trackLength = dataLength / (ALfloat)(freq * oalGetSampleSize(format));
}
return trackLength;
}

Share this post


Link to post
Share on other sites
_rab_    122
Thanks for your reply Gorax - that's the best option i could think of, but I don't have the uncompressed data length - it's streaming from the internet and I'm not guaranteed that all the data is down yet :/

I was wanting to know if this information was available in the headers. I thought it might be simply because windows media player knows what length an mp3 is when it is being streamed - so i guess mp3 has it - just don't know if it exists in ogg, or where to get it from if it does.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this