The MASM Forum

General => The Soap Box => Topic started by: cman on January 14, 2014, 04:47:49 AM

Title: Mp3 Calculations
Post by: cman on January 14, 2014, 04:47:49 AM
I was looking at some code that reads a mp3 header file and calculates information about the file ( bitrate , number of channels , etc. ) and found a line of c I can't figure out.  In this line the track length in seconds is calculated from the number of frames contained in the mp3:

Code: [Select]

int playTimeInSeconds = toupper ( numberOfFrames * 26 / 1000 );


Does anyone know what the "magic numbers"  26 and 1000 represent in this calculation ?  I can't figure this out. Thanks for any information!
Title: Re: Mp3 Calculations
Post by: dedndave on January 14, 2014, 05:24:48 AM
good for 44.1 KHz
near the bottom of this page is a section named "Frame size and frame duration"

http://www.compuphase.com/mp3/sta013.htm (http://www.compuphase.com/mp3/sta013.htm)
Title: Re: Mp3 Calculations
Post by: Siekmanski on January 14, 2014, 01:57:58 PM
For MPEG layer-3,

block size  MPEG 1 == 1152
block size  MPEG 2 & 2.5 == 576

frame size: ((block size / 8 * bitrate * 1000) / samplerate) + padding size

total mp3 file duration in milliseconds: file length / average bitrate / 8
Title: Re: Mp3 Calculations
Post by: cman on January 15, 2014, 09:31:06 AM
Thanks for the input! I was using a library to calculate mp3 values  ( taglib ) but this turned out to be somewhat unreliable. I found some code on "codeproject.com" that helped me to figure out to accomplish the data retrieval  ( I had to correct the code for a few hours as the author seemed to have a poor understanding of how to do bit-level operations - note the unneeded use of toupper() in the code fragment above ). Thanks for the information!  :t