Mercurial > hg > svcore
comparison base/Pitch.h @ 1025:88b54a185a0a
Use double instead of float for frequencies in Pitch, just for confidence
author | Chris Cannam |
---|---|
date | Mon, 08 Dec 2014 15:37:12 +0000 |
parents | d1ce7a4a920b |
children | 48e9f538e6e9 |
comparison
equal
deleted
inserted
replaced
1024:d1ce7a4a920b | 1025:88b54a185a0a |
---|---|
28 * | 28 * |
29 * If concertA is non-zero, use that as the reference frequency | 29 * If concertA is non-zero, use that as the reference frequency |
30 * for the A at MIDI pitch 69; otherwise use the tuning frequency | 30 * for the A at MIDI pitch 69; otherwise use the tuning frequency |
31 * specified in the application preferences (default 440Hz). | 31 * specified in the application preferences (default 440Hz). |
32 */ | 32 */ |
33 static float getFrequencyForPitch(int midiPitch, | 33 static double getFrequencyForPitch(int midiPitch, |
34 float centsOffset = 0, | 34 double centsOffset = 0, |
35 float concertA = 0.0); | 35 double concertA = 0.0); |
36 | 36 |
37 /** | 37 /** |
38 * Return the nearest MIDI pitch to the given frequency. | 38 * Return the nearest MIDI pitch to the given frequency. |
39 * | 39 * |
40 * If centsOffsetReturn is non-NULL, return in *centsOffsetReturn | 40 * If centsOffsetReturn is non-NULL, return in *centsOffsetReturn |
44 * | 44 * |
45 * If concertA is non-zero, use that as the reference frequency | 45 * If concertA is non-zero, use that as the reference frequency |
46 * for the A at MIDI pitch 69; otherwise use the tuning frequency | 46 * for the A at MIDI pitch 69; otherwise use the tuning frequency |
47 * specified in the application preferences (default 440Hz). | 47 * specified in the application preferences (default 440Hz). |
48 */ | 48 */ |
49 static int getPitchForFrequency(float frequency, | 49 static int getPitchForFrequency(double frequency, |
50 float *centsOffsetReturn = 0, | 50 double *centsOffsetReturn = 0, |
51 float concertA = 0.0); | 51 double concertA = 0.0); |
52 | |
53 /** | |
54 * Compatibility version of getPitchForFrequency accepting float | |
55 * pointer argument. | |
56 */ | |
57 static int getPitchForFrequency(double frequency, | |
58 float *centsOffsetReturn, | |
59 double concertA = 0.0) { | |
60 double c; | |
61 int p = getPitchForFrequency(frequency, &c, concertA); | |
62 if (centsOffsetReturn) *centsOffsetReturn = float(c); | |
63 return p; | |
64 } | |
52 | 65 |
53 /** | 66 /** |
54 * Return the nearest MIDI pitch range to the given frequency | 67 * Return the nearest MIDI pitch range to the given frequency |
55 * range, that is, the difference in MIDI pitch values between the | 68 * range, that is, the difference in MIDI pitch values between the |
56 * higher and lower frequencies. | 69 * higher and lower frequencies. |
62 * | 75 * |
63 * If concertA is non-zero, use that as the reference frequency | 76 * If concertA is non-zero, use that as the reference frequency |
64 * for the A at MIDI pitch 69; otherwise use the tuning frequency | 77 * for the A at MIDI pitch 69; otherwise use the tuning frequency |
65 * specified in the application preferences (default 440Hz). | 78 * specified in the application preferences (default 440Hz). |
66 */ | 79 */ |
67 static int getPitchForFrequencyDifference(float frequencyA, | 80 static int getPitchForFrequencyDifference(double frequencyA, |
68 float frequencyB, | 81 double frequencyB, |
69 float *centsOffsetReturn = 0, | 82 double *centsOffsetReturn = 0, |
70 float concertA = 0.0); | 83 double concertA = 0.0); |
71 | 84 |
85 /** | |
86 * Compatibility version of getPitchForFrequencyDifference | |
87 * accepting float pointer argument. | |
88 */ | |
89 static int getPitchForFrequencyDifference(double frequencyA, | |
90 double frequencyB, | |
91 float *centsOffsetReturn, | |
92 double concertA = 0.0) { | |
93 double c; | |
94 int p = getPitchForFrequencyDifference(frequencyA, frequencyB, | |
95 &c, concertA); | |
96 if (centsOffsetReturn) *centsOffsetReturn = float(c); | |
97 return p; | |
98 } | |
99 | |
72 /** | 100 /** |
73 * Return the MIDI pitch for the given note number (0-12 where 0 | 101 * Return the MIDI pitch for the given note number (0-12 where 0 |
74 * is C) and octave number. The octave numbering system is based | 102 * is C) and octave number. The octave numbering system is based |
75 * on the application preferences (default is C4 = middle C, | 103 * on the application preferences (default is C4 = middle C, |
76 * though in previous SV releases that was C3). | 104 * though in previous SV releases that was C3). |
97 * | 125 * |
98 * If useFlats is true, spell notes with flats instead of sharps, | 126 * If useFlats is true, spell notes with flats instead of sharps, |
99 * e.g. Bb3 instead of A#3. | 127 * e.g. Bb3 instead of A#3. |
100 */ | 128 */ |
101 static QString getPitchLabel(int midiPitch, | 129 static QString getPitchLabel(int midiPitch, |
102 float centsOffset = 0, | 130 double centsOffset = 0, |
103 bool useFlats = false); | 131 bool useFlats = false); |
104 | 132 |
105 /** | 133 /** |
106 * Return a string describing the nearest MIDI pitch to the given | 134 * Return a string describing the nearest MIDI pitch to the given |
107 * frequency, with cents offset. | 135 * frequency, with cents offset. |
111 * specified in the application preferences (default 440Hz). | 139 * specified in the application preferences (default 440Hz). |
112 * | 140 * |
113 * If useFlats is true, spell notes with flats instead of sharps, | 141 * If useFlats is true, spell notes with flats instead of sharps, |
114 * e.g. Bb3 instead of A#3. | 142 * e.g. Bb3 instead of A#3. |
115 */ | 143 */ |
116 static QString getPitchLabelForFrequency(float frequency, | 144 static QString getPitchLabelForFrequency(double frequency, |
117 float concertA = 0.0, | 145 double concertA = 0.0, |
118 bool useFlats = false); | 146 bool useFlats = false); |
119 | 147 |
120 /** | 148 /** |
121 * Return a string describing the given pitch range in octaves, | 149 * Return a string describing the given pitch range in octaves, |
122 * semitones and cents. This is in the form e.g. "1'2+4c". | 150 * semitones and cents. This is in the form e.g. "1'2+4c". |
123 */ | 151 */ |
124 static QString getLabelForPitchRange(int semis, float cents = 0); | 152 static QString getLabelForPitchRange(int semis, double cents = 0); |
125 | 153 |
126 /** | 154 /** |
127 * Return true if the given frequency falls within the range of | 155 * Return true if the given frequency falls within the range of |
128 * MIDI note pitches, plus or minus half a semitone. This is | 156 * MIDI note pitches, plus or minus half a semitone. This is |
129 * equivalent to testing whether getPitchForFrequency returns a | 157 * equivalent to testing whether getPitchForFrequency returns a |
132 * | 160 * |
133 * If concertA is non-zero, use that as the reference frequency | 161 * If concertA is non-zero, use that as the reference frequency |
134 * for the A at MIDI pitch 69; otherwise use the tuning frequency | 162 * for the A at MIDI pitch 69; otherwise use the tuning frequency |
135 * specified in the application preferences (default 440Hz). | 163 * specified in the application preferences (default 440Hz). |
136 */ | 164 */ |
137 static bool isFrequencyInMidiRange(float frequency, | 165 static bool isFrequencyInMidiRange(double frequency, |
138 float concertA = 0.0); | 166 double concertA = 0.0); |
139 }; | 167 }; |
140 | 168 |
141 | 169 |
142 #endif | 170 #endif |