1 /********************************************************************** 2 3 Audacity: A Digital Audio Editor 4 Audacity(R) is copyright (c) 1999-2013 Audacity Team. 5 License: GPL v2. See License.txt. 6 7 PitchName.h 8 Vaughan Johnson, Dominic Mazzoni 9 10 ******************************************************************//** 11 12 utilities for converting among frequency, MIDI note number, 13 pitch index, pitch name 14 15 *//*******************************************************************/ 16 17 18 #ifndef __AUDACITY_PITCHNAME__ 19 #define __AUDACITY_PITCHNAME__ 20 21 class TranslatableString; 22 23 // FreqToMIDInote takes a frequency in Hz (exponential scale relative to 24 // alphabetic pitch names) and returns a pitch ID number (linear 25 // scale), such that A440 (A4) is 69, middle C (C4) is 60, etc. 26 // Each register starts with C (e.g., for middle C and A440, 27 // it's register 4). 28 // MIDI note number 0 is C-1 in Scientific pitch notation. 29 AUDACITY_DLL_API double FreqToMIDInote(const double freq); 30 31 AUDACITY_DLL_API double MIDInoteToFreq(const double dMIDInote); 32 33 // PitchIndex returns the [0,11] index for a double MIDI note number, 34 // per result from FreqToMIDInote, corresponding to modulo 12 35 // of the integer part of (dMIDInote + 0.5), so 0=C, 1=C#, etc. 36 AUDACITY_DLL_API unsigned int PitchIndex(const double dMIDInote); 37 38 // PitchOctave returns the octave index for a double dMIDInote note number, 39 // per result from FreqToMIDInote. 40 // MIDI note number 0 is C-1 in Scientific pitch notation. 41 AUDACITY_DLL_API int PitchOctave(const double dMIDInote); 42 43 enum class PitchNameChoice { Sharps, Flats, Both }; 44 45 // PitchName takes dMIDInote (per result from 46 // FreqToMIDInote) and returns a standard pitch/note name [C, C#, etc.). 47 AUDACITY_DLL_API TranslatableString PitchName( 48 const double dMIDInote, 49 const PitchNameChoice choice = PitchNameChoice::Sharps ); 50 51 // PitchName_Absolute does the same thing as PitchName, but appends 52 // the octave number, e.g., instead of "C" it will return "C4" 53 // if the dMIDInote corresponds to middle C, i.e., is 60. 54 AUDACITY_DLL_API TranslatableString PitchName_Absolute( 55 const double dMIDInote, 56 const PitchNameChoice choice = PitchNameChoice::Sharps); 57 58 AUDACITY_DLL_API 59 double PitchToMIDInote(const unsigned int nPitchIndex, const int nPitchOctave); 60 61 AUDACITY_DLL_API 62 double PitchToFreq(const unsigned int nPitchIndex, const int nPitchOctave); 63 64 #endif // __AUDACITY_PITCHNAME__ 65