示例#1
0
        /**
         * Implements step 4 of the AUBIO_YIN paper.
         */
        private int absoluteThreshold()
        {
            // Uses another loop construct
            // than the AUBIO implementation
            int tau;

            // first two positions in yinBuffer are always 1
            // So start at the third (index 2)
            for (tau = 2; tau < yinBuffer.Length; tau++)
            {
                if (yinBuffer[tau] < threshold)
                {
                    while (tau + 1 < yinBuffer.Length && yinBuffer[tau + 1] < yinBuffer[tau])
                    {
                        tau++;
                    }
                    // found tau, exit loop and return
                    // store the probability
                    // From the YIN paper: The threshold determines the list of
                    // candidates admitted to the set, and can be interpreted as the
                    // proportion of aperiodic power tolerated
                    // within a periodic signal.
                    //
                    // Since we want the periodicity and and not aperiodicity:
                    // periodicity = 1 - aperiodicity
                    result.setProbability(1 - yinBuffer[tau]);
                    break;
                }
            }


            // if no pitch found, tau => -1
            if (tau == yinBuffer.Length || yinBuffer[tau] >= threshold)
            {
                tau = -1;
                result.setProbability(0);
                result.setPitched(false);
            }
            else
            {
                result.setPitched(true);
            }

            return(tau);
        }