Synchsafe

Synchsafe

Synchsafe integers appear in ID3 tags that are attached to an MP3 file.

An ID3 tag [http://www.id3.org/id3v2.4.0-structure.txt ID3 tag version 2.4.0 - Main Structure] encodes several blocks of data. Some blocks (containing metadata about the content of the file) are variable in length and are encoded as 'synchsafe' integers to distinguish them from data in other blocks.

In a synchsafe integer, the most significant bit of each byte is zero, making seven bits out of eight available.So, for example, a 32 bit synchsafe integer can only store 28 bits of information.

Examples:

:(%11111111) is encoded as a 16 bit synchsafe integer (%00000001 01111111). :(%11111111 11111111) is encoded as a 24 bit synchsafe integer (%00000011 01111111 01111111).

C/C++ code to decode Synchsafe encoded values

int unsynchsafe(unsigned int in) { int out=0, i; unsigned int mask=0x7F000000;

for(i=0; i<4; ++i) { out >>= 1; out |= in & mask; mask >>= 8; }

return out;}

References


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”