On 6/22/05, Angerstein <[EMAIL PROTECTED]> wrote:
> 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 don´t know.
> 
> I tried the uucode format transformer "un"pack("u", $buffer) but this don´t
> 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 -> $ss\n";
    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 -> $n\n";
}


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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to