Image/ExifTool/WavPack.pm

filter: Statementstmt 65.7% 23 / 35 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 69.5% 32 / 46 CC 3 SCAR 9.4
CC
3
Cov
67%
ProcessWV
5.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.6
« Image/ExifTool/PhotoCD.pm ↑ Summary Image/ExifTool/Casio.pm »
1 #------------------------------------------------------------------------------
2 # File: WavPack.pm
3 #
4 # Description: Read metadata from WavPack audio files
5 #
6 # Revisions: 2025-09-24 - P. Harvey Created
7 #
8 # References: 1) https://www.wavpack.com/WavPack5FileFormat.pdf
9 #------------------------------------------------------------------------------
10  
11 package Image::ExifTool::WavPack;
12  
13 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use Image::ExifTool::RIFF;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶use Image::ExifTool::APE;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 6 $VERSION = '1.00';
20  
21 6 %Image::ExifTool::WavPack::Main = (
22 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
23 GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Audio' },
24 FORMAT => 'int32u',
25 NOTES => q{
26 Tags extracted from the header of WavPack (WV and WVP) audio files. These
27 files may also contain RIFF, ID3 and/or APE metadata which is also extracted
28 by ExifTool. See L<https://www.wavpack.com/WavPack5FileFormat.pdf> for the
29 WavPack specification.
30 },
31 6.1 => {
32 Name => 'BytesPerSample',
33 Mask => 0x03,
34 ValueConv => '$val + 1',
35 },
36 6.2 => {
37 Name => 'AudioType',
38 Mask => 0x04,
39 PrintConv => { 0 => 'Stereo', 1 => 'Mono' },
40 },
41 6.3 => {
42 Name => 'Compression',
43 Mask => 0x08,
44 PrintConv => { 0 => 'Lossless', 1 => 'Hybrid' },
45 },
46 6.4 => {
47 Name => 'DataFormat',
48 Mask => 0x80,
49 PrintConv => { 0 => 'Integer', 1 => 'Floating Point' },
50 },
51 6.5 => {
52 Name => 'SampleRate',
53 Mask => 0x07800000,
54 Priority => 0, # ("Custom" is not very useful)
55 PrintConv => { # (NC)
56 0 => 6000,
57 1 => 8000,
58 2 => 9600,
59 3 => 11025,
60 4 => 12000,
61 5 => 16000,
62 6 => 22050,
63 7 => 24000,
64 8 => 32000,
65 9 => 44100,
66 10 => 48000,
67 11 => 64000,
68 12 => 88200,
69 13 => 96000,
70 14 => 192000,
71 15 => 'Custom',
72 },
73 },
74 );
75  
76 #------------------------------------------------------------------------------
77 # Extract metadata from a WavPack file
78 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
79 # Returns: 1 on success, 0 if this wasn't a valid WavPack file
80 sub ProcessWV($$)
81 14 ▶{
Subroutine ProcessWV: called CC=3 SCAR=16.4
Pod undocumented
82 14 my ($et, $dirInfo) = @_;
83 14 my $raf = $$dirInfo{RAF};
84 14 my $buff;
85  
86 # verify this is a valid WavPack file
87 14 ▶ return 0 unless $raf->Read($buff, 32) == 32;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 32) == 32 11 3 14
88 3 ▶ return 0 unless $buff =~ /^wvpk.{4}[\x02\x10]\x04/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $buff =~ /^wvpk.{4}[\x02\x10]\x04/s 3 0 3
89 0 $et->SetFileType();
90 0 my %dirInfo = (
91 DataPt => \$buff,
92 DirStart => 0,
93 DirLen => length($buff),
94 );
95 0 $et->ProcessBinaryData(\%dirInfo, GetTagTable('Image::ExifTool::WavPack::Main'));
96 # historically, the RIFF module has handled RIFF-type WavPack files
97 0 $raf->Seek(0,0);
98 0 push @{$$et{PATH}}, 'RIFF'; # update metadata path
99 0 Image::ExifTool::RIFF::ProcessRIFF($et, $dirInfo);
100 # also look for ID3 and APE trailers (ProcessAPE also checks for ID3)
101 0 $$et{PATH}[-1] = 'APE';
102 0 Image::ExifTool::APE::ProcessAPE($et, $dirInfo);
103 0 pop @{$$et{PATH}};
104 0 return 1;
105 }
106  
107 6 1; # end
108  
109 __END__
« Image/ExifTool/PhotoCD.pm ↑ Summary Image/ExifTool/Casio.pm »