| 1 | package MP3::Splitter; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.005; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | # This allows declaration use MP3::Splitter ':all'; | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # will save memory. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||||||||||||||||||||||||||||||||||
| 18 | mp3split | ||||||||||||||||||||||||||||||||||||||||||
| 19 | mp3split_read | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ) ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | @EXPORT = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | # Preloaded methods go here. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use MPEG::Audio::Frame 0.04; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | die "This version of MPEG::Audio::Frame unsupported" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | if 0.07 == MPEG::Audio::Frame->VERSION; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 10 | ▶ | sub piece_open ($$$$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
piece_open: called CC=6 SCAR=20.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 10 | my ($fname, $piece, $track, $Xing, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 10 | ▶ | my $callback = $piece->[2] || $opts->{name_callback}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$piece->[2] || $opts->{'name_callback'}
MC/DC0%0/2
$piece->[2] || $opts->{'name_callback'}
$piece->[2]
$opts->{'name_callback'}
Truth table33%1/3
A || B
A= $piece->[2]B= $opts->{'name_callback'}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 10 | my $name = &$callback($track, $fname, $piece, $Xing, $opts); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 10 | local *OUT; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 10 | ▶ | die "file `$name' exists" if not $opts->{overwrite} and -f $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $opts->{"overwrite"} and -f $name
MC/DC0%0/2
not $opts->{"overwrite"} and -f $name
not $opts->{"overwrite"}
-f $name
Truth table33%1/3
not(A) and B
A= not $opts->{"overwrite"}B= -f $name
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 10 | ▶ | open OUT, "> $name" or die "open `$name' for write: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 10 | ▶ | binmode OUT or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 10 | ($name, *OUT); # Ouch! | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 18 | ▶ | sub make_sec ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_sec: called CC=8 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 18 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 18 | ▶ | my ($h, $m, $s) = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | $t =~ /^(?:([\d.]+)(?:h|:(?=.*[m:])))?(?:([\d.]+)[m:])?(?:([\d.]+)s?)?$/ | ||||||||||||||||||||||||||||||||||||||||||
| 51 | or die "Unexpected format of time: `$t'"; | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 18 | for my $p ($h, $m, $s) { | |||||||||||||||||||||||||||||||||||||||||
| 53 | 54 | ▶ | next unless defined $p; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 26 | ▶ | $p =~ /^(\d+\.?|\d*\.\d+)$/ or die "Unexpected format of time: `$t'"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 18 | ▶ | ($h || 0) * 3600 + ($m || 0) * 60 + ($s || 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$h || 0
$m || 0
$s || 0
MC/DC0%0/1
$h || 0
$h
MC/DC100%1/1
$m || 0
$m
MC/DC100%1/1
$s || 0
$s
Truth table50%1/2
A
A= $h
Truth table100%2/2
A
A= $m
Truth table100%2/2
A
A= $s
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | sub MY_INF () {1e100} | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 10 | ▶ | sub piece_decl ($$;@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
piece_decl: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 10 | my ($start, $end, %piece_opts) = @{shift()}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 10 | my $was = shift; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 10 | (my $rel_start, $start) = $start =~ /^(>?)(.*)/; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 10 | (my $abs_end, $end) = $end =~ /^(=?)(.*)/; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 10 | $start = make_sec $start; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 10 | ▶ | $start += $was if $rel_start; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 10 | ▶ | if ($end eq 'INF') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | $end = make_sec $_[0][0]; # Start of the next chunk | |||||||||||||||||||||||||||||||||||||||||
| 71 | } else { # Go to the end of the file | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | $end = MY_INF; # Soft infinity | |||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | $piece_opts{lax} = $end; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | ▶ | $end = make_sec $end unless $end eq MY_INF; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | ▶ | $end += $start unless $abs_end; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 10 | ($start, $end, %piece_opts); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | sub _Xing ($) { # Guesswork... What is the correct \0* ? | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Xing: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | my $f = shift; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my $c = $f->content; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | $c =~ /^(\0{4,}(Xing|Info))(.{112})/s or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | length($1)+4, $2, unpack 'N3 C100', $3; # FramesOffset, Type, Flags, Frames, Bytes, Offsets | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 10 | ▶ | sub _Xing_h ($$$$$$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Xing_h: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 10 | my ($Xing, $frames_off, $frames, $bytes, $time, $end, $off) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 10 | my @o; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 10 | ▶ | if ($end >= MY_INF) { # [time, frames, pos] - know it's a final write | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | # Need to interpolate | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | my ($last_time, $last_frac, $i) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | for $i (@$off) { | |||||||||||||||||||||||||||||||||||||||||
| 96 | 389 | my $this_time = $i->[0]/$time * 100; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 389 | ▶ | next if $this_time == $last_time; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 389 | my $this_frac = $i->[2]/$bytes * 256; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 389 | ▶ | while (@o <= $this_time) { # Fuzz ok: actually need only 99 of 100 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 101 | push @o, $last_frac | |||||||||||||||||||||||||||||||||||||||||
| 101 | + ($this_frac - $last_frac)*(@o - $last_time)/($this_time - $last_time); | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 389 | $last_time = $this_time; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 389 | $last_frac = $this_frac; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | } elsif (@$off) { | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | @o = map int($_->[2]/$bytes*256), @$off; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } else { # Before writing, assume linear flow | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 5 | @o = map $_*256/100, 0..99; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 10 | ▶ | @o = map { $_ > 255 ? 255 : $_ } @o[0..99]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 10 | my $c = $Xing->content; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 10 | substr($c, $frames_off, 108) = pack 'N2 C100', $frames, $bytes, @o; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 10 | my $crc = $Xing->crc; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 10 | ▶ | $crc = '' unless defined $crc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 10 | $Xing->header() . $crc . $c; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | ▶ | sub mp3split ($;@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mp3split: called CC=45 SCAR=41.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | my $f = shift; | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | ▶ | return unless @_; # Nothing to do | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | my %opts = ( lax => 0.02, # close to 1/75 - tolerate terminations that early | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 10 | ▶ | verbose => 0, append => sub{''}, prepend => sub{''}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 5 | ▶ | name_callback => sub {sprintf "%02d_%s", shift, shift}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | ▶ | after_write => sub {}, keep_Xing => 1, update_Xing => 1, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | ▶ | %opts = (%opts, %{shift()}) unless 'ARRAY' eq ref $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | ▶ | return unless @_; # Nothing to do | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | local *F; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | ▶ | open F, $f or die("open `$f': $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | binmode F; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | my $frame; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | my $trk = 0; # Before first track | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | my ($frames, $piece_frames) = (0, 0); # frames written | |||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | my ($ttime, $ptime) = (0,0); # total and piece time | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | ▶ | my $piece = shift or return; # start, duration, name-callback, finish-callback, user-data | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | my ($start, $end, %piece_opts) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | ($start, $end, %piece_opts) = piece_decl $piece, $end, @_; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | %piece_opts = (%opts, %piece_opts); | |||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | my ($outf, $out, $finished); # output file and its name, etc | |||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | my ($Xing, $Xing_off, $av_fr, $vbr, $tot_len, $frt, @off, $Xing_tell, $l); | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | ▶ | print STDERR "`$f'\n" if $opts{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | ▶ | while ( $frame = MPEG::Audio::Frame->read(\*F) or ++$finished) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$frame = "MPEG::Audio::Frame"->read(\*F) or ++$finished
MC/DC0%0/2
$frame = "MPEG::Audio::Frame"->read(\*F) or ++$finished
$frame = "MPEG::Audio::Frame"->read(\*F)
++$finished
Truth table66%2/3
A or B
A= $frame = "MPEG::Audio::Frame"->read(\*F)B= ++$finished
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | # Check whether it is an Xing frame | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 11004 | ▶ | if ( !$frames and !$finished | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $frames || $finished and ($Xing_off, undef, undef, my $fr, my $b) = &_Xing($frame)
$frames || $finished
MC/DC33%1/3
not $frames || $finished and ($Xing_off, undef, undef, my $fr, my $b) = &_Xing($frame)
$frames
$finished
($Xing_off, undef, undef, my $fr, my $b) = &_Xing($frame)
Truth table50%2/4
not(A || B) and C
A= $framesB= $finishedC= ($Xing_off, undef, undef, my $fr, my $b) = &_Xing($frame)
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | and ($Xing_off, undef, undef, my $fr, my $b) = _Xing($frame) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | $av_fr = $b/$fr; # Average length of a frame | |||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | $frt = $frame->seconds; # Depends on layer and samplerate only | |||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | $vbr = $av_fr/$frt/125; # kbits is 1000 bits = 1000/8 bytes | |||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | $tot_len = $fr * $frt; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | $Xing = $frame; | |||||||||||||||||||||||||||||||||||||||||
| 159 | printf STDERR "VBR: %.1fkBit/sec. Total: %.2fsec (from Xing header)\n", $vbr, $tot_len | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | ▶ | if $piece_opts{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | # Check what to do with this frame | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 11004 | ▶ | if ( $ttime > $end or $finished ) { # Need to end the current piece | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ttime > $end or $finished
MC/DC100%2/2
$ttime > $end or $finished
$ttime > $end
$finished
Truth table100%3/3
A or B
A= $ttime > $endB= $finished
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 10 | ▶ | die "Unexpected end of piece" unless $outf; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 10 | my $cb = $piece_opts{append}; | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | my $append = | ||||||||||||||||||||||||||||||||||||||||||
| 168 | &$cb($f, $piece, $trk, $ttime, $ptime, $out, $frames, $piece_frames, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 10 | ▶ | ($Xing and $piece_opts{keep_Xing}), $Xing, \%piece_opts, $outf); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Xing && $piece_opts{'keep_Xing'}
MC/DC50%1/2
$Xing && $piece_opts{'keep_Xing'}
$Xing
$piece_opts{'keep_Xing'}
Truth table66%2/3
A && B
A= $XingB= $piece_opts{'keep_Xing'}
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 10 | ▶ | print $outf $append or die if length $append; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
length $append && (print($outf $append) || die())
print $outf $append or die
MC/DC0%0/2
length $append && (print($outf $append) || die())
length $append
print $outf $append
Truth table33%1/3
A && B
A= length $appendB= print $outf $append
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 10 | ▶ | if ($Xing and $piece_opts{keep_Xing} and $piece_opts{update_Xing}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$Xing and $piece_opts{"keep_Xing"} and $piece_opts{"update_Xing"}
$Xing and $piece_opts{"keep_Xing"}
MC/DC33%1/3
$Xing and $piece_opts{"keep_Xing"} and $piece_opts{"update_Xing"}
$Xing
$piece_opts{"keep_Xing"}
$piece_opts{"update_Xing"}
Truth table50%2/4
A and B and C
A= $XingB= $piece_opts{"keep_Xing"}C= $piece_opts{"update_Xing"}
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | # Print actual header | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 5 | my $pos = tell $outf; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 5 | ▶ | seek $outf, 0, $Xing_tell or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 5 | ▶ | push @off, ([$ptime, $piece_frames, $pos]) x (100 - @off) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | if @off < 100; | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 5 | ▶ | push @off, [$ptime, $piece_frames, $pos] if $end >= MY_INF; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 5 | print $outf _Xing_h($Xing, $Xing_off, $piece_frames, | |||||||||||||||||||||||||||||||||||||||||
| 180 | $pos, $ptime, $end, \@off); | ||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 10 | ▶ | close $outf or die "Error closing `$out' for write: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 10 | $cb = $piece_opts{after_write}; | |||||||||||||||||||||||||||||||||||||||||
| 185 | &$cb($f, $piece, $trk, $ttime, $ptime, $out, $frames, $piece_frames, | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 10 | ▶ | ($Xing and $piece_opts{keep_Xing}), $Xing, \%piece_opts); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Xing && $piece_opts{'keep_Xing'}
MC/DC50%1/2
$Xing && $piece_opts{'keep_Xing'}
$Xing
$piece_opts{'keep_Xing'}
Truth table66%2/3
A && B
A= $XingB= $piece_opts{'keep_Xing'}
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 10 | undef $outf; | |||||||||||||||||||||||||||||||||||||||||
| 188 | die "end of audio file before all the tracks written" | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 10 | ▶ | if $finished and (@_ or $ttime < $end - $piece_opts{lax}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$finished and @_ || $ttime < $end - $piece_opts{"lax"}
@_ or $ttime < $end - $piece_opts{"lax"}
MC/DC0%0/3
$finished and @_ || $ttime < $end - $piece_opts{"lax"}
$finished
@_
$ttime < $end - $piece_opts{"lax"}
Truth table50%2/4
A and B or C
A= $finishedB= @_C= $ttime < $end - $piece_opts{"lax"}
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 10 | ▶ | last if $finished; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 8 | ▶ | $piece = shift or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 8 | ($start, $end, %piece_opts) = piece_decl $piece, $end, @_; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 8 | %piece_opts = (%opts, %piece_opts); | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 11002 | my $len = $frame->seconds; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 11002 | $ttime += $len; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 11002 | $ptime += $len; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 11002 | $frames++; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 11002 | ▶ | next if $frames == 1 and $Xing; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$frames == 1 and $Xing
MC/DC50%1/2
$frames == 1 and $Xing
$frames == 1
$Xing
Truth table66%2/3
A and B
A= $frames == 1B= $Xing
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 11000 | ▶ | next if $ttime < $start; # Does not intersect the next interval | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | # Need to write this piece | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 10836 | ▶ | unless ($outf) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 10 | ($out, $outf) = piece_open($f, $piece, ++$trk, $Xing, \%piece_opts); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 10 | $ptime = $len; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 10 | $piece_frames = $l = 0; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 10 | @off = (); | |||||||||||||||||||||||||||||||||||||||||
| 208 | my $prepend = | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 10 | &{$piece_opts{prepend}}($trk, $f, $piece, $Xing, \%piece_opts, $out, $outf); | |||||||||||||||||||||||||||||||||||||||||
| 210 | 10 | ▶ | print $outf $prepend or die if length $prepend; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
length $prepend && (print($outf $prepend) || die())
print $outf $prepend or die
MC/DC0%0/2
length $prepend && (print($outf $prepend) || die())
length $prepend
print $outf $prepend
Truth table33%1/3
A && B
A= length $prependB= print $outf $prepend
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 10 | ▶ | if ($Xing and $piece_opts{keep_Xing}) { # Print estimated header | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Xing and $piece_opts{"keep_Xing"}
MC/DC50%1/2
$Xing and $piece_opts{"keep_Xing"}
$Xing
$piece_opts{"keep_Xing"}
Truth table66%2/3
A and B
A= $XingB= $piece_opts{"keep_Xing"}
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 5 | $Xing_tell = tell $outf; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 5 | print $outf _Xing_h($Xing, $Xing_off, ($end - $start)/$frt, | |||||||||||||||||||||||||||||||||||||||||
| 214 | ($end - $start)/$frt*$av_fr, 0, 0, \@off); | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 5 | $piece_frames++; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | printf STDERR " %2d \@ %17s (=%8s) %s\n", | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 10 | ▶ | $trk, "$start-$end", $end-$start, $out if $piece_opts{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | # For Xing header | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 10836 | ▶ | if ($end < MY_INF) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 5578 | ▶ | my $perc = $end > $start ? int($ptime/($end-$start)*100) : -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 5578 | ▶ | push @off, ([$ptime, $piece_frames, tell $outf]) x ($perc - @off + 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | if $perc >= @off; | ||||||||||||||||||||||||||||||||||||||||||
| 226 | } elsif ($l * 1.01 <= $piece_frames) { | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 777 | push @off, [$ptime, $piece_frames, tell $outf]; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 777 | $l = $piece_frames; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | # Copy frame data. | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 10836 | print $outf $frame->asbin; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 10836 | $piece_frames++; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | ▶ | sub mp3split_read ($$;$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mp3split_read: called CC=8 SCAR=21.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | ▶ | my ($file, $datafile, $opts, @p) = (shift, shift, shift || {}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | local(*IN, $_); | |||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | ▶ | open IN, "< $datafile" or die "Can't open `$datafile' for read: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | ▶ | while (<IN>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 10 | ▶ | next if /^\s*($|#)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 10 | ▶ | /^\s*(>?[\d.hms:]+)\s+(=?([\d.hms:]+|INF))?\s*($|#)/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | or die "unrecognized line: `$_'"; | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 10 | ▶ | push @p, [$1, defined $2 ? $2 : 'INF']; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | close IN or die "Can't close `$datafile' for read: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | mp3split($file, $opts, @p); | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 252 | __END__ | ||||||||||||||||||||||||||||||||||||||||||