NAME

MIDI::Pitch - Converts MIDI pitches, note names and frequencies into each other

SYNOPSIS

use MIDI::Pitch qw(name2pitch pitch2name freq2pitch pitch2freq basefreq);

my $pitch = name2pitch($name);

DESCRIPTION

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 C, C#/Db, D, ..., followed by an octave number from -1 to 9. Thus, the valid notes range between C-1 and G9.

FUNCTIONS

name2pitch

my $pitch = name2pitch($name);

Converts a note name into a pitch.

pitch2name

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').

freq2pitch

my $pitch = freq2pitch($440);

Converts a frequency >= 0 Hz to a pitch, using the base frequency set.

pitch2freq

my $freq = pitch2freq(69);

Converts a pitch to a frequency, using the base frequency set.

name2freq

my $freq = name2freq('c2');

This is just an alias for pitch2freq(name2pitch($x)).

freq2name

my $name = freq2name('c2');

This is just an alias for pitch2name(freq2pitch($x)).

findsemitone {

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.

basefreq

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.

HISTORY

0.7

Added Changes file.

0.6

findsemitone now also understands semitones specified as integers between 0 and 11. Fixed bug in findsemitone.

0.5

Added findsemitone function

0.2

Added pitch rounding (60.49 and 59.5 will both be considered 60/'C4').

Added frequency/pitch conversion.

Added POD tests.

0.1

Original version; created by h2xs 1.22 with options

-A -C -X -n MIDI::Pitch -v 0.1 -b 5.5.3

SEE ALSO

MIDI. MIDI::Tools.

http://www.harmony-central.com/MIDI/Doc/table2.html

AUTHOR

Christian Renz, <crenz @ web42.com>

COPYRIGHT AND LICENSE

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.