ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/PDL-Audio/Pitches.pm
Revision: 1.2
Committed: Thu Mar 3 17:36:58 2005 UTC (19 years, 7 months ago) by root
Branch: MAIN
CVS Tags: rel-1_1, rel-1_2, HEAD
Changes since 1.1: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package PDL::Audio::Pitches;
2
3 require Exporter;
4
5 @ISA = qw(Exporter);
6
7 $VERSION = 1.0;
8
9 =head1 NAME
10
11 PDL::Audio::Pitches - All the standard musical pitch names.
12
13 =head1 SYNOPSIS
14
15 use PDL::Audio::Pitches;
16
17 print a4; # prints 440
18 print bs3; # prints 261.63
19
20 =head1 DESCRIPTION
21
22 This module defines (and exports by default(!)) all standard pitch names:
23
24 C<cdefgab> with trailing octave, e.g. C<a4>, C<g3>, C<c0>, C<a8>,
25 C<interleaved "f" and "s", e.g. as4>, C<bf3>, C<fs6>.
26
27 =cut
28
29 =head1 AUTHOR
30
31 Marc Lehmann <schmorp@schmorp.de>
32
33 =head1 SEE ALSO
34
35 perl(1), L<PDL>, L<PDL::Audio>.
36
37 =cut
38
39 my $base = 440.0 / (2 ** 4.75);
40
41 sub gen($$$) {
42 my ($o,$p,$i) = @_;
43 my $note = "$p$o";
44 my $hz = $base * (2 ** ($o + $i/12));
45 eval "sub $note (){ $hz }";
46 push @EXPORT, $note;
47 }
48
49 for my $o (0..8) {
50 gen $o, 'c', 0; gen $o, 'cs', 1; gen $o, 'df', 1;
51 gen $o, 'd', 2; gen $o, 'ds', 3; gen $o, 'ef', 3;
52 gen $o, 'e', 4; gen $o, 'ff', 4; gen $o, 'es', 5;
53 gen $o, 'f', 5; gen $o, 'fs', 6; gen $o, 'gf', 6;
54 gen $o, 'g', 7; gen $o, 'gs', 8; gen $o, 'af', 8;
55 gen $o, 'a', 9; gen $o, 'as',10; gen $o, 'bf',10;
56 gen $o, 'b',11; gen $o, 'cf',-1; gen $o, 'bs',12;
57 }
58
59 1;