]> de.git.xonotic.org Git - xonotic/mediasource.git/blobdiff - sound/weapons/loopfinder/findloop.c
more improvement for loopnote making from fluidsynth
[xonotic/mediasource.git] / sound / weapons / loopfinder / findloop.c
index 22073187ceab3a9f4eed2d50f0a8951e7ecef997..cbfc43409b94fd7012701ae838371911987dc984 100644 (file)
@@ -68,7 +68,7 @@ sf_count_t findMaximumSingle(double (*func) (sf_count_t), sf_count_t x0, sf_coun
 
        sf_count_t i;
 
-       for(i = x0 + step; i < x1; i += step)
+       for(i = x0; i < x1; i += step)
        {
                double cur = func(i);
                if(cur > best)
@@ -88,21 +88,25 @@ sf_count_t findMaximum(double (*func) (sf_count_t), sf_count_t x0, sf_count_t xg
        xg0 = xg = MAX(x0, MIN(xg, x1));
        xg20 = xg2 = MAX(x0, MIN(xg2, x1));
 
+       fprintf(stderr, "min/max: %d %d\n", (int)xg, (int)xg2);
+
        for(;;)
        {
                sf_count_t size = xg2 - xg;
                if(size == 0)
                        break;
-               fprintf(stderr, "round:\n");
-               sf_count_t bestguess = findMaximumSingle(func, xg, xg2, (xg2 - xg) / 16 + 1);
-               xg = MAX(x0, bestguess - size / 3);
-               xg2 = MIN(bestguess + size / 3, x1);
+               //fprintf(stderr, "round:\n");
+               sf_count_t bestguess = findMaximumSingle(func, xg, xg2, size / 32 + 1);
+               xg = MAX(xg, bestguess - size / 3);
+               xg2 = MIN(bestguess + size / 3, xg2);
        }
 
-       if(xg - xg0 < (xg20 - xg0) / 16)
+       fprintf(stderr, "guessed: %d\n", (int)xg);
+
+       if(xg - xg0 < (xg20 - xg0) / 64)
                fprintf(stderr, "warning: best match very close to left margin, maybe decrease the guess?\n");
 
-       if(xg20 - xg < (xg20 - xg0) / 16)
+       if(xg20 - xg < (xg20 - xg0) / 64)
                fprintf(stderr, "warning: best match very close to right margin, maybe increase the guess?\n");
 
        return xg;
@@ -200,7 +204,7 @@ int main(int argc, char **argv)
                double sxy = vectorDot(data_end + ndata_lowpass, data_cur + ndata_lowpass, ndata_highpass - ndata_lowpass);
                double syy = vectorDot(data_cur + ndata_lowpass, data_cur + ndata_lowpass, ndata_highpass - ndata_lowpass);
                double v = syy ? ((sxy*sxy) / (sxx*syy)) : -1;
-               fprintf(stderr, "Evaluated at %.9f: %f\n", i / (double) infile_info.samplerate, v);
+               //fprintf(stderr, "Evaluated at %.9f: %f\n", i / (double) infile_info.samplerate, v);
                return v;
        }