Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: ID3v2 TAG unpack uninitialized value

by thanos1983 (Scribe)
on Jan 05, 2014 at 23:42 UTC ( #1069430=note: print w/ replies, xml ) Need Help??


in reply to Re: ID3v2 TAG unpack uninitialized value
in thread ID3v2 TAG unpack uninitialized value

Thanks a lot it works just fine, but I am really confused. I have been trying to understand how the ID3v2 TAG works and I can not figure out this part (header size). Theoretically the whole header should be 10 Bytes. The size part is 4 Unsigned Bytes. So based on this theory if I read 4 Bytes I should be able to get the whole header size. In practice I failed.

The information that I have take is from the official page of the TAG given under:

http://id3.org/id3v2.3.0

I can not still figure this out, because then by adding 16 Bytes (16 Bytes = 4 Unsigned Bytes x 32 Bits size each). So in theory the header size is 4 Bytes now will be 16 Bytes.

Please correct me if I am wrong


Comment on Re^2: ID3v2 TAG unpack uninitialized value
Re^3: ID3v2 TAG unpack uninitialized value
by BrowserUk (Pope) on Jan 06, 2014 at 00:30 UTC
    I can not still figure this out, because then by adding 16 Bytes (16 Bytes = 4 Unsigned Bytes x 32 Bits size each). So in theory the header size is 4 Bytes now will be 16 Bytes.

    As the spec you've now linked indicates that the 'size' field is a 28-bit value encoded in 7-lsbs of each of 4 bytes, my correction of your code was wrong. You should not read 16 byte and decode with a template of "I I I I" as I suggested.

    But rather read 4 bytes as you were, but then decode with a template of 'C C C C' (or 'CCCC' or 'C4').

    And if you unpack to a variable called my @size = unpack 'C4', ...; (rather than the 4 separate $lines_* variables), then the following code from your OP:

    $mp3_size = ($size[0] & 0xFF) | (( $size[1] & 0xFF ) << 7) | (( $size[2] & 0xFF ) << 14) | (( $size[3] & 0xFF ) << 21);

    starts to make sense. It extracts the 7-bit values from the 4 bytes and combines them together to produce the required 28-bit numeric value.

    BTW: reading 4 bytes into a variable called $lines is also misleading.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      It seems correct reading 4 Bytes and printing with C4 but I thought that I should print 4 Unsigned Integers this is the reason that I was using I4. Maybe I was wrong.

        'C' is also an unsigned integer. Just 8-bits rather than 32-bits for 'I'.

        The logic you posted (but presumably didn't write?) then strips the high bits and combined the 4x 7-bits to produce the 28-bit value.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
        Computers are making people easier to use everyday

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1069430]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2014-07-13 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (249 votes), past polls