Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Synchronizing an MP3 (Read 3299 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Synchronizing an MP3

Hello!

I have attached an MP3 file which has several errors. MP3Tag and Winamp will rely on the first frame header and will therefore report wrong information.
The first position, which looks like a valid MPEG frame is 735 (0x02DF). EncSpot found the first frame at 1013 (0x03F5).

Peter (or any other Guru around here), could you tell me at which frame the real MP3 begins? How should I synchronize? I tried setting my code to look for 2 valid frames without trash between them, but that returned byte offset 26092 (0x65EC). This is how I look for a frame:
  • Look for a frame header (0xFF 0xF?).
  • Calculate the frame size using Coefficient * Bitrate * 1000 / Sampling Rate + Padding.

    Coefficient:
    48 for MPEG 1 Layer 1
    144 for MPEG 1 Layer 2 and 3
    24 for MPEG 2 Layer 1
    144 for MPEG 2 Layer 2
    72 for MPEG 2 Layer 3

    Padding:
    1 if Padding was used
    0 if Padding was not used
  • Search for a valid frame header after the current frame.
  • If a frame was found, quit the function
  • If a frame wasn't found, look for the next frame CURRENT POSITION + FRAME SIZE
Any help would be appreciated.

Sebastian Mares

Synchronizing an MP3

Reply #1
OK, the error is here:

Quote
If a frame wasn't found, look for the next frame CURRENT POSITION + FRAME SIZE


If the thing we found isn't really a frame, the frame size information will be wrong. I changed it to CURRENT POSITION + 1 (to look on byte after another), but can't the number (1) be greater (4, for example)? That would accelerate the seeking. The buffer I use for reading has 4 bytes.

In VB (I know, I know...) it looks like this:

Get #intFileNumber, lngCurrentPosition + 1,  abytBuffer

abytBuffer is a byte array with 4 items (0 - 3).