billthefarmer / tuner

Android accordion tuner

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What a great tuner!

duo2005duo opened this issue · comments

commented

The tuner is amazing! Could you talk about the algorithms?

The frequency detection algorithm comes from here: http://blogs.zynaptiq.com/bernsee/pitch-shifting-using-the-ft/ This site used to be called The DSP Dimension. I have just used the first part of it. Most of the DSP stuff is in the Audio class towards the end of MainActivity.java here:https://github.com/billthefarmer/tuner/blob/master/src/org/billthefarmer/tuner/MainActivity.java. I have put comments in explaining what is going on.

commented

Thank you.

commented

I found it's difficult for me to understand the follow code block in the Audio class towards the end of MainActivity.java

// Calculate phase difference

            dp -= i * expect;

            int qpd = (int)(dp / Math.PI);

            if (qpd >= 0)
            qpd += qpd & 1;

            else
            qpd -= qpd & 1;

            dp -=  Math.PI * qpd;

            // Calculate frequency difference

            double df = OVERSAMPLE * dp / (2.0 * Math.PI);

            // Calculate actual frequency from slot frequency plus
            // frequency difference and correction value

            xf[i] = i * fps + df * fps;

I don't quite get why xf[i] = i * fps + df * fps instead of xf[i] = i * fps ,Is there any tecknology used here? Could you point out what it is?

This bit of code:

            double p = Math.atan2(imag, real);
            double dp = xp[i] - p;

            xp[i] = p;

calculates the current phase, the phase difference from the last iteraction and saves the phase for the next iteration. The next bit

            // Calculate phase difference

            dp -= i * expect;

            int qpd = (int)(dp / Math.PI);

            if (qpd >= 0)
            qpd += qpd & 1;

            else
            qpd -= qpd & 1;

            dp -=  Math.PI * qpd;

calculates the difference between the actual phase shift and the expected phase shift for that slot, and compensates for crossing the 0/360 degree region. The next bir

            // Calculate frequency difference

            double df = OVERSAMPLE * dp / (2.0 * Math.PI);

            // Calculate actual frequency from slot frequency plus
            // frequency difference and correction value

            xf[i] = i * fps + df * fps;

            // Calculate differences for finding maxima

            dx[i] = xa[i] - xa[i - 1];
        }

calculates the frequency difference for that slot from the phase difference and the actual frequency from the slot frequency plus the difference. There is no correction on this platform, that comment is from the windows version.

commented

Oh,I see.You did not just use the first part of the post you mentioned but also other parts of it.Thanks.