### Author Topic: How does BASS calculate the MP3s playtime?  (Read 2804 times)

#### 3delite

• Posts: 932
##### How does BASS calculate the MP3s playtime?
« on: 30 Oct '05 - 20:49 »

How does BASS calculate the MP3's playtime?
I use the formula MPEG frames * 0.026 but get different values.

#### Sebastian_Mares

• Guest
##### Re: How does BASS calculate the MP3s playtime?
« Reply #1 on: 31 Oct '05 - 07:04 »

How does BASS calculate the MP3's playtime?
I use the formula MPEG frames * 0.026 but get different values.

It's not always 0.026. It's actually Sample Size / Sampling Rate in Hz.
Here are the sample sizes:

MPEG 1 Layer 1 = 384
MPEG 1 Layer 2 = 1152
MPEG 1 Layer 3 = 1152

MPEG 2(.5) Layer 1 = 384
MPEG 2(.5) Layer 2 = 1152
MPEG 2(.5) Layer 3 = 576

#### spacefractal

• Posts: 44
##### Re: How does BASS calculate the MP3s playtime?
« Reply #2 on: 31 Oct '05 - 08:08 »
Im used this to calulate the mp3 in length:

BBDECL int BBCALL JUKEBOX_TotalTime(int Handle)
{  int pos=BASS_ChannelGetLength(Handle);
if (pos==0) return -1;
int time=(DWORD)BASS_ChannelBytes2Seconds(Handle,pos);
return time;
}

Handle is ment the ID handle, you got when you open the file.

#### 3delite

• Posts: 932
##### Re: How does BASS calculate the MP3s playtime?
« Reply #3 on: 31 Oct '05 - 08:37 »
It's not always 0.026. It's actually Sample Size / Sampling Rate in Hz.
Here are the sample sizes:

MPEG 1 Layer 1 = 384
MPEG 1 Layer 2 = 1152
MPEG 1 Layer 3 = 1152

MPEG 2(.5) Layer 1 = 384
MPEG 2(.5) Layer 2 = 1152
MPEG 2(.5) Layer 3 = 576

I see, thanks!
I was using the 0.026 sec time all the way in my code , that would be too complicated to change, but I improved the opening of MPEG files time display. Still there is some difference (0.10secs) but that's much better now!
Thanks!

« Last Edit: 31 Oct '05 - 09:00 by 3delite »