| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 2 |  |  |  |  |  |  | # File:         MPC.pm | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | # Description:  Read Musepack audio meta information | 
| 5 |  |  |  |  |  |  | # | 
| 6 |  |  |  |  |  |  | # Revisions:    11/14/2006 - P. Harvey Created | 
| 7 |  |  |  |  |  |  | # | 
| 8 |  |  |  |  |  |  | # References:   1) http://www.musepack.net/ | 
| 9 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | package Image::ExifTool::MPC; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 1 |  |  | 1 |  | 7 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 41 |  | 
| 14 | 1 |  |  | 1 |  | 5 | use vars qw($VERSION); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 59 |  | 
| 15 | 1 |  |  | 1 |  | 11 | use Image::ExifTool qw(:DataAccess :Utils); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 239 |  | 
| 16 | 1 |  |  | 1 |  | 517 | use Image::ExifTool::FLAC; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 433 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | $VERSION = '1.01'; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # MPC metadata blocks | 
| 21 |  |  |  |  |  |  | %Image::ExifTool::MPC::Main = ( | 
| 22 |  |  |  |  |  |  | PROCESS_PROC => \&Image::ExifTool::FLAC::ProcessBitStream, | 
| 23 |  |  |  |  |  |  | GROUPS => { 2 => 'Audio' }, | 
| 24 |  |  |  |  |  |  | NOTES => q{ | 
| 25 |  |  |  |  |  |  | Tags used in Musepack (MPC) audio files.  ExifTool also extracts ID3 and APE | 
| 26 |  |  |  |  |  |  | information from these files. | 
| 27 |  |  |  |  |  |  | }, | 
| 28 |  |  |  |  |  |  | 'Bit032-063' => 'TotalFrames', | 
| 29 |  |  |  |  |  |  | 'Bit080-081' => { | 
| 30 |  |  |  |  |  |  | Name => 'SampleRate', | 
| 31 |  |  |  |  |  |  | PrintConv => { | 
| 32 |  |  |  |  |  |  | 0 => 44100, | 
| 33 |  |  |  |  |  |  | 1 => 48000, | 
| 34 |  |  |  |  |  |  | 2 => 37800, | 
| 35 |  |  |  |  |  |  | 3 => 32000, | 
| 36 |  |  |  |  |  |  | }, | 
| 37 |  |  |  |  |  |  | }, | 
| 38 |  |  |  |  |  |  | 'Bit084-087' => { | 
| 39 |  |  |  |  |  |  | Name => 'Quality', | 
| 40 |  |  |  |  |  |  | PrintConv => { | 
| 41 |  |  |  |  |  |  | 1 => 'Unstable/Experimental', | 
| 42 |  |  |  |  |  |  | 5 => '0', | 
| 43 |  |  |  |  |  |  | 6 => '1', | 
| 44 |  |  |  |  |  |  | 7 => '2 (Telephone)', | 
| 45 |  |  |  |  |  |  | 8 => '3 (Thumb)', | 
| 46 |  |  |  |  |  |  | 9 => '4 (Radio)', | 
| 47 |  |  |  |  |  |  | 10 => '5 (Standard)', | 
| 48 |  |  |  |  |  |  | 11 => '6 (Xtreme)', | 
| 49 |  |  |  |  |  |  | 12 => '7 (Insane)', | 
| 50 |  |  |  |  |  |  | 13 => '8 (BrainDead)', | 
| 51 |  |  |  |  |  |  | 14 => '9', | 
| 52 |  |  |  |  |  |  | 15 => '10', | 
| 53 |  |  |  |  |  |  | }, | 
| 54 |  |  |  |  |  |  | }, | 
| 55 |  |  |  |  |  |  | 'Bit088-093' => 'MaxBand', | 
| 56 |  |  |  |  |  |  | 'Bit096-111' => 'ReplayGainTrackPeak', | 
| 57 |  |  |  |  |  |  | 'Bit112-127' => 'ReplayGainTrackGain', | 
| 58 |  |  |  |  |  |  | 'Bit128-143' => 'ReplayGainAlbumPeak', | 
| 59 |  |  |  |  |  |  | 'Bit144-159' => 'ReplayGainAlbumGain', | 
| 60 |  |  |  |  |  |  | 'Bit179' => { | 
| 61 |  |  |  |  |  |  | Name => 'FastSeek', | 
| 62 |  |  |  |  |  |  | PrintConv => { 0 => 'No', 1 => 'Yes' }, | 
| 63 |  |  |  |  |  |  | }, | 
| 64 |  |  |  |  |  |  | 'Bit191' => { | 
| 65 |  |  |  |  |  |  | Name => 'Gapless', | 
| 66 |  |  |  |  |  |  | PrintConv => { 0 => 'No', 1 => 'Yes' }, | 
| 67 |  |  |  |  |  |  | }, | 
| 68 |  |  |  |  |  |  | 'Bit216-223' => { | 
| 69 |  |  |  |  |  |  | Name => 'EncoderVersion', | 
| 70 |  |  |  |  |  |  | PrintConv => '$val =~ s/(\d)(\d)(\d)$/$1.$2.$3/; $val', | 
| 71 |  |  |  |  |  |  | }, | 
| 72 |  |  |  |  |  |  | ); | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 75 |  |  |  |  |  |  | # Extract information from an MPC file | 
| 76 |  |  |  |  |  |  | # Inputs: 0) ExifTool object reference, 1) dirInfo reference | 
| 77 |  |  |  |  |  |  | # - Just looks for MPC trailer if FileType is already set | 
| 78 |  |  |  |  |  |  | # Returns: 1 on success, 0 if this wasn't a valid MPC file | 
| 79 |  |  |  |  |  |  | sub ProcessMPC($$) | 
| 80 |  |  |  |  |  |  | { | 
| 81 | 2 |  |  | 2 | 0 | 5 | my ($et, $dirInfo) = @_; | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | # must first check for leading ID3 information | 
| 84 | 2 | 100 |  |  |  | 6 | unless ($$et{DoneID3}) { | 
| 85 | 1 |  |  |  |  | 6 | require Image::ExifTool::ID3; | 
| 86 | 1 | 50 |  |  |  | 9 | Image::ExifTool::ID3::ProcessID3($et, $dirInfo) and return 1; | 
| 87 |  |  |  |  |  |  | } | 
| 88 | 1 |  |  |  |  | 2 | my $raf = $$dirInfo{RAF}; | 
| 89 | 1 |  |  |  |  | 1 | my $buff; | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | # check MPC signature | 
| 92 | 1 | 50 | 33 |  |  | 3 | $raf->Read($buff, 32) == 32 and $buff =~ /^MP\+(.)/s or return 0; | 
| 93 | 1 |  |  |  |  | 11 | my $vers = ord($1) & 0x0f; | 
| 94 | 1 |  |  |  |  | 6 | $et->SetFileType(); | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | # extract audio information (currently only from version 7 MPC files) | 
| 97 | 1 | 50 |  |  |  | 3 | if ($vers == 0x07) { | 
| 98 | 1 |  |  |  |  | 8 | SetByteOrder('II'); | 
| 99 | 1 |  |  |  |  | 4 | my $pos = $raf->Tell() - 32; | 
| 100 | 1 | 50 |  |  |  | 4 | if ($et->Options('Verbose')) { | 
| 101 | 0 |  |  |  |  | 0 | $et->VPrint(0, "MPC Header (32 bytes):\n"); | 
| 102 | 0 |  |  |  |  | 0 | $et->VerboseDump(\$buff, DataPos => $pos); | 
| 103 |  |  |  |  |  |  | } | 
| 104 | 1 |  |  |  |  | 3 | my $tagTablePtr = GetTagTable('Image::ExifTool::MPC::Main'); | 
| 105 | 1 |  |  |  |  | 3 | my %dirInfo = ( DataPt => \$buff, DataPos => $pos ); | 
| 106 | 1 |  |  |  |  | 4 | $et->ProcessDirectory(\%dirInfo, $tagTablePtr); | 
| 107 |  |  |  |  |  |  | } else { | 
| 108 | 0 |  |  |  |  | 0 | $et->Warn('Audio info currently not extracted from this version MPC file'); | 
| 109 |  |  |  |  |  |  | } | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | # process APE trailer if it exists | 
| 112 | 1 |  |  |  |  | 8 | require Image::ExifTool::APE; | 
| 113 | 1 |  |  |  |  | 17 | Image::ExifTool::APE::ProcessAPE($et, $dirInfo); | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 1 |  |  |  |  | 5 | return 1; | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | 1;  # end | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | __END__ |