English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 02 January 2015, 02:58   #1
kkhard
Registered User

 
Join Date: Aug 2014
Location: USA
Posts: 10
mp3 time

is there a way to get the time of an mp3 using datatypes? and maybe the bitrate too? just a quick lookup, not actually play the song.
kkhard is offline  
Old 03 January 2015, 16:25   #2
mritter0
Registered User

 
Join Date: Sep 2013
Location: Bettendorf, IA, USA
Age: 49
Posts: 204
mpega.library gives the BitRate but not the time. It gives some "weird" 5 digit ms number. You would think the time would be pretty important to programmers.....
mritter0 is offline  
Old 03 January 2015, 17:01   #3
jPV
Registered User
jPV's Avatar
 
Join Date: Feb 2008
Location: RNO
Posts: 848
There isn't any reliable way to tell mp3 length (time) without scannning all frames in mp3 file. Scanning whole file takes some time especially on 68k.. although less than playing it, but I'm not sure if there's a program which would do it...

mp3 files may for example contain Info, Xing or Lame tag which would tell the length, but it also may be missing or telling wrong length. Constant bit rate files can be calculated, but for variable bit rate tracks it's harder.

In any case there are so many differently encoded mp3 files with all kinds of mess in tags, but if you only need it for your own encoded cbr tracks then you could trust it
jPV is offline  
Old 03 January 2015, 18:50   #4
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,326
The duration returned by mpega.library is quite accurate even for vbr streams. It's in no way "weird".
thomas is offline  
Old 03 January 2015, 22:23   #5
mritter0
Registered User

 
Join Date: Sep 2013
Location: Bettendorf, IA, USA
Age: 49
Posts: 204
@Thomas: I would think mpega would be accurate. This is what I get from the demo for:

"Armageddon It", 5min 22sec:
Quote:
mpega_demo dh2:mark/music/armageddonit.mp3
Custom bitstream access used
Read 262144 bytes from file 'dh2:mark/music/armageddonit.mp3'
Test if MPEG Audio sync inside...
Ok, found MPEG Audio sync at position 21
bitstream open: filename='dh2:mark/music/armageddonit.mp3'
bitstream open: buffer_size=32676

MPEG norm 1 Layer III
Bitrate: 320 kbps
Frequency: 44100 Hz
Mode: 0 (stereo)
Stream duration: 4340 ms

Output decoding parameters
Channels: 2
Quality: 2
Frequency: 44100 Hz

time used = 0.074 secs
2584216 samples / sec
1.707 % CPU used on real time

last pcm_count = -1
total_pcm = 191232
bitstream close
"Stop" 2min 52sec
Quote:
mpega_demo dh2:mark/music/stop.mp3
Custom bitstream access used
Read 262144 bytes from file 'dh2:mark/music/stop.mp3'
Test if MPEG Audio sync inside...
Ok, found MPEG Audio sync at position 21
bitstream open: filename='dh2:mark/music/stop.mp3'
bitstream open: buffer_size=32676

MPEG norm 1 Layer III
Bitrate: 320 kbps
Frequency: 44100 Hz
Mode: 0 (stereo)
Stream duration: 5538 ms

Output decoding parameters
Channels: 2
Quality: 2
Frequency: 44100 Hz

time used = 0.090 secs
2713600 samples / sec
1.625 % CPU used on real time

last pcm_count = -1
total_pcm = 244224
bitstream close
The shorter song has a longer duration? Should it not be "172,000 ms"?

Or is it just not reading my MP3s that I ripped with iTunes correctly?
mritter0 is offline  
Old 04 January 2015, 00:16   #6
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,326
Quote:
Read 262144 bytes from file
Certainly you cannot get the duration of the entire file if you read only a part of it. The first file probably has a worse compression rate and therefore stores less uncompressed data in the same compressed area. You can see this from the total_pcm which corresponds with the duration.

To get the complete duration of the file, you have to scan it entirely.
thomas is offline  
Old 04 January 2015, 01:58   #7
kkhard
Registered User

 
Join Date: Aug 2014
Location: USA
Posts: 10
ugh
kkhard is offline  
Old 04 January 2015, 10:10   #8
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 46
Posts: 24,862
I had same problem when adding iso+mp3 CD emulation support.
Best method I found was:

1: Check for ID3 tag, if it exists (if VBR it is nearly guaranteed to exist), it most likely will include TLEN field. (Assuming your mp3s are not ancient)
2: If tag is not found, check bitrates of first 100 or so mp3 frames. If all have same bitrate, assume CBR and calculate play time from size of file and single frame's parameters.
3: If VBR and no tag: need to scan whole file to calculate play time.
Toni Wilen is online now  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Guess it's time to go back in time :) mhh Member Introductions 6 10 April 2011 23:40
Mp3 Specksynder request.Modules 3 31 October 2008 11:52
App to update Amiga System time from web time?? DDNI request.Apps 2 31 December 2007 07:21
For Sale: MP3@64 (Clockport MP3 player!) Smiley MarketPlace 6 18 March 2007 01:13
Icon colors are shifting from time to time digital support.WinUAE 15 11 March 2003 22:48

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 13:45.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Page generated in 0.08948 seconds with 15 queries