Developing an application which maps the note played on an instrument. Example:- If a C is played on the piano, the application displays a C.
double [] notes={16.35,17.32,18.35,19.45,20.6,21.83,23.12,24.5,25.96,27.5,29.14,30.87};
char [] notations={'c','C','d','D','e','f','F','g','G','a','A','b'};
int index=0;
double minvalue=999999;
if(values[0]>16.34){
for (int i=0;i<=11;i++)
{
double result=values[0]%notes[i];
if(result==0)
{
index=i;
break;
}
double temp=notes[i]-result;
if(temp<minvalue)
{
minvalue=temp;
index=i;
}
}
TextView display2 = (TextView) findViewById(R.id.textView2);
display2.setText(String.valueOf(notations[index]));
notes array consists of the frequencies of the twelve different notes. value[0] consists of the frequency which is obtained. value[0]%notes[i] is used to determine the closest note the frequency belongs to.
The problem:
The values change a lot! Because of which, when C is played on the piano, It sets on C, but changes qucikly to some other not because of the changing values.
Is there a better mapping scheme which can be followed?