comparison base/test/TestPitch.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 451f7f3ab6e7
children bbc4e4ee15d5
comparison
equal deleted inserted replaced
1024:d1ce7a4a920b 1025:88b54a185a0a
70 QCOMPARE(Pitch::getPitchLabelForFrequency(440, 440, false), QString("A4")); 70 QCOMPARE(Pitch::getPitchLabelForFrequency(440, 440, false), QString("A4"));
71 QCOMPARE(Pitch::getPitchLabelForFrequency(440, 220, false), QString("A5")); 71 QCOMPARE(Pitch::getPitchLabelForFrequency(440, 220, false), QString("A5"));
72 QCOMPARE(Pitch::getPitchLabelForFrequency(261.63, 440, false), QString("C4")); 72 QCOMPARE(Pitch::getPitchLabelForFrequency(261.63, 440, false), QString("C4"));
73 } 73 }
74 74
75 #define MIDDLE_C 261.6255653f 75 #define MIDDLE_C 261.6255653005986
76 76
77 void frequencyForPitch() 77 void frequencyForPitch()
78 { 78 {
79 QCOMPARE(Pitch::getFrequencyForPitch(60, 0), MIDDLE_C); 79 QCOMPARE(Pitch::getFrequencyForPitch(60, 0), MIDDLE_C);
80 QCOMPARE(Pitch::getFrequencyForPitch(69, 0), 440.f); 80 QCOMPARE(Pitch::getFrequencyForPitch(69, 0), 440.0);
81 QCOMPARE(Pitch::getFrequencyForPitch(60, 0, 220), MIDDLE_C / 2.f); 81 QCOMPARE(Pitch::getFrequencyForPitch(60, 0, 220), MIDDLE_C / 2.0);
82 QCOMPARE(Pitch::getFrequencyForPitch(69, 0, 220), 220.f); 82 QCOMPARE(Pitch::getFrequencyForPitch(69, 0, 220), 220.0);
83 } 83 }
84 84
85 void pitchForFrequency() 85 void pitchForFrequency()
86 {
87 double centsOffset = 0.0;
88 QCOMPARE(Pitch::getPitchForFrequency(MIDDLE_C, &centsOffset), 60);
89 QCOMPARE(centsOffset, 0.0);
90 QCOMPARE(Pitch::getPitchForFrequency(261.0, &centsOffset), 60);
91 QCOMPARE(int(centsOffset), -4);
92 QCOMPARE(Pitch::getPitchForFrequency(440.0, &centsOffset), 69);
93 QCOMPARE(centsOffset, 0.0);
94 }
95
96 void pitchForFrequencyF()
86 { 97 {
87 float centsOffset = 0.f; 98 float centsOffset = 0.f;
88 QCOMPARE(Pitch::getPitchForFrequency(MIDDLE_C, &centsOffset), 60); 99 QCOMPARE(Pitch::getPitchForFrequency(MIDDLE_C, &centsOffset), 60);
89 QCOMPARE(centsOffset, 0.f); 100 QCOMPARE(centsOffset, 0.f);
90 QCOMPARE(Pitch::getPitchForFrequency(261.0, &centsOffset), 60); 101 QCOMPARE(Pitch::getPitchForFrequency(261.0, &centsOffset), 60);