File Coverage

blib/lib/Music/Note/Frequency.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 21 21 100.0


line stmt bran cond sub pod time code
1             package Music::Note::Frequency;
2              
3 3     3   31762 use 5.006;
  3         6  
4 3     3   10 use strict;
  3         3  
  3         43  
5 3     3   8 use warnings;
  3         6  
  3         104  
6              
7             our @ISA=("Music::Note");
8 3     3   1092 use Music::Note;
  3         3284  
  3         249  
9              
10             =head1 NAME
11              
12             Music::Note::Frequency - returns the note's frequency in Hertz (Hz).
13              
14             =head1 VERSION
15              
16             Version 0.03
17              
18             =cut
19              
20             our $VERSION = '0.03';
21              
22              
23             =head1 SYNOPSIS
24              
25             use Music::Note::Frequency;
26              
27             # 'new' is inherited from Music::Note
28             my $note = Music::Note::Frequency->new("C4","ISO");
29              
30             print $note->frequency(); # prints 261.625565300599
31              
32             =head1 DESCRIPTION
33              
34             This module extends Music::Note to provide a method to return the frequency in Hertz (Hz) of the object's note from an equal-tempered tuning. The formula for calculating frequency values was taken from L and modified to support MIDI pitch values instead of piano key numbers:
35              
36             f(n) = 2**((n - 69)/12) * 440 Hz
37              
38            
39              
40             =head1 METHODS
41              
42             =head2 frequency()
43              
44             Returns the frequency in Hertz (Hz) of the note from an equal-tempered tuning. Calculates the frequency from the above formula. Supports all note types that are supported by Music::Note.
45              
46              
47             =cut
48              
49             sub frequency {
50 4     4 1 50 my $self = shift;
51 4         10 my $n=$self->to_midinum();
52            
53 4         31 my $f=440 * 2**(($n-69)/12);
54              
55 4         58 return $f;
56             };
57              
58              
59             =head1 ACKNOWLEDGEMENTS
60              
61             Special thanks to Ben Daglish, the author of Music::Note L, and Wikipedia for source material: L.
62              
63              
64             =head1 AUTHOR
65              
66             Mike Kroh, C<< >>
67              
68             =head1 BUGS
69              
70             Please report any bugs or feature requests to C, or through
71             the web interface at L. I will be notified, and then you'll
72             automatically be notified of progress on your bug as I make changes.
73              
74             =head1 TODO
75              
76             Future releases should contain methods to: return frequency in radians/second, return normalized frequencies (given the sampling rate), return frequencies for alternate tunings. Should create methods for different tunings instead of including equal-tempered formula in "frequency()". None of these are a priority at the time of this release.
77              
78              
79             =head1 SUPPORT
80              
81             You can find documentation for this module with the perldoc command.
82              
83             perldoc Music::Note::Frequency
84              
85              
86             You can also look for information at:
87              
88             =over 4
89              
90             =item * RT: CPAN's request tracker (report bugs here)
91              
92             L
93              
94             =item * AnnoCPAN: Annotated CPAN documentation
95              
96             L
97              
98             =item * CPAN Ratings
99              
100             L
101              
102             =item * Search CPAN
103              
104             L
105              
106             =back
107              
108              
109             =head1 LICENSE AND COPYRIGHT
110              
111             Copyright 2016 Mike Kroh.
112              
113             This program is free software; you can redistribute it and/or modify it
114             under the terms of the the Artistic License (2.0). You may obtain a
115             copy of the full license at:
116              
117             L
118              
119             Any use, modification, and distribution of the Standard or Modified
120             Versions is governed by this Artistic License. By using, modifying or
121             distributing the Package, you accept this license. Do not use, modify,
122             or distribute the Package, if you do not accept this license.
123              
124             If your Modified Version has been derived from a Modified Version made
125             by someone other than you, you are nevertheless required to ensure that
126             your Modified Version complies with the requirements of this license.
127              
128             This license does not grant you the right to use any trademark, service
129             mark, tradename, or logo of the Copyright Holder.
130              
131             This license includes the non-exclusive, worldwide, free-of-charge
132             patent license to make, have made, use, offer to sell, sell, import and
133             otherwise transfer the Package with respect to any patent claims
134             licensable by the Copyright Holder that are necessarily infringed by the
135             Package. If you institute patent litigation (including a cross-claim or
136             counterclaim) against any party alleging that the Package constitutes
137             direct or contributory patent infringement, then this Artistic License
138             to you shall terminate on the date that such litigation is filed.
139              
140             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
141             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
142             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
143             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
144             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
145             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
146             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
147             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
148              
149              
150             =cut
151              
152             1; # End of Music::Note::Frequency