]> de.git.xonotic.org Git - xonotic/mediasource.git/blobdiff - sound/weapons/loopfinder/findloop.c
make this mess work with fluidsynth too :P
[xonotic/mediasource.git] / sound / weapons / loopfinder / findloop.c
index 661f41d1b9dfdcc9bae0536df233805ed503c24c..22073187ceab3a9f4eed2d50f0a8951e7ecef997 100644 (file)
@@ -81,12 +81,12 @@ sf_count_t findMaximumSingle(double (*func) (sf_count_t), sf_count_t x0, sf_coun
        return bestpos;
 }
 
-sf_count_t findMaximum(double (*func) (sf_count_t), sf_count_t x0, sf_count_t xgm, sf_count_t x1)
+sf_count_t findMaximum(double (*func) (sf_count_t), sf_count_t x0, sf_count_t xg, sf_count_t xg2, sf_count_t x1)
 {
-       sf_count_t xg, xg2, xg0, xg20;
+       sf_count_t xg0, xg20;
 
-       xg0 = xg = MAX(x0, xgm - 65536);
-       xg20 = xg2 = MIN(xgm + 65536, x1);
+       xg0 = xg = MAX(x0, MIN(xg, x1));
+       xg20 = xg2 = MAX(x0, MIN(xg2, x1));
 
        for(;;)
        {
@@ -128,6 +128,7 @@ int main(int argc, char **argv)
 
        sf_count_t size = MIN(infile_info.frames, strtod(argv[3], NULL) * infile_info.samplerate);
        sf_count_t guess = strtod(argv[4], NULL) * infile_info.samplerate;
+       sf_count_t guess2 = strtod(argv[5], NULL) * infile_info.samplerate;
        int channels = infile_info.channels;
        size_t fftsize = atoi(argv[2]);
        size_t ndata = channels * (fftsize/2 + 1);
@@ -214,7 +215,7 @@ int main(int argc, char **argv)
        }
 #endif
 
-       sf_count_t best = findMaximum(similarityAt, 0, guess - fftsize, size - 2 * fftsize);
+       sf_count_t best = findMaximum(similarityAt, 0, guess - fftsize, guess2 - fftsize, size - 2 * fftsize);
        fprintf(stderr, "Result: %.9f (sample %ld)\n", (best + fftsize) / (double) infile_info.samplerate, (long) (best + fftsize));
 
        // Now write it!
@@ -239,7 +240,7 @@ int main(int argc, char **argv)
 
        // 2. Open sound file
        fprintf(stderr, "Opening...\n");
-       SNDFILE *outfile = sf_open(argv[5], SFM_WRITE, &infile_info);
+       SNDFILE *outfile = sf_open(argv[6], SFM_WRITE, &infile_info);
        if(!outfile)
                err(1, "open");