30 Nov 2005 08:40:02 UTC
- Distribution: MIDI-Pitch
- Module version: 0.7
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (4238 / 0 / 0)
- KwaliteeBus factor: 0
- 66.93% Coverage
- License: unknown
- Activity24 month
- Download (5.12KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionCRENZ Christian Renz
- SEE ALSO
- COPYRIGHT AND LICENSE
MIDI::Pitch - Converts MIDI pitches, note names and frequencies into each other
use MIDI::Pitch qw(name2pitch pitch2name freq2pitch pitch2freq basefreq); my $pitch = name2pitch($name);
This module converts MIDI pitches between 0 and 127 (called 'note numbers' in the MIDI standard) and note names into each other. The octave numbers are based on the table found in the MIDI standard (see http://www.harmony-central.com/MIDI/Doc/table2.html):
The MIDI specification only defines note number 60 as "Middle C", and all other notes are relative. The absolute octave number designations shown here are based on Middle C = C4, which is an arbitrary assignment.
The note names are
D, ..., followed by an octave number from -1 to 9. Thus, the valid notes range between
my $pitch = name2pitch($name);
Converts a note name into a pitch.
my $name = pitch2name($pitch);
Converts a pitch between 0 and 127 into a note name. pitch2name returns the lowercase version with a sharp, if necessary (e.g. it will return 'g#', not 'Ab').
my $pitch = freq2pitch($440);
Converts a frequency >= 0 Hz to a pitch, using the base frequency set.
my $freq = pitch2freq(69);
Converts a pitch to a frequency, using the base frequency set.
my $freq = name2freq('c2');
This is just an alias for
my $name = freq2name('c2');
This is just an alias for
my $pitch = findsemitone('d#', 60);
Finds the nearest pitch that expresses the semitone given around the pitch given. The example above would return 63, since the d# at pitch 63 is nearer to 60 than the d# at pitch 51.
The semitone can be specified in the same format as a note name (without the octave) or as an integer between 0 and 11.
If there are two possibilities for the nearest pitch, findsemitone returns the lower one.
my $basefreq = basefreq; basefreq(432);
Sets/returns current base frequency for frequency/pitch conversion. The standard base frequency set is 440 (Hz). Note that the base frequency does not affect the pitch/name conversion.
Added Changes file.
findsemitone now also understands semitones specified as integers between 0 and 11. Fixed bug in findsemitone.
Added findsemitone function
Added pitch rounding (60.49 and 59.5 will both be considered 60/'C4').
Added frequency/pitch conversion.
Added POD tests.
Original version; created by h2xs 1.22 with options
-A -C -X -n MIDI::Pitch -v 0.1 -b 5.5.3
Christian Renz, <crenz @ web42.com>
Copyright 2004-2005 by Christian Renz <crenz @ web42.com>. All Rights Reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.