File: PitchName.h

package info (click to toggle)
audacity 3.7.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 134,800 kB
  • sloc: cpp: 366,277; ansic: 198,323; lisp: 7,761; sh: 3,414; python: 1,501; xml: 1,385; perl: 854; makefile: 125
file content (64 lines) | stat: -rw-r--r-- 2,379 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**********************************************************************

   Audacity: A Digital Audio Editor
   Audacity(R) is copyright (c) 1999-2013 Audacity Team.
   License: GPL v2 or later.  See License.txt.

   PitchName.h
   Vaughan Johnson, Dominic Mazzoni

******************************************************************//**

   utilities for converting among frequency, MIDI note number,
   pitch index, pitch name

*//*******************************************************************/


#ifndef __AUDACITY_PITCHNAME__
#define __AUDACITY_PITCHNAME__

class TranslatableString;

// FreqToMIDInote takes a frequency in Hz (exponential scale relative to
// alphabetic pitch names) and returns a pitch ID number (linear
// scale), such that A440 (A4) is 69, middle C (C4) is 60, etc.
// Each register starts with C (e.g., for middle C and A440,
// it's register 4).
// MIDI note number 0 is C-1 in Scientific pitch notation.
UTILITY_API double FreqToMIDInote(const double freq);

UTILITY_API double MIDInoteToFreq(const double dMIDInote);

// PitchIndex returns the [0,11] index for a double MIDI note number,
// per result from FreqToMIDInote, corresponding to modulo 12
// of the integer part of (dMIDInote + 0.5), so 0=C, 1=C#, etc.
UTILITY_API unsigned int PitchIndex(const double dMIDInote);

// PitchOctave returns the octave index for a double dMIDInote note number,
// per result from FreqToMIDInote.
// MIDI note number 0 is C-1 in Scientific pitch notation.
UTILITY_API int PitchOctave(const double dMIDInote);

enum class PitchNameChoice { Sharps, Flats, Both };

// PitchName takes dMIDInote (per result from
// FreqToMIDInote) and returns a standard pitch/note name [C, C#, etc.).
UTILITY_API TranslatableString PitchName(
   const double dMIDInote,
   const PitchNameChoice choice = PitchNameChoice::Sharps );

// PitchName_Absolute does the same thing as PitchName, but appends
// the octave number, e.g., instead of "C" it will return "C4"
// if the dMIDInote corresponds to middle C, i.e., is 60.
UTILITY_API TranslatableString PitchName_Absolute(
   const double dMIDInote,
   const PitchNameChoice choice = PitchNameChoice::Sharps);

UTILITY_API
double PitchToMIDInote(const unsigned int nPitchIndex, const int nPitchOctave);

UTILITY_API
double PitchToFreq(const unsigned int nPitchIndex, const int nPitchOctave);

#endif	// __AUDACITY_PITCHNAME__