Beispiel #1
0
/*
 * A simplified version of MQ Partial Tracking.
 */
PeakList* track_peaks(PeakList* peak_list, MQParameters* params)
{
    PeakList* current = peak_list;

    /* MQ algorithm needs 2 frames of data, so return if this is the first frame */
    if(params->prev_peaks)
    {
        /* find all matches for previous peaks in the current frame */
        current = params->prev_peaks;
        while(current && current->peak)
        {
            Peak* match = find_closest_match(current->peak, peak_list, params, 1);
            /*printf("peak: %f\n", current->peak->frequency);*/
            if(match)
            {
                Peak* closest_to_cand = find_closest_match(match, params->prev_peaks, params, 0);
                if(closest_to_cand != current->peak)
                {
                    /*printf("%f closer to %f\n", match->frequency, closest_to_cand->frequency);*/
                    /* see if the closest peak with lower frequency to the candidate is within
                     * the matching interval
                     */
                    Peak* lower = free_peak_below(match, peak_list);
                    if(lower)
                    {
                        if(fabs(lower->frequency - current->peak->frequency) < params->matching_interval)
                        {
                            lower->prev = current->peak;
                            current->peak->next = lower;
                        }
                    }
                }
                /* if closest_peak == peak, it is a definitive match */
                else
                {
                    match->prev = current->peak;
                    current->peak->next = match;
                }
            }
            current = current->next;
        }
    }

    params->prev_peaks = peak_list;
    return peak_list;
}
Beispiel #2
0
// A simplified version of MQ Partial Tracking.
PeakList* track_peaks(PeakList* peak_list, MQParameters* params) {
    PeakList* current = peak_list;

    // MQ algorithm needs 2 frames of data, so return if this is the
    // first frame
    if(params->prev_peaks) {
        // find all matches for previous peaks in the current frame
        current = params->prev_peaks;
        while(current && current->peak) {
            Peak* match = find_closest_match(
                current->peak, peak_list, params, 1
            );
            if(match) {
                Peak* closest_to_cand = find_closest_match(
                    match, params->prev_peaks, params, 0
                );
                if(closest_to_cand != current->peak) {
                    // see if the closest peak with lower frequency to the
                    // candidate is within the matching interval
                    Peak* lower = free_peak_below(match, peak_list);
                    if(lower) {
                        if(fabs(lower->frequency - current->peak->frequency)
                           < params->matching_interval) {
                            lower->prev = current->peak;
                            current->peak->next = lower;
                        }
                    }
                }
                // if closest_peak == peak, it is a definitive match
                else {
                    match->prev = current->peak;
                    current->peak->next = match;
                }
            }
            current = current->next;
        }
    }

    delete_peak_list(params->prev_peaks2);
    params->prev_peaks2 = params->prev_peaks;
    params->prev_peaks = peak_list;
    return peak_list;
}