Help - Search - Member List - Calendar
Full Version: Syncsave Integers 7Bit Data +1 sync bit... How do I get my value out of it?
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Angerstein
Hello,

I have just another issue fighting binaeries.

The mp3 format uses something (sick) called syncsave integer.

If you have a 4 Byte 32 Bit the very first bit of every Byte is used
as a syncsave bit. so you can only put a 28 Bit long Number in it.

Puting stuff in this format is the one thing and getting the right number
out of it is the other thing I dont know.

I tried the uucode format transformer "un"pack("u", $buffer) but this dont
work.

Thanks,

Bastian

Dave Gray
On 6/22/05, Angerstein <[Email Removed]> wrote:
QUOTE
The mp3 format uses something (sick) called syncsave integer.

If you have a 4 Byte 32 Bit the very first bit of every Byte is used
as a syncsave bit. so you can only put a 28 Bit long Number in it.

Puting stuff in this format is the one thing and getting the right number
out of it is the other thing I dont know.

I tried the uucode format transformer "un"pack("u", $buffer) but this dont
work.

What you have to do is skip those ranges (between (2^7)+1 and 2^8, etc).

#!/usr/bin/perl
use strict;
use warnings;

my @data = ((2**8)-1, (2**16)-1, (2**24)-1, (2**32)-1);
my @ss = ();
my %gaps;
for (my $i = 7; $i <= 32; $i += 8) {
$gaps{$i} = (2**($i+1)) - (2**$i);
}

# normal to synchsafe
for my $n (@data) {
my $ss = $n;
for my $k (keys %gaps) {
$ss += $gaps{$k} if $ss > (2**$k);
}
print "$n -> $ssn";
push @ss, $ss;
}

# synchsafe to normal
for my $ss (@ss) {
my $n = $ss;
for my $k (keys %gaps) {
$n -= $gaps{$k} if $ss > (2**$k);
}
print "$ss -> $nn";
}


[1] <http://www.id3.org/id3v2.4.0-structure.txt> (section 6.2)


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.