-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHarpNoteDetection.cpp
More file actions
68 lines (54 loc) · 1.76 KB
/
HarpNoteDetection.cpp
File metadata and controls
68 lines (54 loc) · 1.76 KB
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
65
66
#include "HarpNoteDetection.h"
const int pluckDelta = 25;
HarpNoteDetection::HarpNoteDetection()
{
}
HarpNoteDetection::~HarpNoteDetection()
{
}
void HarpNoteDetection::checkNotes(int reflectedLightValues[], bool pluckedNotes[]) {
for (int testString = 0; testString < numberNotes; testString++) {
pluckedNotes[testString] = false;
//We are looking at one string. Compare its reading to every other string. Is the difference over the threshhold?
//Comparing to yourself just returns a zero, so allow it (that's simpler!) Count up the number of comparison
//points that are "large" (ie, over the delta.)
int counter = 0;
for (int comparisonString = 0; comparisonString < numberNotes; comparisonString++) {
int difference = reflectedLightValues[testString] - reflectedLightValues[comparisonString];
if (difference > pluckDelta) {
counter++;
}
}
//If there are at least three strings with a reading much lower than this one - then
//count this one as plucked.
//Three means that we have a wide comparison - one string might be too low, there's tons
//of variations - but this way we account for ambient light as we're comparing the strings
//to each other, and since there must be at least three we get pretty robust.
if (counter > 3) {
pluckedNotes[testString] = true;
}
}
return;
}
bool HarpNoteDetection::getNotes(int& note1, int& note2, bool pluckedNotes[]){
note1 = -1;
note2 = -1;
int numPlucked = 0;
for (int testString = 0; testString < numberNotes; testString++) {
if (pluckedNotes[testString]) {
numPlucked++;
if (note1 == -1) {
note1 = testString;
}
else {
note2 = testString;
}
}
}
if (numPlucked >= 3) {
//Too many strings! Fail the call.
return false;
}
//Yay! It was all good!
return true;
}