Results 1 to 5 of 5

Thread: Working with mp3

  1. #1
    Guest

    Thumbs up

    Ok Here goes:

    I have made a simple mp3 player with the Windows Media Player control. I would like to know

    1. How to determine its bitrate, and

    2. How to get its length in min/sec

    I have done the second by loading it into the med player and getting the filename's duration, but it was very slow. Anyone know how to do either of these? Thanks

  2. #2
    Guest

    Thumbs up Try This

    the www.vbweb.co.uk have a great mp3 tut.
    u'll find their the answer to your question

    regards

  3. #3
    Junior Member
    Join Date
    Jan 2001
    Posts
    26
    Hi, working on something myself,
    as an example 128kbps 44100 divide filesize by 16000 time in seconds.

    Sample Rate
    44100
    160kbps Stereo Mp1.0 L3 VBR frame261bytes
    160kbps Mp1 L3 /20000
    128kbps Stereo Mp1.0 L3 /16000 frame208*2
    128kbps JS Mp1 /16000 frame208*2
    112kbps JS Mp1.0 L3 /14000 frame182*2
    96kbps JS Mp1.0 L3 /12000 frame156
    32kbps Mono Mp1.0 L2 /4000
    48000
    32000
    64kbps Mono Mp1.0 L3 /8000 frame144
    22050
    64kbps JS M2.0 L3 /8000
    56kbps JS M2 L3 /
    40kbps JS M2.0 L3 /5000 frame130
    32kbps Mono M2.0 L3 /4000 frame104
    24000
    16000
    24kbps JS M2.0 L3 /8000
    11025
    16kbps Mono M2.5 L3 /2000 frame104
    12000
    8000

    trying to find another doc also
    Steve

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Here's a module I wrote some time ago...
    it's not finished yet, do it yourself

    Code:
    Option Explicit
    'MP3 info module made by Jop de Klein.
    
    Public Type MP3Info
            'Header info
            Bitrate As String
            Layer As String
            MPEGv As String
            Emphasis As String
            Private As Boolean
            Original As Boolean
            CopyRighted As Boolean
            Protected As Boolean
    
            'ID3 Tag
            IsValidTag As Boolean
            Artist As String * 30
            Album As String * 30
            Title As String * 30
            Year As String * 4
            Comment As String * 30
            Genre As String * 1
    End Type
    
    
    Public Function GetMp3Info(f As String) As MP3Info
    Dim fn%, tmp() As Byte, Bitrate&, Tag$, Title$, mp3 As MP3Info, nr&
    fn = FreeFile  'sets a free file slot for the fileopening.
    ReDim tmp(3) 'Redim the byte array (4 bytes = 32 bits) so we can put the header in it
    
    Open f For Binary As #fn
        Get #fn, , tmp 'this is for the header, the first 4 bytes (32 bits)
    Tag = Space(128) 'Fill the string with spaces so there's enough room to put the ID3Tag in.
        Get #fn, LOF(fn) - 127, Tag 'this is to get the id3 tag, the last 128 bytes.
    Close #fn
    
    With mp3
        'Get the mp3 information
        
    'Ok let me explain you something, it MIGHT confuse you 
    'to take bits out of a byte, we use AND & then 2 ^ n
    'where n is the number of the bit
    'so let's say we want the 20th bit
    'we have 32 bits in the byte array (called tmp), so 3 * 8 = 24
    'so we take the third byte, that's tmp(2), cause arrays start
    'from 0.
    'Remember we use AND to take the bits out, and we want the
    '4th bit out of the third byte.
    'We now do tmp(2) AND 2 ^ 4
    '          ^byte          ^bit
    
    'For speed and coolness improvement we use HEXIDECIMAL codes 
    'Just to show how cool we are ok? 
    'You don't need to know what's all this, read more about
    'HEXIDECIMAL stuff on the internet
    'When we want to take the 20th bit I would do
    'tmp(2) AND 2 ^ 4, and with hex that would be
    'tmp(2) AND &H10
    
    'If you really need the Hex values try (IN VB)
    'MSGBOX HEX(2 ^ n), where n = the number of the bit.
    'Like MSGBOX HEX(2 ^ 4) would result 10
    'so you would write in VB
    'tmp(2) AND &H10, where H means hex, to notify VB it's
    'not a decimal nr.
    
    
    'These are booleans (from the header)
        .Original = CBool(tmp(3) And &H40) 'this is bit 30 (bit 6 of the 4th byte)
        .CopyRighted = CBool(tmp(3) And &H20) 'this is bit 29 (bit 5 of the 4th byte)
        .Private = CBool(tmp(2) And &H100) 'this is bit 24 (bit 8 of the 3th byte)
        .Protected = CBool(tmp(1) And &H100) 'this is bit 16 (bit 8 of the 2nd byte)
        
    'Does not work yet (header info), I'll fix it later 
     '  .Bitrate = (tmp(2) \ &H10) 
        .Bitrate = (tmp(2) And &H1F0) \ 16) 'bit 20 - 23 (bit 4 to 8 from the 3nd byte)
        .Layer = (tmp(1) And &H180) \ 128 'bit 14 - 15 (7 and 8 from the 2nd byte)
        .MPEGv = (tmp(1) And &H10) 'bit 12 - 13
        .Emphasis = (tmp(0) And &H3) \ 1 'bit 1 - 2 from the first byte
    
    'from now on, it works again 
    'this is for the ID3tags
        .IsValidTag = (Trim(Mid(Tag, 1, 3) = "TAG")) 'sets a boolean to see if tag exists
    
    If .IsValidTag Then 'only continue if the tag is valid, to avoid errors
         .Title = Trim(Mid(Tag, 4, 30))
          .Artist = Trim(Mid(Tag, 34, 30))
           .Album = Trim(Mid(Tag, 64, 30))
          .Year = Trim(Mid(Tag, 94, 4))
         .Comment = Trim(Mid(Tag, 98, 30))
        .Genre = asc(Trim(Mid(Tag, 128, 1)))
    End If
    
    End With
    GetMp3Info = mp3
    End Function
    Well, the part from Bitrate to the Emphasis doesn't work yet (I have no time (well I don't wanna right now) to fix it, do so if you like)

    the ID3 part is working so that'll get you started, also, the Genre has to be converted with a table too, haven't implemented it *yet*, do so if you need it.

    here's how you would call the sub
    Code:
    Private Sub Form_Load()
    Dim mp3 As Mp3Info
    mp3 = GetMp3Info("MYMP3FILE")
    MsgBox mp3.Album 'to display the album of the mp3file.
    End Sub
    Have Fun!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Guest

    i'll check it out

    thanks eevryone, ill check it out

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width