MPC.pm 4.1 KB

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