# NAME

Music::Note::Frequency - returns the note's frequency in Hertz (Hz).

Version 0.05

# SYNOPSIS

``````    use Music::Note::Frequency;

# create a new note object at C4 with base frequency A4=440 Hz.
my \$note = Music::Note::Frequency->new();

# all of these create a new object with note = C4 and base
#   frequency A4=431 Hz (default is 440):
my \$note = Music::Note::Frequency->new(431);
my \$note = Music::Note::Frequency->new("C4",431);
my \$note = Music::Note::Frequency->new("C4","ISO",431);
my \$note = Music::Note::Frequency->new({   step=>'C',
alter=>0,
octave=>4,
base=>431});
my \$note = Music::Note::Frequency->new({base=>431});

# get the frequency of a note
my \$note = Music::Note::Frequency->new("C4");
print \$note->frequency(); # prints 261.625565300599
# change the note's base frequency
my \$base=\$note->base(431); # sets new base to 431 Hz
print \$note->frequency(); # prints 256.274133283086``````

# DESCRIPTION

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 https://en.wikipedia.org/wiki/Piano_key_frequencies and modified to support MIDI pitch values instead of piano key numbers and alternative base frequencies:

``````        f(n) = 2**((n - 69)/12) * base

``````

# METHODS

## new(\%args)

Creates and returns a Music::Note::Frequency object with the values specified in the arguments or defaults of note value = C4 and frequency base (value of A4) = 440 Hz. Otherwise takes the same arguments as described in the perldoc for Music::Note, with the addition of BASE as an optional (last) numeric argument or as a key/value pair in the passed argument hashref. Example:

``        my \$note = Music::Note::Frequency->new({step=>'C',octave=>4,base=>415});``

## frequency()

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.

## base(FREQ)

Sets or gets the base frequency, i.e. the value of A4 (the A above middle C). This defaults to 440 when you create the note object without specifying a base frequency. If called without any parameters, it simply returns the currently set base frequency (from which all other frequencies are calculated). If called with a numeric parameter, then it sets the base frequency to that value and returns the same. If FREQ is not numeric, then it doesn't set anything - it just returns the current base frequency.

# ACKNOWLEDGEMENTS

Special thanks to Ben Daglish, the author of Music::Note http://search.cpan.org/dist/Music-Note/, both for his original module and his suggestion to allow setting the base frequency, and Wikipedia for source material: https://en.wikipedia.org/wiki/Piano_key_frequencies.

# AUTHOR

Mike Kroh, `<kroh at cpan.org>`

# BUGS

Please report any bugs or feature requests to `bug-music-note-frequency at rt.cpan.org`, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Music-Note-Frequency. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

# TODO

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.

# SUPPORT

You can find documentation for this module with the perldoc command.

``    perldoc Music::Note::Frequency``

You can also look for information at:

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at: