summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2013-03-28 15:34:31 +0000
committererdgeist <>2013-03-28 15:34:31 +0000
commit37cbb8ec1871134e3cccfb30938cad0da791eaf3 (patch)
tree43b024fcf581e84c9b4fcd4602f635d894f6ff25
parentddcb4ab4507cac8b3ec36f9d454e98c336b920b5 (diff)
Attribute slope function to the original author. Get rid off the last float outside initialization
-rw-r--r--timestretch.c13
1 files 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 ) {
44 44
45 free( g_overlap_heuristic ); 45 free( g_overlap_heuristic );
46 g_overlap_heuristic = malloc( sizeof(short) * g_corr_length ); 46 g_overlap_heuristic = malloc( sizeof(short) * g_corr_length );
47
48 // boost middle of sequence by top of a flat parabola
49 // slope stolen from soundtouch, precalc table
47 for( i = 0; i < g_corr_length; ++i ) 50 for( i = 0; i < g_corr_length; ++i )
48 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); 51 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);
49 52
@@ -67,17 +70,13 @@ we found an offset of 5 msec
67 70
68static unsigned int find_corr_max(const short *input, const short *mixbuf) { 71static unsigned int find_corr_max(const short *input, const short *mixbuf) {
69 unsigned int i, j, offs = 0; 72 unsigned int i, j, offs = 0;
70 double corr_max = FLT_MIN; 73 int64_t acc, corr_max = 0;
71 74
72 // Scans for the best correlation value by testing each possible position 75 // Scans for the best correlation value by testing each possible position
73 for (i = 0; i < g_corr_length; ++i) { 76 for (i = 0; i < g_corr_length; ++i) {
74 int64_t acc = 0; 77 for(j = 0, acc = 0; j < g_overlap; ++j )
75
76 for(j = 0; j < g_overlap; ++j )
77 acc += input[i+j] * mixbuf[j]; 78 acc += input[i+j] * mixbuf[j];
78 79
79 // boost middle of sequence by top of a flat parabola
80 // slope stolen from soundtouch
81 acc *= g_overlap_heuristic[i]; 80 acc *= g_overlap_heuristic[i];
82 if ( corr_max < acc ) { 81 if ( corr_max < acc ) {
83 offs = i; 82 offs = i;
@@ -85,7 +84,7 @@ static unsigned int find_corr_max(const short *input, const short *mixbuf) {
85 } 84 }
86 } 85 }
87 86
88printf( "%03d %016llX\n", offs, (int64_t)corr_max ); 87printf( "%03d %016llX\n", offs, corr_max );
89 return offs; 88 return offs;
90} 89}
91 90