line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Audio::Wav::Tools; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
4
|
|
|
|
|
|
|
eval { require warnings; }; #it's ok if we can't load warnings |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
9
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
834
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.14'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
2
|
|
|
2
|
0
|
8
|
my ($class, %options) = @_; |
11
|
2
|
|
|
|
|
13
|
my $self = { |
12
|
|
|
|
|
|
|
'errorHandler' => undef, |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
9
|
foreach my $key ( qw( .01compatible oldcooledithack debug ) ) { |
16
|
6
|
50
|
66
|
|
|
43
|
$self -> {$key} = exists( $options{$key} ) && $options{$key} ? 1 : 0; |
17
|
|
|
|
|
|
|
} |
18
|
2
|
|
|
|
|
9
|
bless $self, $class; |
19
|
2
|
|
|
|
|
13
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub is_debug { |
23
|
4
|
|
|
4
|
0
|
8
|
my $self = shift; |
24
|
4
|
|
|
|
|
21
|
return $self -> {'debug'}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub is_01compatible { |
28
|
9
|
|
|
9
|
0
|
81
|
my $self = shift; |
29
|
9
|
|
|
|
|
47
|
return $self -> {'.01compatible'}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub is_oldcooledithack { |
33
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
34
|
2
|
|
|
|
|
5
|
return $self -> {'oldcooledithack'}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub set_error_handler { |
38
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
39
|
0
|
|
|
|
|
0
|
my $handler = shift; |
40
|
0
|
0
|
|
|
|
0
|
unless ( ref( $handler ) eq 'CODE' ) { |
41
|
0
|
|
|
|
|
0
|
die 'set_error_handler is expecting a reference to a sub routine'; |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
0
|
$self -> {'errorHandler'} = $handler; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub is_big_endian { |
47
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
48
|
0
|
0
|
|
|
|
0
|
return $self -> {'is_big_endian'} if exists $self -> {'is_big_endian'}; |
49
|
0
|
|
|
|
|
0
|
my $VALUE = 1801677134; |
50
|
0
|
|
|
|
|
0
|
my $nativeLong = pack 'L', $VALUE; # 'kciN' (big) or 'Nick' (little) |
51
|
0
|
|
|
|
|
0
|
my $bigLong = pack 'N', $VALUE; # should return 'kciN' |
52
|
0
|
0
|
|
|
|
0
|
$self -> {'is_big_endian'} = $nativeLong eq $bigLong ? 1 : 0; |
53
|
0
|
|
|
|
|
0
|
return $self -> {'is_big_endian'}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_info_fields { |
57
|
|
|
|
|
|
|
return ( |
58
|
2
|
|
|
2
|
0
|
32
|
'IARL' => 'archivallocation', |
59
|
|
|
|
|
|
|
'IART' => 'artist', |
60
|
|
|
|
|
|
|
'ICMS' => 'commissioned', |
61
|
|
|
|
|
|
|
'ICMT' => 'comments', |
62
|
|
|
|
|
|
|
'ICOP' => 'copyright', |
63
|
|
|
|
|
|
|
'ICRD' => 'creationdate', |
64
|
|
|
|
|
|
|
'IENG' => 'engineers', |
65
|
|
|
|
|
|
|
'IGNR' => 'genre', |
66
|
|
|
|
|
|
|
'IKEY' => 'keywords', |
67
|
|
|
|
|
|
|
'IMED' => 'medium', |
68
|
|
|
|
|
|
|
'INAM' => 'name', |
69
|
|
|
|
|
|
|
'IPRD' => 'product', |
70
|
|
|
|
|
|
|
'ISBJ' => 'subject', |
71
|
|
|
|
|
|
|
'ISFT' => 'software', |
72
|
|
|
|
|
|
|
'ISRC' => 'supplier', |
73
|
|
|
|
|
|
|
'ISRF' => 'source', |
74
|
|
|
|
|
|
|
'ITCH' => 'digitizer', |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get_rev_info_fields { |
79
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
80
|
2
|
100
|
|
|
|
8
|
return %{ $self -> {'rev_info_fields'} } if exists $self -> {'rev_info_fields'}; |
|
1
|
|
|
|
|
21
|
|
81
|
1
|
|
|
|
|
5
|
my %info_fields = $self -> get_info_fields(); |
82
|
1
|
|
|
|
|
4
|
my %rev_info; |
83
|
1
|
|
|
|
|
4
|
foreach my $key ( keys %info_fields ) { |
84
|
17
|
|
|
|
|
38
|
$rev_info{ $info_fields{$key} } = $key; |
85
|
|
|
|
|
|
|
} |
86
|
1
|
|
|
|
|
4
|
$self -> {'rev_info_fields'} = \%rev_info; |
87
|
1
|
|
|
|
|
14
|
return %rev_info; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub get_sampler_fields { |
92
|
|
|
|
|
|
|
# dwManufacturer dwProduct dwSamplePeriod dwMIDIUnityNote dwMIDIPitchFraction dwSMPTEFormat dwSMPTEOffset cSampleLoops cbSamplerData |
93
|
|
|
|
|
|
|
# ) struct dwIdentifier; dwType; dwStart; dwEnd; dwFraction; dwPlayCount; |
94
|
|
|
|
|
|
|
return ( |
95
|
3
|
|
|
3
|
0
|
34
|
'fields' => [ qw( manufacturer product sample_period midi_unity_note midi_pitch_fraction smpte_format smpte_offset sample_loops sample_data ) ], |
96
|
|
|
|
|
|
|
'loop' => [ qw( id type start end fraction play_count ) ], |
97
|
|
|
|
|
|
|
'extra' => [], |
98
|
|
|
|
|
|
|
# 'extra' => [ map 'unknown' . $_, 1 .. 3 ], |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub get_sampler_defaults { |
103
|
|
|
|
|
|
|
return ( |
104
|
2
|
|
|
2
|
0
|
19
|
'midi_pitch_fraction' => 0, |
105
|
|
|
|
|
|
|
'smpte_format' => 0, |
106
|
|
|
|
|
|
|
'smpte_offset' => 0, |
107
|
|
|
|
|
|
|
'product' => 0, |
108
|
|
|
|
|
|
|
'sample_period' => 0, # 22675, |
109
|
|
|
|
|
|
|
'manufacturer' => 0, |
110
|
|
|
|
|
|
|
'sample_data' => 0, |
111
|
|
|
|
|
|
|
'midi_unity_note' => 65 |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub get_sampler_loop_defaults { |
116
|
|
|
|
|
|
|
return ( |
117
|
2
|
|
|
2
|
0
|
9
|
'fraction' => 0, |
118
|
|
|
|
|
|
|
'type' => 0 |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub error { |
124
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
125
|
0
|
|
|
|
|
0
|
my $filename = shift; |
126
|
0
|
|
|
|
|
0
|
my $msg = shift; |
127
|
0
|
|
|
|
|
0
|
my $type = shift; |
128
|
0
|
|
|
|
|
0
|
my $handler = $self -> {'errorHandler'}; |
129
|
0
|
0
|
|
|
|
0
|
if ( $handler ) { |
130
|
0
|
0
|
|
|
|
0
|
my %hash = ( |
131
|
|
|
|
|
|
|
'filename' => $filename, |
132
|
|
|
|
|
|
|
'message' => $msg ? $msg : '', |
133
|
|
|
|
|
|
|
); |
134
|
0
|
0
|
|
|
|
0
|
$hash{'warning'} = 1 if $type eq 'warn'; |
135
|
0
|
|
|
|
|
0
|
&$handler( %hash ); |
136
|
|
|
|
|
|
|
} else { |
137
|
0
|
0
|
|
|
|
0
|
my $txt = $filename ? "$filename: $msg\n" : "$msg\n"; |
138
|
0
|
0
|
0
|
|
|
0
|
if ( $type && $type eq 'warn' ) { |
139
|
0
|
|
|
|
|
0
|
warn $txt; |
140
|
|
|
|
|
|
|
} else { |
141
|
0
|
|
|
|
|
0
|
die $txt; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
0
|
|
|
|
|
0
|
return; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub get_wav_pack { |
148
|
4
|
|
|
4
|
0
|
8
|
my $self = shift; |
149
|
|
|
|
|
|
|
return { |
150
|
4
|
|
|
|
|
45
|
'order' => [ qw( format channels sample_rate bytes_sec block_align bits_sample ) ], |
151
|
|
|
|
|
|
|
'types' => { |
152
|
|
|
|
|
|
|
'format' => 'v', |
153
|
|
|
|
|
|
|
'channels' => 'v', |
154
|
|
|
|
|
|
|
'sample_rate' => 'V', |
155
|
|
|
|
|
|
|
'bytes_sec' => 'V', |
156
|
|
|
|
|
|
|
'block_align' => 'v', |
157
|
|
|
|
|
|
|
'bits_sample' => 'v', |
158
|
|
|
|
|
|
|
}, |
159
|
|
|
|
|
|
|
}; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |