Mercurial > hg > svcore
comparison base/test/TestPitch.h @ 1450:a12fd0456f0c streaming-csv-writer
Merge from default branch
author | Chris Cannam |
---|---|
date | Tue, 17 Apr 2018 10:35:42 +0100 |
parents | 48e9f538e6e9 |
children |
comparison
equal
deleted
inserted
replaced
1449:deabf9fd3d28 | 1450:a12fd0456f0c |
---|---|
30 { | 30 { |
31 Q_OBJECT | 31 Q_OBJECT |
32 | 32 |
33 private slots: | 33 private slots: |
34 void init() { | 34 void init() { |
35 Preferences::getInstance()->setOctaveOfMiddleC(4); | 35 Preferences::getInstance()->setOctaveOfMiddleC(4); |
36 Preferences::getInstance()->setTuningFrequency(440); | 36 Preferences::getInstance()->setTuningFrequency(440); |
37 } | 37 } |
38 | 38 |
39 void pitchLabel() | 39 void pitchLabel() |
40 { | 40 { |
41 QCOMPARE(Pitch::getPitchLabel(60, 0, false), QString("C4")); | 41 QCOMPARE(Pitch::getPitchLabel(60, 0, false), QString("C4")); |
42 QCOMPARE(Pitch::getPitchLabel(69, 0, false), QString("A4")); | 42 QCOMPARE(Pitch::getPitchLabel(69, 0, false), QString("A4")); |
43 QCOMPARE(Pitch::getPitchLabel(61, 0, false), QString("C#4")); | 43 QCOMPARE(Pitch::getPitchLabel(61, 0, false), QString("C#4")); |
44 QCOMPARE(Pitch::getPitchLabel(61, 0, true), QString("Db4")); | 44 QCOMPARE(Pitch::getPitchLabel(61, 0, true), QString("Db4")); |
45 QCOMPARE(Pitch::getPitchLabel(59, 0, false), QString("B3")); | 45 QCOMPARE(Pitch::getPitchLabel(59, 0, false), QString("B3")); |
46 QCOMPARE(Pitch::getPitchLabel(59, 0, true), QString("B3")); | 46 QCOMPARE(Pitch::getPitchLabel(59, 0, true), QString("B3")); |
47 QCOMPARE(Pitch::getPitchLabel(0, 0, false), QString("C-1")); | 47 QCOMPARE(Pitch::getPitchLabel(0, 0, false), QString("C-1")); |
48 | 48 |
49 QCOMPARE(Pitch::getPitchLabel(60, -40, false), QString("C4-40c")); | 49 QCOMPARE(Pitch::getPitchLabel(60, -40, false), QString("C4-40c")); |
50 QCOMPARE(Pitch::getPitchLabel(60, 40, false), QString("C4+40c")); | 50 QCOMPARE(Pitch::getPitchLabel(60, 40, false), QString("C4+40c")); |
51 QCOMPARE(Pitch::getPitchLabel(58, 4, false), QString("A#3+4c")); | 51 QCOMPARE(Pitch::getPitchLabel(58, 4, false), QString("A#3+4c")); |
52 | 52 |
53 Preferences::getInstance()->setOctaveOfMiddleC(3); | 53 Preferences::getInstance()->setOctaveOfMiddleC(3); |
54 | 54 |
55 QCOMPARE(Pitch::getPitchLabel(60, 0, false), QString("C3")); | 55 QCOMPARE(Pitch::getPitchLabel(60, 0, false), QString("C3")); |
56 QCOMPARE(Pitch::getPitchLabel(69, 0, false), QString("A3")); | 56 QCOMPARE(Pitch::getPitchLabel(69, 0, false), QString("A3")); |
57 QCOMPARE(Pitch::getPitchLabel(61, 0, false), QString("C#3")); | 57 QCOMPARE(Pitch::getPitchLabel(61, 0, false), QString("C#3")); |
58 QCOMPARE(Pitch::getPitchLabel(61, 0, true), QString("Db3")); | 58 QCOMPARE(Pitch::getPitchLabel(61, 0, true), QString("Db3")); |
59 QCOMPARE(Pitch::getPitchLabel(59, 0, false), QString("B2")); | 59 QCOMPARE(Pitch::getPitchLabel(59, 0, false), QString("B2")); |
60 QCOMPARE(Pitch::getPitchLabel(59, 0, true), QString("B2")); | 60 QCOMPARE(Pitch::getPitchLabel(59, 0, true), QString("B2")); |
61 QCOMPARE(Pitch::getPitchLabel(0, 0, false), QString("C-2")); | 61 QCOMPARE(Pitch::getPitchLabel(0, 0, false), QString("C-2")); |
62 | 62 |
63 QCOMPARE(Pitch::getPitchLabel(60, -40, false), QString("C3-40c")); | 63 QCOMPARE(Pitch::getPitchLabel(60, -40, false), QString("C3-40c")); |
64 QCOMPARE(Pitch::getPitchLabel(60, 40, false), QString("C3+40c")); | 64 QCOMPARE(Pitch::getPitchLabel(60, 40, false), QString("C3+40c")); |
65 QCOMPARE(Pitch::getPitchLabel(58, 4, false), QString("A#2+4c")); | 65 QCOMPARE(Pitch::getPitchLabel(58, 4, false), QString("A#2+4c")); |
66 } | 66 } |
67 | 67 |
68 void pitchLabelForFrequency() | 68 void pitchLabelForFrequency() |
69 { | 69 { |
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.6255653005986 | 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.0); | 80 QCOMPARE(Pitch::getFrequencyForPitch(69, 0), 440.0); |
81 QCOMPARE(Pitch::getFrequencyForPitch(60, 0, 220), MIDDLE_C / 2.0); | 81 QCOMPARE(Pitch::getFrequencyForPitch(60, 0, 220), MIDDLE_C / 2.0); |
82 QCOMPARE(Pitch::getFrequencyForPitch(69, 0, 220), 220.0); | 82 QCOMPARE(Pitch::getFrequencyForPitch(69, 0, 220), 220.0); |
83 } | 83 } |
84 | 84 |
85 void pitchForFrequency() | 85 void pitchForFrequency() |
86 { | 86 { |
87 double centsOffset = 0.0; | 87 double centsOffset = 0.0; |
88 QCOMPARE(Pitch::getPitchForFrequency(MIDDLE_C, ¢sOffset), 60); | 88 QCOMPARE(Pitch::getPitchForFrequency(MIDDLE_C, ¢sOffset), 60); |
89 QCOMPARE(centsOffset + 1.0, 1.0); // avoid ineffective fuzzy-compare to 0 | 89 QCOMPARE(centsOffset + 1.0, 1.0); // avoid ineffective fuzzy-compare to 0 |
90 QCOMPARE(Pitch::getPitchForFrequency(261.0, ¢sOffset), 60); | 90 QCOMPARE(Pitch::getPitchForFrequency(261.0, ¢sOffset), 60); |
91 QCOMPARE(int(centsOffset), -4); | 91 QCOMPARE(int(centsOffset), -4); |
92 QCOMPARE(Pitch::getPitchForFrequency(440.0, ¢sOffset), 69); | 92 QCOMPARE(Pitch::getPitchForFrequency(440.0, ¢sOffset), 69); |
93 QCOMPARE(centsOffset + 1.0, 1.0); | 93 QCOMPARE(centsOffset + 1.0, 1.0); |
94 } | 94 } |
95 | 95 |
96 void pitchForFrequencyF() | 96 void pitchForFrequencyF() |
97 { | 97 { |
98 float centsOffset = 0.f; | 98 float centsOffset = 0.f; |
99 QCOMPARE(Pitch::getPitchForFrequency(MIDDLE_C, ¢sOffset), 60); | 99 QCOMPARE(Pitch::getPitchForFrequency(MIDDLE_C, ¢sOffset), 60); |
100 QCOMPARE(centsOffset + 1.f, 1.f); // avoid ineffective fuzzy-compare to 0 | 100 QCOMPARE(centsOffset + 1.f, 1.f); // avoid ineffective fuzzy-compare to 0 |
101 QCOMPARE(Pitch::getPitchForFrequency(261.0, ¢sOffset), 60); | 101 QCOMPARE(Pitch::getPitchForFrequency(261.0, ¢sOffset), 60); |
102 QCOMPARE(int(centsOffset), -4); | 102 QCOMPARE(int(centsOffset), -4); |
103 QCOMPARE(Pitch::getPitchForFrequency(440.0, ¢sOffset), 69); | 103 QCOMPARE(Pitch::getPitchForFrequency(440.0, ¢sOffset), 69); |
104 QCOMPARE(centsOffset + 1.f, 1.f); | 104 QCOMPARE(centsOffset + 1.f, 1.f); |
105 } | 105 } |
106 }; | 106 }; |
107 | 107 |
108 #endif | 108 #endif |