### Author Topic: Mp3 Calculations  (Read 2353 times)

#### cman

• Member
• Posts: 225
##### Mp3 Calculations
« 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!

#### dedndave

• Member
• Posts: 8829
• Still using Abacus 2.0
##### Re: Mp3 Calculations
« Reply #1 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

#### Siekmanski

• Member
• Posts: 2453
##### Re: Mp3 Calculations
« Reply #2 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
Creative coders use backward thinking techniques as a strategy.

#### cman

• Member
• Posts: 225
##### Re: Mp3 Calculations
« Reply #3 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