comparison base/Pitch.cpp @ 483:fdaa63607c15

Untabify, indent, tidy
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 31 May 2019 11:54:32 +0100
parents d5014ab8b0e5
children
comparison
equal deleted inserted replaced
482:cbe668c7d724 483:fdaa63607c15
16 16
17 #include <math.h> 17 #include <math.h>
18 18
19 float 19 float
20 Pitch::getFrequencyForPitch(int midiPitch, 20 Pitch::getFrequencyForPitch(int midiPitch,
21 float centsOffset, 21 float centsOffset,
22 float concertA) 22 float concertA)
23 { 23 {
24 float p = float(midiPitch) + (centsOffset / 100); 24 float p = float(midiPitch) + (centsOffset / 100);
25 return concertA * powf(2.0, (p - 69.0) / 12.0); 25 return concertA * powf(2.0, (p - 69.0) / 12.0);
26 } 26 }
27 27
28 int 28 int
29 Pitch::getPitchForFrequency(float frequency, 29 Pitch::getPitchForFrequency(float frequency,
30 float *centsOffsetReturn, 30 float *centsOffsetReturn,
31 float concertA) 31 float concertA)
32 { 32 {
33 float p = 12.0 * (log(frequency / (concertA / 2.0)) / log(2.0)) + 57.0; 33 float p = 12.0 * (log(frequency / (concertA / 2.0)) / log(2.0)) + 57.0;
34 34
35 int midiPitch = int(p + 0.00001); 35 int midiPitch = int(p + 0.00001);
36 float centsOffset = (p - midiPitch) * 100.0; 36 float centsOffset = (p - midiPitch) * 100.0;
37 37
38 if (centsOffset >= 50.0) { 38 if (centsOffset >= 50.0) {
39 midiPitch = midiPitch + 1; 39 midiPitch = midiPitch + 1;
40 centsOffset = -(100.0 - centsOffset); 40 centsOffset = -(100.0 - centsOffset);
41 } 41 }
42 42
43 if (centsOffsetReturn) *centsOffsetReturn = centsOffset; 43 if (centsOffsetReturn) *centsOffsetReturn = centsOffset;
44 return midiPitch; 44 return midiPitch;
45 } 45 }