|
-
Jun 10th, 2007, 10:56 AM
#1
Thread Starter
New Member
ID3v2 Size bytes
Hi, i'm just messing around trying to make me own mp3 ID3v2 tag retriever. I have managed to read the id3v2 header and then retrieve some tag data from the tag frames. but the way im doing it is i read the overal size of the tag frames from the id3v2 header and then loop through that many bytes reading the tag info. this works fine it seems, but then instead of retrieving tags i seemed to be reading non-tag data. i am not sure why because i assumed that all of the bytes specified in the size (in the id3v2 header) would be tag bytes/data.
i'm guessing that this means i am reading the size from the id3v2 header frame incorrectly. the way i do it is...
the size is stored in 4 bytes (but 7 (most significant bit) is always 0 because it's syncsafe). they use 4 bytes because it is supposed to be one 32-bit number, and so simply adding the 4 bytes together won't give the correct result. right? that's what i thought anyway so i made my own funciton (i don't know if there is some built in function) to read 4 bytes and return them as a single integer representing to correct 32-bit number. In this i include bit 7 from each byte (not sure if i am meant to include this bit).
Anyway the function works as it is expected to but what i want to know is.. am i going about retrieving the size correctly? or am i doing it all wrong, if it is wrong it might explain why i read data past the end of the tag frames.
sorry if this makes no sense, please let me know if you want me to explain something.
thanks for any help!
-
Jun 10th, 2007, 12:01 PM
#2
Hyperactive Member
Re: ID3v2 Size bytes
Have you tried www.id3.org?
It has a wealth of info that may help you.
Also, how are you reading the 32bit Integer?
Prefix has no suffix, but suffix has a prefix.
-
Jun 10th, 2007, 12:18 PM
#3
Thread Starter
New Member
Re: ID3v2 Size bytes
hey, yeah i've been using a number of sites to try figure it all out. but some things i'm just not clear on. i'm assuming that tag frames are all one after the other without any other data being in between, this would allow me to loop through them easily.
the code i use to convert the 4 bytes to the 32-bit int is:
Code:
'-------------------------------------------------------------------
' name: BytesToInt
' comments: takes an array of syncsafe bytes and returns the integer value of
' the bytes as if they were a single binary number. The byte passed in to the
' array at index 0 is the farthest left byte (contains the most significant bit)
' note:
' syncsafe bytes have the most significant bit always set to 0 and so
' it is ignored.
' example:
' binary 0000011 = decimal 3
' binary 0010001 = decimal 17
' binary 0000011 0010001 = 401 (NOT 17 + 3 = 20)
'-------------------------------------------------------------------
Private Function BytesToInt(ByVal iByte() As Byte) As Integer
Dim iTotal As Integer = 0
' ensure that there are no more than 4 bytes passed to the function
If Not (iByte.GetUpperBound(0) > 3) Then
iTotal = iByte(iByte.GetUpperBound(0)) ' store the value of the last passed byte
' ' check that more than 1 byte was passed to the function
If iByte.GetUpperBound(0) > 0 Then ' more than 1 byte was passed
Dim iTotalBitIndicie As Integer = 7
' loop through each of the remaining passed bytes (in reverse)
For iB As Integer = (iByte.GetUpperBound(0) - 1) To 0 Step -1
For iBitIndicie As Integer = 0 To 6
If ((iByte(iB) And (1 * (2 ^ iBitIndicie))) >= 1) Then _
iTotal = iTotal + (1 * (2 ^ iTotalBitIndicie))
iTotalBitIndicie = iTotalBitIndicie + 1
Next
Next
End If
End If
Return iTotal
End Function
-
Jun 10th, 2007, 12:27 PM
#4
Hyperactive Member
Re: ID3v2 Size bytes
That function looks a bit complicated. This is what I use to read 32 bits from a byte array:
vb.net Code:
CByte(Buffer(Index)) Or (CInt(Buffer(Index + 1)) << 8) Or (CInt(Buffer(Index + 2)) << 16) Or (CInt(Buffer(Index + 3)) << 24)
It doesn't care if bit 7 is set or not. If the header is truly syncsafe then you shouldn't worry about that either.
All tags are one after the other but they may not all be present.
Prefix has no suffix, but suffix has a prefix.
-
Jun 10th, 2007, 12:43 PM
#5
Thread Starter
New Member
Re: ID3v2 Size bytes
so with syncsafe bytes when turning it into a 32bit int you still include bit 7?
for example
binary byte 1 is 000000011 = decimal 3
binary byte 2 is 000010001 = decimal 17
(the bold bit is the syncsafe bit)
put these 2 bytes into a 32bit int would mean that the bits get position like this..
binary 000000011 000010001 = decimal 785
but...
if the syncsafe bit (bit 7) isn't meant to be included the bits would be positioned as....
binary 00000011 00010001 = decimal 401
which is the correct way to do it?
-
Jun 10th, 2007, 05:36 PM
#6
Hyperactive Member
Re: ID3v2 Size bytes
I am saying just read the 32 bit value. If bit 7 is supposed to be unset then it will be. If it isn't then obviously the file is corrupt.
Also,
binary byte 1 is 000000011 = decimal 3
has too many bits. One byte only has 8 bits (0-7) and is read right to left.
Prefix has no suffix, but suffix has a prefix.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|