0

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?

shivram
  • 469
  • 2
  • 10
  • 26

1 Answers1

2

You should look for pitch detection algorithm

Real-world sounds are not static. Relative intensity of each overtone may change at different rate over time. The fundamental frequency of a sound at given moment can be different from FFT peak magnitude.

P.S. Found more comprehensive answer

Community
  • 1
  • 1
otykhonruk
  • 181
  • 7
  • Thank you for your reply! I have tried using the zero crossing method. How often should I call the function which calculates the frequency using the zero crossing method? Because I do not want it to change very often – shivram Jan 03 '15 at 13:51