Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: ID3v2 TAG unpack uninitialized value

by BrowserUk (Pope)
on Jan 06, 2014 at 00:30 UTC ( #1069434=note: print w/ replies, xml ) Need Help??


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

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.


Comment on Re^3: ID3v2 TAG unpack uninitialized value
Select or Download Code
Re^4: ID3v2 TAG unpack uninitialized value
by thanos1983 (Scribe) on Jan 06, 2014 at 04:59 UTC

    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://1069434]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-07-30 00:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls