From 37cbb8ec1871134e3cccfb30938cad0da791eaf3 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Thu, 28 Mar 2013 15:34:31 +0000 Subject: Attribute slope function to the original author. Get rid off the last float outside initialization --- timestretch.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/timestretch.c b/timestretch.c index 7f9bcd6..8baa7c8 100644 --- a/timestretch.c +++ b/timestretch.c @@ -44,6 +44,9 @@ static size_t calc_convert_values( int sample_rate, float tempo ) { free( g_overlap_heuristic ); g_overlap_heuristic = malloc( sizeof(short) * g_corr_length ); + + // boost middle of sequence by top of a flat parabola + // slope stolen from soundtouch, precalc table for( i = 0; i < g_corr_length; ++i ) g_overlap_heuristic[i] = (short)16384.0*(-(double)i*(double)i/((double)g_corr_length*(double)g_corr_length)+(double)i/(double)g_corr_length+0.75f); @@ -67,17 +70,13 @@ we found an offset of 5 msec static unsigned int find_corr_max(const short *input, const short *mixbuf) { unsigned int i, j, offs = 0; - double corr_max = FLT_MIN; + int64_t acc, corr_max = 0; // Scans for the best correlation value by testing each possible position for (i = 0; i < g_corr_length; ++i) { - int64_t acc = 0; - - for(j = 0; j < g_overlap; ++j ) + for(j = 0, acc = 0; j < g_overlap; ++j ) acc += input[i+j] * mixbuf[j]; - // boost middle of sequence by top of a flat parabola - // slope stolen from soundtouch acc *= g_overlap_heuristic[i]; if ( corr_max < acc ) { offs = i; @@ -85,7 +84,7 @@ static unsigned int find_corr_max(const short *input, const short *mixbuf) { } } -printf( "%03d %016llX\n", offs, (int64_t)corr_max ); +printf( "%03d %016llX\n", offs, corr_max ); return offs; } -- cgit v1.2.3